Google Cloud数据流:如何每个工人(单个)仅初始化一次Hikari连接池? [英] Google Cloud dataflow : How to initialize Hikari connection pool only once per worker (singleton)?

查看:147
本文介绍了Google Cloud数据流:如何每个工人(单个)仅初始化一次Hikari连接池?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hibernate Utils与Hikari配置一起创建了会话工厂.当前,我们在ParDo的@Setup方法内部进行操作,但是它打开了太多的连接.那么,有没有很好的示例初始化每个工作程序的连接池?

Hibernate Utils is creating the session factory along with Hikari configuration. Currently we are doing inside @Setup method of ParDo, but it opens way too many connections. So is there any good example to initialize connection pool per worker ?

推荐答案

如果您在 DoFn 中使用 @Setup 方法创建数据库连接,请记住ApacheBeam将为每个工作程序实例线程创建连接池.这可能会导致大量数据库连接,具体取决于启动的工作程序数量.

If you are using @Setup method inside DoFn to create a database connection keep in mind that Apache Beam would create connection pool per worker instance thread. This might result in a lot of database connections depending on the number of workers that spin up.

您可以在ParDo中使用Singleton类来创建连接池并控制每个工作程序的连接数.您可以在这里查看示例实现

You can use a Singleton class inside a ParDo to create your connection pool and control the number of connections per worker. You can take a look here for a sample implementation

http://mail-archives.apache.org/mod_mbox/beam-issues/201905.mbox/%3CJIRA.13231789.1557156230000.210182.1557222420198@Atlassian.JIRA%3E

这篇关于Google Cloud数据流:如何每个工人(单个)仅初始化一次Hikari连接池?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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