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

Basic support for ConnectionPool and persistent connections #351

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

marshall-lee
Copy link
Contributor

This PR adds a connection pool options and also tells in README about a benefit of persistent connections. Not informing users about Net::HTTP weakness is just harmful, I think :)

@marshall-lee
Copy link
Contributor Author

...When comparing Her to ActiveRecord it's the one of the important features Her lacks. And since creating connections is done by Her itself there is no other way to setup a pooling than add its support to Her.

connection_pool gem with its simple with { ... } semantic (acquire connection from pool for every request and release it immediately) is very suitable for stateless protocols like HTTP.

@marshall-lee
Copy link
Contributor Author

You can read more about all this stuff in the updated README

@marshall-lee marshall-lee mentioned this pull request Jul 6, 2015
@marshall-lee marshall-lee force-pushed the connection_pool branch 3 times, most recently from 8fa2f81 to 5288afd Compare July 6, 2015 14:50
@marshall-lee
Copy link
Contributor Author

@hubert I don't think so. Using a connection pool is optional so installing a connection_pool gem is also optional. Her should not require it to work — marshall-lee@5288afd#diff-6b1740b8978bf165426acae9d1c17138R1

@marshall-lee
Copy link
Contributor Author

add_runtime_dependency is an alias to add_dependency 😃

@marshall-lee
Copy link
Contributor Author

I made it a development dependency only for running connection pool-related specs.

@marshall-lee
Copy link
Contributor Author

Maybe it is worth to add a connection_pool as a dependency and use it every time. Even if there's only one connection, having a pool will automatically solve thread safety issues. However it can confuse existing Her users that have long running queries — they can get a Timeout::Error accidently.

@marshall-lee
Copy link
Contributor Author

bump! /cc @hubert

@hubert
Copy link
Contributor

hubert commented Aug 12, 2015

@marshall-lee thanks as always for your contributions. this was actually on my list of things to enhance for her, so really glad that you are taking this one. have a few questions/comments.

  1. could you create a new connection_pool_spec file that exercises the connection pool code? also, i'd like to see some specs that validate that the connection pool code is doing the right thing, in addition to just running without error. i know metaprogramming let's you really reduced the code you write, but it would be nice to have specs that document and exercise each of the methods that is generated.

  2. i know Net::HTTP:Persistent maintains it's own connection pool. have you tested the code with this adapter to make sure they work nicely together?

  3. could you move the additions to the README into the advanced section?i believe the top section should really be focused on getting the user up and running.

@marshall-lee marshall-lee force-pushed the connection_pool branch 2 times, most recently from da39257 to e498097 Compare August 20, 2015 10:22
@marshall-lee
Copy link
Contributor Author

@hubert

  1. could you create a new connection_pool_spec

done!

  1. i know Net::HTTP:Persistent maintains it's own connection pool. have you tested the code with this adapter to make sure they work nicely together?

It doesn't require a setup_pool at all and I mentioned it in README. However when using it with setup_pool nothing harmful will occur. There will be no concurrent workload from multiple threads on a single Net::HTTP::Persistent instance so its own pool just won't be used.

  1. could you move the additions to the README into the advanced section

done!

@marshall-lee
Copy link
Contributor Author

cc @hubert

@hubert hubert self-assigned this Sep 4, 2015
@scottraio
Copy link

+1

@marshall-lee
Copy link
Contributor Author

cc @edtjones @Foxpaul :)

@edtjones
Copy link
Collaborator

edtjones commented Dec 27, 2016 via email

@marshall-lee
Copy link
Contributor Author

marshall-lee commented Apr 21, 2017

@edtjones Hi Ed! Sorry for late response.

Should we go one step further and use something with swappable backends like httparty?

Only if someone really-really needs it and wants to contribute :) But for me it would be ridiculous because Faraday itself is a solution for swappable backends. BTW supporting HTTParty doesn't make any sense because it's just a convenient wrapper around Net::HTTP but its benefits will be hidden from the user.

Nevertheless, making our own swappable backends solution won't become harder after adding a connection pool, it's implementation-agnostic.

with a connection pool the requests are usually blocking, so you can run out of connections. Obviously, disregarding the negative side effects of resending the same tcp packets in Net::HTTP, that wouldn't happen in the current implementation. Does that mean that this could break an existing implementation if someone naively added a connection pool which is too small?

Yes. Rule of thumb is to make a pool size equal to threads count.

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.

4 participants