P
P
pup_pupets2016-08-19 00:10:41
Ruby on Rails
pup_pupets, 2016-08-19 00:10:41

How to deal with multiple workers and "could not obtain a database connection within 5.000 seconds"?

I have about a couple of dozen workers who do something there and Sidekiq launches them. It is planned that about 50 more pieces will be added. But the trouble is, they all write certain information into a certain table. Not just like that, but to the point. And sometimes, or rather often happens "could not obtain a database connection within 5.000 seconds". I have already set pool = 10, it's still not enough. Doing 1 pool for each worker is bad. But how then to solve the problem?
As I understand it, it is necessary to throw all requests in the queue or do something like check if the database is free and wait until it is free. However, there is no knowledge of this kind and I don’t really understand what exactly to dig.
Can anyone suggest the best way to resolve the issue? Or how do the right guys do?) Thank you

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
pup_pupets, 2016-08-27
@pup_pupets

https://brandur.org/postgres-queues

S
sim3x, 2016-08-19
@sim3x

Правильные лузгают семки
Девопсы советуют настроить СУБД под свою нагрузку

A
A_Modestov, 2016-08-25
@A_Modestov

1. Определяешь глобальную переменную, к примеру SIDEKIQ_CONCURRENCY в .env
2. Запускаешь sidekiq через rake задачу с указанием concurrency, примерно так:

namespace :sidekiq do
  desc "TODO"
  task start: :environment do
    exec "sidekiq -c #{ENV['SIDEKIQ_CONCURRENCY']}"
  end
end

3. В database.yml добавляешь:
pool: <%= ENV['SIDEKIQ_CONCURRENCY'].to_i + 5 %>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question