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

Support keep-alive #5

Closed
duncan-bayne opened this issue Sep 15, 2015 · 6 comments
Closed

Support keep-alive #5

duncan-bayne opened this issue Sep 15, 2015 · 6 comments

Comments

@duncan-bayne
Copy link

Support HTTP keep-alive for speedier requests.

(I'll be addressing this with a PR soon ...)

@mikecmpbll
Copy link
Owner

hi @duncan-bayne. is this the same Keep Alive as described here https://api.developer.betfair.com/services/webapps/docs/display/1smk3cen4v3lu3yomq5qye0ni/Keep+Alive ? if so, that appears to be a session extender implemented by Betfair rather than the keep-alive HTTP header that you linked to. (for what it's worth, this looks like it might be a useful addition too.)

If it's the HTTP keep-alive that you're referring to, do you have any links that show that Betfair recommend a persistent connection? (makes sense, but just want to be sure!)

@mikecmpbll
Copy link
Owner

nvm w.r.t. my last question, found something:

We recommend that Connection: keep-alive header is set for all requests to guarantee a persistent connection and therefore reducing latency.

https://api.developer.betfair.com/services/webapps/docs/display/1smk3cen4v3lu3yomq5qye0ni/Optimizing+API+Application+Performance

look forward to the PR!

@duncan-bayne
Copy link
Author

Okay, so I might have been a little optimistic in describing the PR as coming 'soon' :)

It turns out HTTPI doesn't support keep-alive, at least not yet.

I've modified my app to use Faraday with net-http-persistent. That works really nicely; connections are kept open, and overall processing time drops way down.

So ... would you be open to the idea of a PR that switches this library over to using Faraday? It'd be a pretty major change.

@mikecmpbll
Copy link
Owner

crap.

hmm, Faraday isn't desperately different in design to HTTPI, in that it supports multiple adapters, so in theory it should be possible to write a net-http-persistent adapter for HTTPI or modify the net-http adapter or something.

i'll take a look this evening!

@mikecmpbll
Copy link
Owner

not forgotten about this, just been super busy. hope to look at it in the next week or so 😘

@mikecmpbll
Copy link
Owner

riight so, finally got around to looking at this. because we're using HTTPI, kind of the advantage of it is you can use whichever underlying client library you want (whether we want to continue this way is another question).

there's already a net-http-persistent adapter for HTTPI, and at least one other adapter (httpclient) which supports keep-alive, so in my view we don't need to make any changes except to the README to make it clear that it's recommended that you use a keep-alive connection. to use net_http_persistent, simply:

require 'betfair'
HTTPI.adapter = :net_http_persistent # because it's lower precedence than net-http

as far as i can tell, httpclient automatically caches connections where the server supports it, so simply using that adapter should be enough to use a persistent connection. because the httpclient has the highest precedence of the adapters, simply having it installed and in your load path is enough to use that adapter for betfair.

i'll update the readme now.

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

No branches or pull requests

2 participants