java 为什么 HikariCP 推荐固定大小的池以获得更好的性能
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28987540/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why does HikariCP recommend fixed size pool for better performance
提问by shivadarshan
According to HikariCP's documentation they mentioned to create fixed size pool for better performance.
根据 HikariCP 的文档,他们提到创建固定大小的池以获得更好的性能。
minimumIdle:
This property controls the minimum number of idle connections that HikariCP tries to maintain in the pool.If the idle connections dip below this value, HikariCP will make a best effort to add additional connections quickly and efficiently. However, for maximum performanceand responsiveness to spike demands, we recommend not setting this value and instead allowing HikariCP to act as a fixed size connection pool. Default: same as
maximumPoolSize
最小空闲:
此属性控制 HikariCP 尝试在池中维护的最小空闲连接数。如果空闲连接低于此值,HikariCP 将尽最大努力快速有效地添加额外连接。但是,为了获得最佳性能和对峰值需求的响应,我们建议不要设置此值,而是允许 HikariCP 充当固定大小的连接池。默认值:与
maximumPoolSize
My application usually requires 100 connections and only at a few circumstances reaches 200 connections.
我的应用程序通常需要 100 个连接,只有在少数情况下才能达到 200 个连接。
If I create a 200 connection fixed size pool, most of the time 100 connections will be idle.
如果我创建一个 200 个连接固定大小的池,大部分时间 100 个连接将处于空闲状态。
So which of the following is the best:
那么以下哪个是最好的:
- Create connection pool with fixed size. i.e. 200
- 创建固定大小的连接池。即 200
OR
或者
- Create connection pool by setting
minimumIdle
to 100 andmaximumPoolSize
to 200.
- 通过设置
minimumIdle
为 100 和maximumPoolSize
200创建连接池。
Why the second point is not recommended by HikariCP? I think the second one would be the best for my case.
为什么HikariCP不推荐第二点?我认为第二个最适合我的情况。
回答by brettw
I suggest you read thispage and watch the attached video. The Oracle Performance Group demonstrates how an application with a pool of 96 connection easily handles 10,000 front-end users and 20,000 transactions per-second.
我建议您阅读此页面并观看随附的视频。Oracle Performance Group 演示了具有 96 个连接池的应用程序如何轻松处理 10,000 个前端用户和每秒 20,000 个事务。
PostgreSQL recommends a formula of:
PostgreSQL 推荐一个公式:
connections = ((core_count * 2) + effective_spindle_count)
connections = ((core_count * 2) + effective_spindle_count)
Where core_count
is CPU cores, and effective_spindle_count
is the number of disks in a RAID. For many servers, this formula would result in a connection pool of 10-20 maximum connections.
哪里core_count
是 CPU 内核,effective_spindle_count
是 RAID 中的磁盘数量。对于许多服务器,此公式将导致最大连接数为 10-20 个的连接池。
The odds are that with even 100 connections, your database is heavily over saturated. Do you have 50 CPU cores? If you're drives are spinning platters not SSDs the head can only be in one place at a time, and unless the entire dataset is in memory there is no way to service so many requests at once (100-200).
即使有 100 个连接,您的数据库也有可能严重过度饱和。你有 50 个 CPU 内核吗?如果您的驱动器是旋转盘片而不是 SSD,则磁头一次只能在一个地方,除非整个数据集都在内存中,否则无法同时处理如此多的请求(100-200)。
UPDATE: Directly answering your question about fixed-pool sizing. You will likely get the best performance from your application with a pool that as a maximum connection count turned right at the "knee" or "peak" performance that your DB can handle. This is likely a small number. If you have "spike demand", as many applications do, trying to spin up new connections to grow the pool at the instant of the spike is counter-productive (creates moreload on the server). A small, constant pool will give you predictable performance.
更新:直接回答您关于固定池大小的问题。您可能会使用一个池从您的应用程序中获得最佳性能,该池的最大连接数在您的数据库可以处理的“膝盖”或“峰值”性能时右转。这可能是一个很小的数字。如果您有“尖峰需求”,就像许多应用程序一样,尝试在尖峰时刻启动新连接以增加池会适得其反(在服务器上产生更多负载)。一个小的、恒定的池将为您提供可预测的性能。
回答by sunilpatil
It really depends on the application behavior of running long running and short running transactions. Sometimes I feel that it's better to hold of some idle connections to pool if we wants to respond to client synchronous manner.
这实际上取决于运行长时间运行和短期运行的事务的应用程序行为。有时我觉得如果我们想响应客户端同步方式,最好保留一些空闲连接到池。