httpx: Performance degrading with muliple requests

As previously discussed, httpx performance is observed to degrade - pretty linearly - as requests are made. For example, this is a fragment of a benchmark run against a Rust Hyper server endpoint, each line being a batch of 5,000:

httpx      26.242188   0.515625  26.757812 ( 10.709051)
httpx      22.445312   0.257812  22.703125 ( 15.107915)
httpx      22.562500   0.351562  22.914062 ( 21.772903)
httpx      29.093750   0.289062  29.382812 ( 28.842361)
httpx      38.132812   0.500000  38.632812 ( 38.192884)
httpx      44.257812   0.328125  44.585938 ( 44.105139)
httpx      50.718750   0.406250  51.125000 ( 50.627243)

I also observed this under your own benchmark when adding support for running each test multiple times. Here’s what ruby-prof kicks up with 1,000 requests - a fairly obvious hotspot:

 %self      total      self      wait     child     calls  name                           location
 27.34      5.655     2.038     0.000     3.617  2039667  *Array#delete_if
 11.63      1.132     0.867     0.000     0.265  2095014   HTTPX::Callbacks#callbacks     /home/freaky/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/httpx-1.0.2/lib/httpx/callbacks.rb:33
 10.78      5.401     0.804     0.000     4.597  2037002  *HTTPX::Callbacks#emit          /home/freaky/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/httpx-1.0.2/lib/httpx/callbacks.rb:23
  7.11      0.724     0.530     0.000     0.194  2003000   HTTPX::TCP#socket              /home/freaky/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/httpx-1.0.2/lib/httpx/io/tcp.rb:43
  3.67      0.274     0.274     0.000     0.000  2003001   HTTPX::Connection#origin
  3.46      0.267     0.258     0.000     0.009  2153288   Hash#[] 

Which appears to intensify with 10,000 requests:

 %self      total      self      wait     child     calls  name                           location
 36.84    517.122   196.842     0.000   320.280 200406486  *Array#delete_if
 15.14    102.826    80.910     0.000    21.916 200950014   HTTPX::Callbacks#callbacks     /home/freaky/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/httpx-1.0.2/lib/httpx/callbacks.rb:33
 13.96    514.587    74.611     0.000   439.975 200370002  *HTTPX::Callbacks#emit          /home/freaky/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/httpx-1.0.2/lib/httpx/callbacks.rb:23
  9.83     71.753    52.516     0.000    19.236 200030000   HTTPX::TCP#socket              /home/freaky/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/httpx-1.0.2/lib/httpx/io/tcp.rb:43
  5.21     27.851    27.851     0.000     0.000 200030001   HTTPX::Connection#origin
  4.09     21.940    21.847     0.000     0.093 201512288   Hash#[]
  3.91     20.912    20.912     0.000     0.000 200030000   HTTPX::Connection#io
  3.71     19.817    19.817     0.000     0.000 201983103   Symbol#==
  3.60     19.244    19.244     0.000     0.000 200086474   IO#to_io

About this issue

  • Original URL
  • State: closed
  • Created 8 months ago
  • Comments: 19 (19 by maintainers)

Commits related to this issue

Most upvoted comments

Hey @Freaky ,

I didn’t forget about it 😃 I’ve already identified a couple of things. But you seem to have mainly stumbled into a regression from v1, due to the change in the default timeouts. I have a patch locally which addresses it (and the benchmark you shared is now presenting a more stable outcome), but I still need to fix a few things as a result, before sharing it back. I’ll make sure to tag you when I have a changeset to share.