Net::HTTP Start vs New

Viewed 3344

Ruby Version: 1.9.3

http://ruby-doc.org/stdlib-1.9.3/libdoc/net/http/rdoc/Net.html The documentation states that "If you wish to re-use a connection across multiple HTTP requests without automatically closing it you can use ::new instead of ::start"

http://ruby-doc.org/stdlib-1.9.3/libdoc/net/http/rdoc/Net/HTTP.html#method-c-new This documentation states that "Creates a new Net::HTTP object without opening a TCP connection or HTTP session. "

Scenario:

My aim is use re-use HTTP and TCP connections as much as possible. If i am using Net::HTTP.start as my HTTP object, and if there is a significant delay between two successive calls ( > 2 minutes), the first call after the delay is failing with EOFError : end of file reached.

So, I am planning to swap Net::HTTP.start with Net::HTTP.new

Questions:

If i use new instead of start, will new re-use connections? or will it try to create a new HTTP and TCP connection everytime a HTTP call is made?

Will there be a performance impact because of this? What is the best way to handle in scenarios like these, where we want to make HTTP calls in a high volume traffic?

1 Answers
Related