gpt4 book ai didi

ruby-on-rails - Rails 应用程序连接池大小,避免最大池大小问题

转载 作者:数据小太阳 更新时间:2023-10-29 06:46:24 25 4
gpt4 key购买 nike

我正在运行 JRuby on Rails 应用程序。我在日志中随机看到很多这样的内容:

最大池大小当前为 5;考虑增加它

我知道我可以在我的配置中增加最大池大小来解决这个问题。我要解决的问题是了解最佳数量应该是多少。我试图避免连接争用问题。显然,将此数字设置得过大也不会奏效。

是否有可遵循的通用协议(protocol)来了解您的应用的最佳池大小设置?

最佳答案

来自 here ,

The optimum size of a thread pool depends on the number of processors available and the nature of the tasks on the work queue. On an N-processor system for a work queue that will hold entirely compute-bound tasks, you will generally achieve maximum CPU utilization with a thread pool of N or N+1 threads.

For tasks that may wait for I/O to complete -- for example, a task that reads an HTTP request from a socket -- you will want to increase the pool size beyond the number of available processors, because not all threads will be working at all times. Using profiling, you can estimate the ratio of waiting time (WT) to service time (ST) for a typical request. If we call this ratio WT/ST, for an N-processor system, you'll want to have approximately N*(1+WT/ST) threads to keep the processors fully utilized.

Processor utilization is not the only consideration in tuning the thread pool size. As the thread pool grows, you may encounter the limitations of the scheduler, available memory, or other system resources, such the number of sockets, open file handles, or database connections.

因此,分析您的应用程序,如果您的线程主要受 CPU 限制,则将线程池大小设置为内核数,或内核数 + 1。如果您花费大部分时间等待数据库调用完成,则使用相当多的线程进行试验,并查看应用程序的性能。

关于ruby-on-rails - Rails 应用程序连接池大小,避免最大池大小问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10435548/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com