Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added shared connection option for worker group #266

Merged
merged 3 commits into from
Jun 5, 2017

Conversation

mikebobrov
Copy link
Contributor

No description provided.

@michaelklishin
Copy link
Collaborator

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

@@ -29,7 +29,9 @@ def run
worker_classes = worker_classes.call
end

@workers = worker_classes.map{|w| w.new(nil, pool) }
bunny_connection = config[:share_bunny_connection] ? create_bunny_connection : nil
Copy link
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?

@@ -52,5 +54,11 @@ def stop
@stop_flag.set!
end

def create_bunny_connection

Copy link
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
Contributor Author

did the requested changes

@michaelklishin
Copy link
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
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
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
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
Collaborator

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

@gabrieljoelc
Copy link
Collaborator

gabrieljoelc commented Jun 5, 2017

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
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
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
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
Collaborator

Should we add something to the README or the wiki?

@michaelklishin
Copy link
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