Use own connection pool for redis

Sidekiq use connection pool internally, with short timeout (1s by default)
On heavy load of workflow creation (>1000 in same time), this pool is quickly
filled and job creation failed with a timeout after waiting for pool allocation
Seems this is not a trouble for Sidekiq base worker creation but only for
workflow/job here
Sidekiq doc seems saying the connection pool is sized for internal purpose only
(size = 2 + concurrency)
So move to own connection pool with longer timeout to workaround the deadlock
and to avoid any possible conflict with Sidekiq
master
aeris 2 years ago
parent 60b753382b
commit 434da61c5f
  1. 11
      lib/sidekiq/workflow/client.rb

@ -5,11 +5,16 @@ require 'json'
class Sidekiq::Workflow::Client
include Singleton
def configure(config)
@ttl = config.delete(:ttl) { 60 * 60 * 24 * 30 }
DEFAULT_REDIS_TTL = 60 * 60 * 24 * 30 # 1 month
DEFAULT_POOL_TIMEOUT = (60 * 60).freeze # 1 minute
DEFAULT_POOL_SIZE = 10.freeze
def configure(config, timeout: DEFAULT_POOL_TIMEOUT, size: DEFAULT_POOL_SIZE)
@ttl = config.delete(:ttl) { DEFAULT_REDIS_TTL }
Sidekiq.configure_server { |c| c.redis = config }
Sidekiq.configure_client { |c| c.redis = config }
@redlock = Redlock::Client.new [Redis.new(config)]
@pool = ConnectionPool.new(timeout: timeout, size: size) { Redis.new config }
end
def persist_workflow(workflow)
@ -84,7 +89,7 @@ class Sidekiq::Workflow::Client
def redis(&block)
# @pool.with { |r| r.multi &block }
#@pool.with { |r| block.call r }
Sidekiq.redis &block
@pool.with &block
end
def persist_jobs(redis, jobs)

Loading…
Cancel
Save