BT

What Is Wrong With Ruby's Net::HTTP?

| by Mirko Stocker Follow 0 Followers on Nov 14, 2008. Estimated reading time: 1 minute |

"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.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT