-
-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: what's the correct way to handle database connection pool size when using cron #443
Comments
I should also add that I have studied the readme but as I understood it, the complexity with connection pool size was with |
Yes. Cron runs in background thread(s), and each thread will consume a database connection from the pool. The Note: It's possible to change the implementation for the CronManager to run on a dedicated and explicitly sized Thread Pool, which would give a bit more certainty to the number of database connections consumed. At the moment, I would recommend that your database pool size GoodJob will check in database connections at the end of each operation (e.g. executing a job, enqueuing a cron entry), so it's possible to to run with less database connections than threads, but that leaves open the possibility that you will hit the limit under load, which will result in those database connection timeouts. |
Thank you @bensheldon ! It makes a lot of sense and with that calculation I needed to double my database pool size. I'm deploying that change now and feel pretty confident it will resolve my issue! :) ❤️ |
Hi @bensheldon
I'm using good_job in my kubernetes setup. I run 2
worker
pods that are started withbundle exec good_job start
. The relevant configuration isI've been seeing
ActiveRecord::ConnectionTimeoutError
recently. Here's a full log entry:which got me wondering if the database connection pool setup is correct.
Does the "cron" process use a connection from the pool?
I should add that I was seeing the errors at a time where a lot of jobs was being retried (using
wait: :exponentially_longer
) but never the less I wouldn't expect this error.Also: I considered whether it would be better to run a separate
scheduler
pod that I could limit to always only have 1 replica and that I would start with--enable-cron
but I then realised that it runs the cron process AND the worker process so I figured that was not the intended setup :)The text was updated successfully, but these errors were encountered: