我对独角兽,Sidekiq和数据库池大小的理解正确吗? [英] Is my understanding of Unicorn, Sidekiq and DB Pool size correct?
问题描述
我有独角兽,Sidekiq和Postgres设置。
I have Unicorn, Sidekiq and Postgres setup.
我试图了解要设置的正确配置,以免达到最大数据库连接限制。在Opsworks中,m1.small Postgres RDS实例最多可具有121个连接。
I am trying to understand the right configuration to set up so that I don't hit the maximum db connection limit. In Opsworks, the m1.small Postgres RDS instance can have a max of 121 connections.
我的数据库池大小为5。
I have a db pool size of 5.
考虑一下。 Sidekiq和Unicorn是它自己的过程。因此,每个进程的数据库池大小为5。如果我的理解错误,请纠正我。
Consider this. Sidekiq and Unicorn are its own process. So the db pool size for each process is 5. Correct me if my understanding here is wrong.
如果我有5个独角兽进程,这意味着5 * 5 = 25个数据库连接
If I have 5 unicorn process', that means 5*5=25 database connections
现在这是我有点困惑的部分,因为Sidekiq是多线程的。如果Sidekiq的并发性为5,并且数据库池大小也设置为5。这是否也意味着在给定的时间有25个潜在的数据库连接?
Now this is the part where I am slightly confused, since Sidekiq is multithreaded. If Sidekiq has a concurrency of 5. and the db pool size is also set to 5. Does that mean 25 potential db connections at a given time too?
这意味着,例如,我可能有50个数据库连接?
This means, for one instance, I could have 50 db connections?
推荐答案
在Unicorn中,每个进程都建立自己的连接池,因此,如果您的数据库池设置为5,并且您有5个Unicorn worker,则最多可以有25个连接。但是,由于每个独角兽工作者一次只能处理一个连接,因此除非您的应用在内部使用线程,否则每个工作者只会实际使用一个数据库连接。
In Unicorn each process establishes its own connection pool, so you if your db pool setting is 5 and you have 5 Unicorn workers then you can have up to 25 connections. However, since each unicorn worker can handle only one connection at a time, then unless your app uses threading internally each worker will only actually use one db connection.
在Sidekiq中,池中的连接在线程之间共享,因此每个工作人员至少需要一个连接。如果您的并发数为5,则您的池必须至少为5。
In Sidekiq, the connections in the pool are shared across threads, so you need to have at least one connection available per worker. If you have a concurrency of 5, then your pool needs to be at least 5.
池的大小大于1意味着每个Unicorn工作者都可以访问连接
Having a pool size greater than 1 means each Unicorn worker has access to connections it can't use, but it won't actually open the connections, so that doesn't matter.
您的应用程序需要的实际连接总数,除非您不使用,但实际上并不会打开连接,因此没关系。在您的应用程序代码中使用线程(并且它们不共享db连接),每个Sidekiq工作者一个线程,每个Unicorn工作者一个线程。
The total number of actual connections your app requires, unless you're using threads in your application code (and they don't share a db connection), is one per Sidekiq worker plus one per Unicorn worker.
这篇关于我对独角兽,Sidekiq和数据库池大小的理解正确吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!