当前位置: 首页 > 知识库问答 >
问题:

慢速Hibernate/C3P0非慢速后置处理选择

席弘图
2023-03-14

针对Postgres数据库的某个索引SELECT查询所花费的时间非常可变--从50毫秒到多秒,有时甚至是几分钟,即使在最轻的负载下也是如此。

你能为26秒的差距提出一个解释吗?

10:19:29.149 DEBUG org.hibernate.SQL [I=9534] - select eventrepor0_.consortium_id as consorti1_3_3_, eventrepor0_.customer_resource_id as customer6_3_3_, eventrepor0_.item_type_id as item2_3_3_, eventrepor0_.reporting_date as reportin3_3_3_, eventrepor0_.event_subtype as event4_3_3_, eventrepor0_.event_count as event5_3_3_, customerre1_.id as id1_2_0_, customerre1_.customer_id as customer2_2_0_, customerre1_.resource_id as resource3_2_0_, resource2_.id as id1_8_1_, resource2_.data_type_id as data2_8_1_, resource2_.platform_id as platform5_8_1_, resource2_.prop_id as prop3_8_1_, resource2_.title as title4_8_1_, resource2_1_.doi as doi1_6_1_, resource2_1_.isbn as isbn2_6_1_, resource2_1_.online_issn as online3_6_1_, resource2_1_.print_issn as print4_6_1_, resource2_1_.publisher as publishe5_6_1_, resource2_1_.yop as yop6_6_1_, case when resource2_1_.id is not null then 1 when resource2_.id is not null then 0 end as clazz_1_, platform3_.id as id1_4_2_, platform3_.api_key as api2_4_2_, platform3_.platform_name as platform3_4_2_, hostnames4_.platform_id as platform1_4_5_, hostnames4_.hostname as hostname2_5_5_ from event_report eventrepor0_ inner join customer_resource customerre1_ on eventrepor0_.customer_resource_id=customerre1_.id left outer join resource resource2_ on customerre1_.resource_id=resource2_.id left outer join published_resource resource2_1_ on resource2_.id=resource2_1_.id left outer join platform platform3_ on resource2_.platform_id=platform3_.id left outer join platform_hostnames hostnames4_ on platform3_.id=hostnames4_.platform_id where eventrepor0_.consortium_id=? and eventrepor0_.customer_resource_id=? and eventrepor0_.item_type_id=? and eventrepor0_.reporting_date=? and eventrepor0_.event_subtype=?
10:19:29.149 DEBUG c.m.v.a.ThreadPoolAsynchronousRunner [I=9534] - com.mchange.v2.async.ThreadPoolAsynchronousRunner@4ffa2724: Adding task to queue -- com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StmtAcquireTask@31e6b320
10:19:29.149 DEBUG c.m.v.c3p0.stmt.GooGooStatementCache [I=9534] - CULLING: update event_report set event_count=event_count+1 where customer_resource_id=? and item_type_id=? and event_subtype=? and reporting_date=? and consortium_id=?
10:19:29.149 DEBUG c.m.v.a.ThreadPoolAsynchronousRunner [I=9534] - com.mchange.v2.async.ThreadPoolAsynchronousRunner@4ffa2724: Adding task to queue -- com.mchange.v2.c3p0.stmt.GooGooStatementCache$StatementDestructionManager$1UncheckedStatementCloseTask@20fa1378
10:19:29.149 DEBUG c.m.v.c3p0.stmt.GooGooStatementCache [I=9534] - cxnStmtMgr.statementSet( org.postgresql.jdbc4.Jdbc4Connection@38e040d2 ).size(): 5
10:19:29.150 DEBUG c.m.v.c3p0.stmt.GooGooStatementCache [I=9534] - checkoutStatement: com.mchange.v2.c3p0.stmt.GlobalMaxOnlyStatementCache stats -- total size: 20; checked out: 5; num connections: 6; num keys: 20
10:19:29.150 TRACE o.h.e.j.internal.JdbcCoordinatorImpl [I=9534] - Registering statement [com.mchange.v2.c3p0.impl.NewProxyPreparedStatement@7cc20161]
10:19:29.150 TRACE o.h.e.j.internal.JdbcCoordinatorImpl [I=9534] - Registering last query statement [com.mchange.v2.c3p0.impl.NewProxyPreparedStatement@7cc20161]
10:19:29.150 TRACE o.h.type.descriptor.sql.BasicBinder [I=9534] - binding parameter [1] as [VARCHAR] - 
10:19:29.150 TRACE o.h.type.descriptor.sql.BasicBinder [I=9534] - binding parameter [2] as [BIGINT] - 47
10:19:29.150 TRACE org.hibernate.type.EnumType [I=9534] - Binding [SEARCH_REG] to parameter: [3]
10:19:29.150 TRACE o.h.type.descriptor.sql.BasicBinder [I=9534] - binding parameter [4] as [TIMESTAMP] - Tue Jul 16 00:00:00 BST 2013
10:19:29.151 TRACE o.h.type.descriptor.sql.BasicBinder [I=9534] - binding parameter [5] as [VARCHAR] - 
10:19:29.151 TRACE org.hibernate.loader.Loader [I=9534] - Bound [6] parameters total
[... massive gap ...]
10:19:55.644 TRACE o.h.e.j.internal.JdbcCoordinatorImpl [I=9534] - Registering result set [com.mchange.v2.c3p0.impl.NewProxyResultSet@fa7b109]

关于并发的注意事项:即使只有一个请求也有很大的可变性:端到端50-300毫秒,但是当一个用户提交一批大约100个这样的查找时(可能有10-20个同时运行),很可能有几个查找需要5-10秒。然而C3P0的统计数据从来没有比:

com.mchange.v2.c3p0.stmt.GlobalMaxOnlyStatementCache stats -- total size: 20; checked out: 6; num connections: 6; num keys: 20

这些服务器功能非常强大,因此没有明显的磁盘、网络或CPU活动。我们用NewRelic来监视。

ComboPooledDataSource dataSource = new com.mchange.v2.c3p0.ComboPooledDataSource();
dataSource.setInitialPoolSize(5);
dataSource.setMaxPoolSize(20);
dataSource.setMinPoolSize(5);
dataSource.setMaxStatements(20);
dataSource.setIdleConnectionTestPeriod(3600);
dataSource.setTestConnectionOnCheckin( Boolean.TRUE.toString() );
dataSource.setPreferredTestQuery("select 1");
props.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQL82Dialect");
props.put("hibernate.show_sql", "false");
props.put("generate_statistics", "false");
props.put("javax.persistence.sharedCache.mode", "ENABLE_SELECTIVE");
props.put("javax.persistence.validation.mode", "NONE");
props.put("hibernate.cache.use_second_level_cache", "false");
props.put("hibernate.cache.region.factory_class", "org.hibernate.cache.impl.NoCachingRegionFactory");
props.put("hibernate.hbm2ddl.auto", "false");

更新-我们当前使用的C3P0属性(在切换到使用MaxStatementSperConnection之后)

C.M.V.C.I.AbstractPoolBackedDataSource[]-正在初始化c3p0池...com.mchange.v2.c3p0.CombopooledDataSource[acquireIncrement->3,AcquireTretyAttempts->30,AcquireTretyDelay->1000,autoCommitOnClose->false,automaticTestTable->null,breakAfterAcquireFailure->false,checkoutTimeout->0,connectionCustomizerClassName->null,connectionTesterClassName->com.mchange.v2.c3p0.impl.DefaultConnectionTester,*****,password=*****},propertyCycle->0,statementCacheNumDeferredCloseThreads->0,testConnectionOnCheckin->true,testConnectionOnCheckout->false,UnreturndConnectionTimeout->0,userOverrides->{},usesTraditionalReflectiveProxies->false]

共有1个答案

艾仲渊
2023-03-14

我不能确定这是你问题的原因,但我认为有一个相当好的机会!

您将maxstatements设置为一个值,对于您所承载的负载来说,这个值太低了。尝试将maxStatements设置为零(关闭语句缓存),或者尝试将maxStatementsPerConnection设置为20,我认为这可能是您的意图。实际上,您已经将全局最多20个PreparedStatements设置为最多20个连接共享。这不太可能产生良好的性能

 类似资料:
  • 我使用的是Guidewire开发工作室(基于IntelliJ的IDE),在处理大文本文件(~1500行及以上)时速度非常慢。我也尝试了一个开箱即用的社区IntelliJ,但遇到了同样的问题。 当我打开这些文件时,键入一个字符需要 1 秒,即使我清楚地看到使用的内存仍然足够 (1441 MB/3959 MB)。此外,如果我打开多个文件,它会迅速吸收所有内存(我只为 IntelliJ 分配 4GB)。

  • 问题内容: 我正在尝试通过使用JAP和HIBERNATE向SQL Server 2008 R2插入一些数据。一切都“正常”,除了它非常慢。要插入20000行,大约需要45秒,而C#脚本大约需要不到1秒。 这个领域的任何资深人士都可以提供帮助吗?我会很感激。 更新:从下面的答案中得到了一些很好的建议,但仍然无法按预期工作。速度是一样的。 这是更新的persistence.xml: 这是更新的代码部分

  • 问题内容: 我正在尝试通过使用JAP和HIBERNATE向SQL Server 2008 R2插入一些数据。一切都“正常”,除了它非常慢。要插入20000行,大约需要45秒,而C#脚本大约需要不到1秒。 这个领域的任何资深人士都可以提供帮助吗?我会很感激。 更新:从下面的答案中得到了一些很好的建议,但仍然无法按预期工作。速度是一样的。 这是更新的persistence.xml: 这是更新的代码部分

  • 我有一张相对较小的桌子(约5万行)。当我选择所有记录时,需要大约40秒。该表有3个JSONB列。当我选择除JSONB之外的每一列时,查询大约需要700ms。 如果我只添加一个JSONB字段,查询时间会跳到近10秒。 我从来没有使用where子句引用JSONB中的内容,只是选择*。尽管如此,我还是尝试添加GIN索引,因为我经常看到它们被提到是JSONB的性能提升器。 我已经运行了一个完全真空。 Po

  • 我正在试用Flutter,我的应用程序在仿真器和实际设备上的响应都非常非常慢。我收到这样的警告 跳过了51帧!应用程序可能在其主线程上做了太多的工作。 我知道Dart是一种单线程编程语言,在Android中,我曾使用用于异步的好的旧块来解决这一问题。我试图在Flutter中应用相同的方法,并且我阅读了和排序,但是当您从Internet读取数据时,这些示例似乎是针对这些示例的。我的应用程序在这个阶段

  • 问题内容: 我正在查询有关的信息。 我正在迭代一个数组,并查询列表中的每个值。 不幸的是 ,在调试器下, 单个查询大约需要3-4秒,而 在禁用调试器的情况下, 查询时间要 短一些。 任何想法为什么这么慢?我使用进行测试。 这是我的代码: 更新资料 当我离开时,评估很快就完成了,但是我没有得到。它返回一个空字符串… 问题答案: 感谢@nvrmnd我尝试了一下,发现了一种更好的解析器: VTD-XML