Skip to content

added shared connection option for worker group - #266

Merged
michaelklishin merged 3 commits into
jondot:masterfrom
mikebobrov:master
Jun 5, 2017
Merged

added shared connection option for worker group#266
michaelklishin merged 3 commits into
jondot:masterfrom
mikebobrov:master

Conversation

@mikebobrov

Copy link
Copy Markdown
Contributor

No description provided.

@michaelklishin

Copy link
Copy Markdown
Collaborator

@jondot @gabrieljoelc sharing a connection should be OK. Objections to this? better option names?

Comment thread lib/sneakers/workergroup.rb Outdated
end

@workers = worker_classes.map{|w| w.new(nil, pool) }
bunny_connection = config[:share_bunny_connection] ? create_bunny_connection : nil

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just push this into the private method?

Comment thread lib/sneakers/workergroup.rb Outdated
end

def create_bunny_connection

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an extra space here and 62.

@mikebobrov

Copy link
Copy Markdown
Contributor Author

did the requested changes

@michaelklishin

Copy link
Copy Markdown
Collaborator

@gabrieljoelc this generally LGTM.

Bunny.new(Sneakers::CONFIG[:amqp], :vhost => Sneakers::CONFIG[:vhost], :heartbeat => Sneakers::CONFIG[:heartbeat], :logger => Sneakers::logger)
end

def create_connection_or_nil

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid it's not obvious what the effects of passing in a Bunny::Session instance vs. a nil are. Can you please add a comment explaining that a non-nil connection will be used as is, and a nil will ensure workers open their own?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikebobrov sorry, I know this PR has been open for a while but before we ask @gabrieljoelc to review it one last time, can you please leave a comment as requested above? Thank you.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure. no problem. sorry for the delay. i commented out the invocation of the function. hope it's rather helpfull

@michaelklishin

Copy link
Copy Markdown
Collaborator

@gabrieljoelc can we get your blessing to merge this? :)

@gabrieljoelc

gabrieljoelc commented Jun 5, 2017

Copy link
Copy Markdown
Collaborator

Code looks good but is there a concern​ that existing applications using sneakers that have a larger number of consumers would have a sudden throughput drop? Here's a good thread discussing this. This answer talks about issues when using a cluster/load balancer and throughput dropping. The poster suggests using a connection pool as an alternative.

Should we consider leveraging the connection_pool gem and allowing users to configure the shared connection pool size? We could make the default configuration to use a connection per worker by default to make it backwards compatible. This would mitigate users experiencing a possible sudden throughput drop in production.

@michaelklishin

Copy link
Copy Markdown
Collaborator

@gabrieljoelc with this PR the default doesn't change: if :share_bunny_connection isn't set, each worker will open its own connection.

We have counterexamples where too many connections is a problem: #291.

Getting connection pooling right is much harder than it sounds so I'm deeply suspicious of pooling libraries by default. We can consider pooling but it's out of scope for this PR.

@michaelklishin

Copy link
Copy Markdown
Collaborator

connection_pool seems to be from the author of Dalli, so it must be good and battle tested. Still, it's out of scope for this PR and we don't really know how well it works with Bunny and automatic connection recovery (in theory it should work OK).

@gabrieljoelc

Copy link
Copy Markdown
Collaborator

@michaelklishin makes sense. I created #292 as a future alternative.

connection_pool seems to be from the author of Dalli, so it must be good and battle tested.

Also, Sidekiq documentation suggests using connection_pool.

:shipit:

@gabrieljoelc

Copy link
Copy Markdown
Collaborator

Should we add something to the README or the wiki?

@michaelklishin

Copy link
Copy Markdown
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants