加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 22:17:45 所属栏目:百科 来源:网络整理
导读:我正在运行一个J Ruby on Rails应用程序.我在我的日志中随机看到很多: 最大池大小目前为5;考虑增加它 我明白我可以增加我的配置中的最大池大小来解决这个问题.我正在寻找的问题是了解什么是最佳数字.我试图避免连接的争用问题.很明显,将这个数字设置成令人
我正在运行一个J Ruby on Rails应用程序.我在我的日志中随机看到很多:

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

我明白我可以增加我的配置中的最大池大小来解决这个问题.我正在寻找的问题是了解什么是最佳数字.我试图避免连接的争用问题.很明显,将这个数字设置成令人讨厌的大小将不会奏效.

有没有一般的协议来了解你的应用程序最佳池大小设置?

解决方法

从 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.如果您花费大部分时间等待数据库调用完成,大量线程,并查看应用程序的执行情况.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读