Skip to content

Commit bcc4212

Browse files
committed
document connection pool size constraint for max_claims
1 parent dea0914 commit bcc4212

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,20 @@ workers will sleep for 5 seconds.
442442

443443
```ruby
444444
# The max number of jobs a worker may lock at a time (also the size of the thread pool):
445+
# NOTE: This should be less than your ActiveRecord connection pool size. The worker process
446+
# itself needs one connection for polling and locking, so if max_claims >= pool_size, a job
447+
# thread that cannot check out a connection within the checkout timeout may raise
448+
# ActiveRecord::ConnectionTimeoutError. The worker will log a warning at startup if this
449+
# is detected.
450+
#
451+
# The general rule is: if each job thread needs N connections and max_claims is M,
452+
# your pool should have at least N * (M + 1) connections. The most common case is N=1
453+
# (one connection per thread), so pool_size should be at least max_claims + 1.
454+
#
455+
# For example, if your pool size is 5, set max_claims to 4:
456+
#
457+
# # config/initializers/delayed_job.rb
458+
# Delayed::Worker.max_claims = ActiveRecord::Base.connection_pool.size - 1
445459
Delayed::Worker.max_claims = 5
446460

447461
# The number of jobs to which a worker may "read ahead" when locking jobs (mysql only!):

0 commit comments

Comments
 (0)