"What should be wrong with Ruby's Net:HTTP implementation?", one might ask. Adam Nelson was surprised by what he saw in an application that transfers huge amounts of data. "What actually happens is the CPU redlines, and the data are transferred in 1024 byte chunks.", Adam found out in his first analysis. The actual problem is that "it puts a timeout around every single rbuf_fill call," writes Alex Young, "so by default it has to spawn a new thread for every 1K of data it intends to receive".

A comparison between various implementations of Ruby and different libraries showed that Ruby 1.8.6 uses "twice as much CPU usage as the nearest competitor", that is Ruby 1.8.7, which apparently uses a larger buffer (16K). Interestingly, Ruby 1.9.0 has the lowest CPU usage, with an implementation that uses readpartial, "no timeout for socket reads" and "pre-allocated String buffer for each read". Close behind is RFuzz, a pure Ruby implementation based on the Mongrel core by Zed Shaw.

This issue isn't new, a thread on the ruby-talk mailinglist from 2006 discusses the problem and workarounds that avoid the problem for now.

In addition, this is also a good example how helpful and valuable having open source implementations can be.