将数据从SparkStreaming Workers保存到数据库 [英] Saving the data from SparkStreaming Workers to Database

查看:84
本文介绍了将数据从SparkStreaming Workers保存到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SparkStreaming中,我们应该将保存部分卸载到另一层,因为当我们使用 SparkCassandraConnector (如果我们的数据库是cassandra)。而且,即使我们使用其他数据库来保存数据,但是每次处理一批rdds时,都需要在worker上创建连接。原因是连接对象未序列化。

In SparkStreaming should we off load the saving part to another layer because SparkStreaming context is not available when we use SparkCassandraConnector if our database is cassandra. Moreover, even if we use some other database to save our data then we need to create connection on the worker every time we process a batch of rdds. Reason being connection objects are not serialized.


  1. 是否建议在工人处创建/关闭连接?

  1. Is it recommended to create/close connections at workers?

这将使我们的系统与现有数据库紧密结合,明天我们可能会更改数据库

It would make our system tightly coupled with the existing database tomorrow we may change the database


推荐答案

要回答您的问题:


  1. 是的,在工作人员处建立/关闭连接绝对没问题。
    但是,请确保不要对每条记录都这样做。建议
    在分区级别或为一组记录创建/关闭
    连接的级别执行此操作。

  2. 可以通过以下方式解耦

可能的重复项:
处理Spark Streaming内部的数据库连接

阅读此链接,它应该阐明一些问题
使用foreachRDD的设计模式

Read this link, it should clarify some of you questions Design Patterns for using foreachRDD

希望获得帮助!

这篇关于将数据从SparkStreaming Workers保存到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆