-
Notifications
You must be signed in to change notification settings - Fork 321
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 connection reuse #184
Conversation
cc @tarcieri |
Last bit of work in and it should go green now. I've added as many state checks for things like recovering from errors that I can think of. Since body's are lazily loaded, I've added sequence IDs. If you make multiple requests, you need to either have read out a body before making the next one, or you can't use the body later without it erroring. |
There was a discussion about connection re-use: #121 # @param [Hash] opts
# @option opts [Array<#to_s>] :hosts ([]) Makes sure connections persist for
# the given list of hosts only. Any host if empty.
# @option opts [#to_i] :pool_size (5) Amount of simultaneous open connections.
def persistent(opts = {}); end |
My concern with using a connection pool is that it adds a lot of additional complexity and I'm not sure that call patterns are worth it. The |
Yeah, I like that this is doing the simple thing, and agree that if pools are needed, |
Then I must admit I was thinking about some absolutely different API :D |
@sferik Hah no problem. We're replacing our use of Net::HTTP::Persistent and the only gems with proper conn reuse are either JRuby or libcurl based :( |
Made a quick change. On any exception we reset the conn, rather than a specific subset of network related ones. Mostly it's a safety measure to be sure we don't have mixed requests/response. |
👍 |
Adds a connection reuse API to http.rb, via
HTTP.persistent("http://www.google.com")
.Results in reusing a connection. I went with the redundant host being passed because it keeps the API consistent. I could make it just
/foo
or/bar
calls too.