Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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?

like image 423
luikore Avatar asked Dec 29 '11 02:12

luikore


1 Answers

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.

like image 137
Moshe Katz Avatar answered Sep 18 '22 08:09

Moshe Katz