Running concurrent background jobs with sequel slowly kills my connection limit #2247
Replies: 2 comments 2 replies
-
By default, Sequel keeps a reference to all created Database objects. If you do not want that, you can use the Note that each Sequel::Database object has it's own pool of connections. I cannot tell if the reason you are doing |
Beta Was this translation helpful? Give feedback.
-
In case it's useful, we have a similar thing for WebhookDB, where we manage our own pool of databases: https://github.com/webhookdb/webhookdb/blob/main/lib/webhookdb/connection_cache.rb Then you can do stuff like |
Beta Was this translation helpful? Give feedback.
-
Problem
I'm running ~6 queries concurrently in background jobs, and it's killing my database (exceeding connection limits). The connections clean up the first few runs but then increase linearly until the db connection limit is reached and it dies.
Question
Am I disconnecting from the db properly in the jobs? Any suggestions would be greatly appreciated I'm totally stumped. I don't know if I'm managing the connections poorly by calling (my method)
connected
on the db before I try to run something, or if I'm supposed to be clearing the DB[key] when I disconnect (although I tried that and it didn't seem to solve the issue).Summary
I'm connecting to a database in a Sidekiq job to create a chart of query results. For reasons I cannot figure out the connections just increase with each job until everything dies. I load and execute a bunch of queries (~6) on a single page, so the jobs kick off around the same time.
Before I try to run the SQL I call a
connected
method which is designed to tell me if the db successfully connected. In the below method,db
isThe problematic job (it seems if I remove this everything is fine)
The job is below. I've tracked the
Destroying connection for query
logs and it seems this is being called for every query.Here's the job that opens connections and only sometimes closes them....
I'm running queries locally with ngrok and tracking the open connections
Beta Was this translation helpful? Give feedback.
All reactions