Does RestCore really use keep-alive connection?

7 views
Skip to first unread message

Man Vuong

unread,
Nov 19, 2014, 5:22:27 AM11/19/14
to rest...@googlegroups.com
According to the README saying that RestCore uses persistent connection, but when I look into the code of rest-core/engine/http-client.rb I saw this:

def request promise, env
  client
= ::HTTPClient.new
 
# ...
end

It seems that a new client/connection will be created for each new request. Look like a kind of confusing here?

Lin Jen-Shin (godfat)

unread,
Nov 19, 2014, 7:40:34 AM11/19/14
to rest...@googlegroups.com
Yes. RestCore didn't do anything here, all the persistent connections
are handled by HTTPClient. You could read the source here:
(Honestly, I didn't verify if httpclient did everything correct here)

For each new client, HTTPClient would create a HTTPClient::SessionManager:
https://github.com/nahi/httpclient/blob/v2.5.3.3/lib/httpclient.rb#L414

For each new request, the client would try to get a connection (session)
from the session manager:
https://github.com/nahi/httpclient/blob/v2.5.3.3/lib/httpclient/session.rb#L207-L211

From there, it would try to find a valid connection from the pool managed
by the session manager:
https://github.com/nahi/httpclient/blob/v2.5.3.3/lib/httpclient/session.rb#L264-L266

Therefore I think we could conclude that HTTPClient has an internal session
manager which would manage a connection pool, and for each request, it would
try to reuse an existing persistent connections if possible.

Frankly speaking since I didn't verify if this is really the case,
please let me know if you found that we still need to do anything to tell
HTTPClient to keep a persistent connections pool :)

Man Vuong

unread,
Nov 22, 2014, 5:23:46 AM11/22/14
to rest...@googlegroups.com
Thank you Lin, very detailed reply :)
Reply all
Reply to author
Forward
0 new messages