How the rails database connection pool works

I am exploring the concept of a rails database connection pool. in the rails application, I determined the pool size to 5.

My understanding of the connection pool size is as follows.

1) when the server run rails automatically create n number of connections defined in the database.yml file. in my case, it will create 5 connections, since the pool size is 5.

2) for each HTTP request, if you need to access the database, then the rails will use an available connection from the connection pool to service the request.

But my question is that if I click 1000 queries at a time, then most of the request will not get access to the database connection, because the connection pool size is only 5.

As far as I understand above, that the rails connection pool is right?

Thanks,

+4
source share
2 answers

This pool size is for one process. Of course, if your application runs on several processes, you will have 5 database connections for each of them. If your server receives 1000 requests at a time, it will distribute requests between these connections when it is full, other requests are waiting in line.

+7
source

Yes, from the docs:

. , , . ConnectionPool , , , ConnectionPool. , , : , , ConnectionPool - .

: http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/ConnectionPool.html

- http-:

Unicorn , , db 5, 5 Unicorn, 25 . , - , , , db.

+7

Source: https://habr.com/ru/post/1620691/


All Articles