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

前端之家收集整理的这篇文章主要介绍了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.如果您花费大部分时间等待数据库调用完成,大量线程,并查看应用程序的执行情况.

猜你在找的Ruby相关文章