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

时间:2022-08-04 17:00:24

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.

Unicorn分叉了几个工人流程。我配置了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. SQL queries should be blocking. Seems the other 4 connections are useless? Can I set the pool size to 1 for better performance?

每个worker都是单线程的,一次处理1个请求。 SQL查询应该是阻塞的。似乎其他4个连接都没用?我可以将池大小设置为1以获得更好的性能吗?

1 个解决方案

#1


7  

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.

由于每个工作人员一次只能处理1个请求,因此每个工作人员一次也只能使用一个连接,并且没有任何东西可以获得更多连接。如果将池大小设置为1,则每个Unicorn工作程序应打开一个连接。您可能不会获得明显的性能提升,但您可以通过减少打开的连接来节省资源。

#1


7  

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.

由于每个工作人员一次只能处理1个请求,因此每个工作人员一次也只能使用一个连接,并且没有任何东西可以获得更多连接。如果将池大小设置为1,则每个Unicorn工作程序应打开一个连接。您可能不会获得明显的性能提升,但您可以通过减少打开的连接来节省资源。