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

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

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...