简体   繁体   English

真的需要一个db连接池用于unicorn rails吗?

[英]Really need a db connection pool for unicorn rails?

I can't find any document describing database connection pooling effect for unicorn . 我找不到任何描述独角兽数据库连接池效应的文档。

Unicorn forks several worker processes. Unicorn分叉了几个工人流程。 I configured prefork and it's critical not to share database connections between workers, so I reset db connections after fork. 我配置了prefork,关键是不要在worker之间共享数据库连接,所以我在fork之后重置db连接。

My rails application has 8 workers per server, and the pool size in database.yml is 5, then I saw 45 connections to mysql. 我的rails应用程序每个服务器有8个worker,而database.yml中的pool大小是5,然后我看到了45个与mysql的连接。

Each worker is single-threaded that handles 1 request at a time. 每个worker都是单线程的,一次处理1个请求。 SQL queries should be blocking. SQL查询应该是阻塞的。 Seems the other 4 connections are useless? 似乎其他4个连接都没用? 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. 由于每个工作人员一次只能处理1个请求,因此每个工作人员一次也只能使用一个连接,并且没有任何东西可以获得更多连接。 If you set the pool size to 1, each Unicorn worker should open one connection. 如果将池大小设置为1,则每个Unicorn工作程序应打开一个连接。 You will likely not get a noticeable performance increase but you will save resources by having fewer open connections. 您可能不会获得明显的性能提升,但您可以通过减少打开的连接来节省资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM