Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

  • Blog Navigation
net/http alternatives

net/http is slow. (and so are libraries that depend on it, like open-uri)

Performance Disclaimer: this ought to matter in your app, measurably, before you do anything about it. If you profile and ruby-prof is showing a bunch of classes like BufferedRead and Timeout at the top of the list, your app qualifies. And in addition if you know that your app is dependent on data transfer over http (let’s say you’re interacting with a Solr server, and you’re storing sizable documents in Solr), you should be aware of the problem.

Otherwise net/http or open-uri might be just fine for you.

The problems with net/http, and benchmarks of ruby http client lbraries are nicely written about in An analysis of Ruby 1.8.x HTTP client performance.

Some good alternatives:

Our findings matched the article referenced above – the alternatives have pros and cons but each was at least 10x faster than net/http for transfers of 50-300k response bodies.

The fastest solution we found was curb, reusing the Curl::Easy object:

require "curb"

curl =

2.times do
    curl.url = ""
    puts curl.body_str
  1. Dr Nic says:

    Thanks for the summary!

  2. For downloading purpose, might be faster and has a small memory footprint thought I’ve not yet checked in detail. ->

    net/http is enough fast when you apply a patch at ->

    On ruby 1.9.1, httpclient is faster than curb and rfuzz on my simple try (not benchmarked enough; I don’t have foreign test server), but the difference is a little.

  3. Ah! fantastic, I was always complaining about open-uri haha, curb <3

Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *

Share This