Created
January 28, 2013 22:41
-
-
Save xxx/4659986 to your computer and use it in GitHub Desktop.
initialization of sidekiq, the hard way
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defaults: | |
:port: 6379 | |
:host: localhost | |
development: | |
:db: 2 | |
:namespace: development | |
# force use of Redis::Distributed | |
:host: | |
- localhost |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
datastore_config = YAML.load(ERB.new(File.read(File.join(Rails.root, "config", "redis.yml"))).result) | |
datastore_config = datastore_config["defaults"].merge(datastore_config[::Rails.env]) | |
if datastore_config[:host].is_a?(Array) | |
if datastore_config[:host].length == 1 | |
datastore_config[:host] = datastore_config[:host].first | |
else | |
datastore_config = datastore_config[:host].map do |host| | |
host_has_port = host =~ /:\d+\z/ | |
if host_has_port | |
"redis://#{host}/#{datastore_config[:db] || 0}" | |
else | |
"redis://#{host}:#{datastore_config[:port] || 6379}/#{datastore_config[:db] || 0}" | |
end | |
end | |
end | |
end | |
Sidekiq.configure_server do |config| | |
config.redis = ::ConnectionPool.new(:size => Sidekiq.options[:concurrency] + 2, :timeout => 2) do | |
redis = if datastore_config.is_a? Array | |
Redis::Distributed.new(datastore_config) | |
else | |
Redis.new(datastore_config) | |
end | |
Redis::Namespace.new('resque', :redis => redis) | |
end | |
end |
With this configuration, if i have configured a CONCURRENCY setting of 5, I will have 7 workers running? How many of these are going to process jobs from Server1 vs Server2? Is there a way of controlling that?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you please explain what is the significance of line 29?