-
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
Connection sharing #121
Comments
This depends on #72 and adding of |
I had planned to add connection pools ala Net::HTTP::Persistent as well. @sferik is this the sort of thing you're after? |
not "needed" atm but having something like net-http-persistent in http would give me one more reason to not depend on net/http if i needed to re-use the same socket. |
@tarcieri Yes, I’m looking for something functionally similar to |
imho something like |
@johnny5- I need to be able to make separate, unchained requests using the same connection object, so this would need to work: connection = HTTP.persistent("https://www.google.com")
connection.get("/foo")
connection.get("/bar") |
there's no reason it couldn't work with my example and yours. |
i think it would mean response's would end up being stacked in |
@johnny5- I just wanted to make sure it doesn’t require chaining the requests in a single statement. |
supporting both might be odd, .get() could return a response that could proxy another .get() through to the same connection object, to implement chaining, but i think it's better if people more familiar with the code weigh in. |
I'm totally opposed to idea of proxy objects. IMHO it's confusing magic. Why one would need to call client = HTTP.persisted # => HTTP::Client::Persisted
users = client.get("http://example.com/users.json")
groups = client.get("http://example.com/groups.json") Persisted client will hold connection pool internally, so if one didn't flushed connection before making another one (above) it will create another connection. Once it will have more than one open (and fully flushed) connection to same host, it will close all superfluous ones. Also, if you will get different host - it will add another persisted connection to the pool. Persistence pool will be configurable (total size, per-host size, auto-flush upon next request). Clarification on "if one didn't flushed connection before": client = HTTP.persisted # => HTTP::Client::Persisted
# 0 open connections
puts client.get("http://example.com/users.json").to_s
puts client.get("http://example.com/users.json").to_s
# 1 open connection
resources = %w[users groups persmissions].map do |res|
client.get "http://example.com/#{res}.json"
end
# 3 open connections
resources.each { |r| r.to_s }
# 1 open connection
client.get("http://foobar.com/users.json").to_s
# 2 open connections |
My ideal API would be transparent... that each [(:http|:https), hostname, port] |
i totally agree a proxy on a response back to the original connection would be confusing as hell :) |
Resolved via #184. |
Hmmm…trying to move this issue into the v0.8.0 milestone but I’m getting an error. Maybe it’s related to the denial of service GitHub was facing earlier today? Anyway, this feature should be released in v0.8.0. |
@sferik GitHub is giving me an error when I try to do that o_O |
@tarcieri Me too. I thought it might be a permissions thing. Let’s remember to try again when GitHub isn’t under attack. I’d guess they’ve temporarily disabled some non-critical services like reassigning milestones. |
I found the workaround to assign milestones :D via issues index not from particular issue... |
@ixti 👍 |
Now that v0.6.0 has shipped, I’ve started benchmarking the
http
branch of thetwitter
gem againstmaster
, which uses Faraday with Net::HTTP.While the spec suite runs about 4X faster in the
http
branch, the following real-world example—which outputs the screen names of my Twitter friends that start and end with the letter “a”—performs about 2X slower (5 seconds vs. 10 seconds).When I run:
It produces the following output:
As you can see, I’m initializing a new TCP socket and calling
connect
for each HTTP request, which takes about a second per request. In themaster
branch, I’m able to share a single HTTP connection across multiple request, which explains why it’s about 5 seconds faster.How can I share a single connection across multiple HTTP requests with the HTTP gem? Without this feature, I won’t be able to replace
faraday
withhttp
in thetwitter
gem. 😦The text was updated successfully, but these errors were encountered: