首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Quarkus和hibernate-reactive的SQL连接耗尽

使用Quarkus和hibernate-reactive的SQL连接耗尽
EN

Stack Overflow用户
提问于 2022-04-22 10:52:18
回答 1查看 522关注 0票数 0

我有一个Quarkus应用程序,它使用hibernate-reactive运行一些查询,而不是处理结果,然后通过Rest调用返回JSON。对于每个Rest调用5DB查询,最后一个查询将加载大约20k行:

代码语言:javascript
复制
    public Uni<GraphProcessor> loadData(GraphProcessor graphProcessor){
    return myEntityRepository.findByDateLeaving(graphProcessor.getSearchDate())
            .select().where(graphProcessor::filter)
            .onItem().invoke(graphProcessor::onNextRow).collect().asList()
            .onItem().invoke(g -> log.info("loadData - end"))
            .replaceWith(graphProcessor);
}

//In myEntityRepository
public Multi<MyEntity> findByDateLeaving(LocalDate searchDate){
    LocalDateTime startDate = searchDate.atStartOfDay();
    return MyEntity.find("#MyEntity.findByDate",
            Parameters.with("startDate", startDate)
                    .map()).stream();

}

这一切在前4次都很好,但在第5次我得到

代码语言:javascript
复制
 11:12:48:070 ERROR [org.hibernate.reactive.util.impl.CompletionStages:121] (147) HR000057: Failed to execute statement [$1select <ONE OF THE QUERIES HERE>]: $2could not load an entity: [com.mycode.SomeEntity#1]: java.util.concurrent.CompletionException: io.vertx.core.impl.NoStackTraceThrowable: Timeout
    at <16 internal lines>
io.vertx.sqlclient.impl.pool.SqlConnectionPool$1PoolRequest.lambda$null$0(SqlConnectionPool.java:202) <4 internal lines>
    at io.vertx.sqlclient.impl.pool.SqlConnectionPool$1PoolRequest.lambda$onEnqueue$1(SqlConnectionPool.java:199) <15 internal lines>
Caused by: io.vertx.core.impl.NoStackTraceThrowable: Timeout

我检查了https://quarkus.io/guides/reactive-sql-clients#pooled-connection-idle-timeout并配置了qukus.datource.reactive.id-timeout=1000

这本身并没有什么不同。我加了夸克.数据源.reactive.max-size=10

在再次超时之前,我能够运行10个Rest电话。在最大大小= 20的泳池设置中,我可以运行20次。因此,看起来每个Rest调用都会耗尽一个SQL连接,而不会再次释放它。

手动释放连接需要做些什么吗?还是这仅仅是一个错误?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-26 14:25:50

问题是在反应性Rest方法上使用@阻塞。有关更多信息,请参见https://github.com/quarkusio/quarkus/issues/25138https://quarkus.io/blog/resteasy-reactive-smart-dispatch/

因此,如果您有一个rest方法返回例如Uni或Multi,就不要在调用中使用@阻塞。一开始我不得不添加它,因为我收到了一个异常,告诉我线程不能阻塞。这是由于一些CPU密集的计算。添加@阻塞使异常消失(在开发模式下,但在本机模式中出现了另一个问题),但导致了这个SQL池问题。

真正的解决方案是使用emitOn来更改cpu密集型方法的线程:

代码语言:javascript
复制
 .emitOn(Infrastructure.getDefaultWorkerPool())
 .onItem().transform(processor::cpuIntensiveMethod)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71967584

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档