Really need a db connection pool for unicorn rails?

爷,独闯天下 提交于 2019-12-21 04:35:15

问题


I can't find any document describing database connection pooling effect for unicorn.

Unicorn forks several worker processes. I configured prefork and it's critical not to share database connections between workers, so I reset db connections after fork.

My rails application has 8 workers per server, and the pool size in database.yml is 5, then I saw 45 connections to mysql.

Each worker is single-threaded that handles 1 request at a time. SQL queries should be blocking. Seems the other 4 connections are useless? Can I set the pool size to 1 for better performance?


回答1:


Since each worker can only serve 1 request at a time, each worker can also use only one connection at a time, and nothing is gained from having more connections. If you set the pool size to 1, each Unicorn worker should open one connection. You will likely not get a noticeable performance increase but you will save resources by having fewer open connections.



来源:https://stackoverflow.com/questions/8663529/really-need-a-db-connection-pool-for-unicorn-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!