You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Perhaps I'm missing something obvious, but when I try to use this gem to optimize multiple calls to the same endpoint, but from different code blocks, it doesn't work.
Version 2.9.4 of the gem worked fine. The ConnectionPool in V2 appears to have been stored as class variable. When upgrading to version 3.0.1 I only see optimizations if I keep the instance of Net::HTTP::Persistent.new around and use it to make all of my calls.
Am I doing something stupid? (btw, the reason I can't keep the instance around is that I'm actually making a call through Savon, which uses HTTI, and it creates the the Net::HTTP::Persistent instance.
Example Code:
The setup (not interesting, just gets us ready):
require 'httpi'
require 'benchmark'
def bench(&block)
time = Benchmark.measure do
5.times do |i|
t = Time.now
yield
puts "Request took #{Time.now - t} seconds"
end
end
puts "Total time #{time.real}"
end
# here are a couple of sites to try with. They are geographically far from me, so good for testing.
url = "https://eryang.world.tmall.com"
url = "https://kenh14.vn"
Testing with HTTPI - every request is just as slow as the last:
puts "**** Testing with HTTPI\n\n"
HTTPI.adapter = :net_http_persistent
request = HTTPI::Request.new(url)
bench do
HTTPI.get(request)
end
Testing using the same HTTP:: Persistent instance - we see a speed improvement here:
puts "**** Testing with Net::HTTP::Persistent with existing instance"
http = Net::HTTP::Persistent.new name: 'my_app_name'
bench do
response = http.request url
end
Testing as if each block of code creates its own HTTP:: Persistent instance. This is slow.
puts "**** Testing with Net::HTTP::Persistent with new instance"
bench do
http = Net::HTTP::Persistent.new name: 'my_app_name'
response = http.request url
end
If you try the first example above using version 2.94 of the gem it is fast.
The text was updated successfully, but these errors were encountered:
Perhaps I'm missing something obvious, but when I try to use this gem to optimize multiple calls to the same endpoint, but from different code blocks, it doesn't work.
Version 2.9.4 of the gem worked fine. The ConnectionPool in V2 appears to have been stored as class variable. When upgrading to version 3.0.1 I only see optimizations if I keep the instance of
Net::HTTP::Persistent.new
around and use it to make all of my calls.Am I doing something stupid? (btw, the reason I can't keep the instance around is that I'm actually making a call through Savon, which uses HTTI, and it creates the the Net::HTTP::Persistent instance.
Example Code:
The setup (not interesting, just gets us ready):
Testing with HTTPI - every request is just as slow as the last:
Testing using the same HTTP:: Persistent instance - we see a speed improvement here:
Testing as if each block of code creates its own HTTP:: Persistent instance. This is slow.
If you try the first example above using version 2.94 of the gem it is fast.
The text was updated successfully, but these errors were encountered: