Ruby on Rails causes Global Warming


I use a laptop. Which means, as I peck away at my keyboard in the waning hours of the evening, I can smell the slow charring of my wool pants (mixed with the redolent odor of singed leg hair) as the tiny fan embedded in my computer tries desperately to keep this multi-thousand-dollar device, from melting into a pile of slag.

As a self-taught engineer, I tend to notice the glaringly-obvious – perhaps more than many of my well-educated peers. And there’s one obvious lesson in this – if solid state electronics are getting HOT, they’re wasting using a fair amount of power.

In a nuclear reactor somewhere out there, an atom died for the pixels on my screen. Another few drops of precious oil, or a few tons more gasified coal, were spilt for those extra minutes of Microsoft Word (or perhaps “Grand Theft Auto 4″).

Moore’s Law has shown us how the steady change of computing SPEED (doubling), and COST (halving), has reliably powered our advancing Information Age. Yet nothing in Moore’s Law has halted the seemingly inexorable increase in ENERGY requirements, of these most devious of machines.

This is not a problem that we’ve address head on – in our subsidized energy economy, there has been no real motivation to do so. In fact, as our dependency on computing infrastructure has deepened, we’ve made it WORSE. Here’s how it works:

“Hey Jim, did you realize that these hard drives fail as they get older? And really reliable hard drives are WAY more expensive.”

“Wow! That SUCKS! Why don’t we just put TWO hard drives in every computer, and copy all the data to BOTH of them?”

No joke. We’ve also done the same thing with (redundant) power supplies, and since all these extra disks and transformers are putting out more HEAT – we’ve had to install more AIR CONDITIONING, too. Oh, and in the REALLY high-end data centers, we’ve got at least one (sometimes two or more) Diesel Generators running at all times – just in CASE the power goes out.

As is typical of the world’s larger problems, the smartest folks haven’t done better – they’ve just done WORSE… in a more complicated way. Let’s take a look at programmers.

Writing software has changed a lot since we started this business. We’ve drifted from the “low-level” languages, up through the “high-level” languages, to things now rightly called “frameworks” that are too abstracted to be considered a language at all.

But along the way (with all this gratuitous computing power sitting around), we’ve gotten UNBELIEVABLY lazy. Here’s an example – it is, by no means, the only one:

Ruby on Rails. A very popular framework, with some fairly typical problems.

Ruby is not, to start with, an efficient language. This means it doesn’t do a very good job of translating “high-level” code, into “low-level” machine code.

Rails, as a framework, is intended to be really easy to use. Which means it does a LOT of stuff for you – much of which you don’t actually need done, in any given case.

Rails uses a database access pattern called “Active Record”. It’s pretty cool, actually – it encapsulates about 10 layers of abstraction, into a few easy-to-use commands.

Unfortunately, that encapsulation ignores most performance impacts. Also unfortunately, the implementation of that pattern – is not thread-safe.

Here’s where the laziness kicks in – rather than fixing the ActiveRecord implementation, or making ruby more efficient in general, someone wrote Mongrel.

What’s Mongrel? An extra web-serving layer, it simply manages a bunch of ruby instances, and hands http requests back and forth. It’s a workaround for the thread-safety problems we were mentioning above.

In software development, it’s called a “Kludge”. In human society, it’s called a “Rat Race”. (We all drive SUVs, even when we object to them environmentally, because we need to be safe – safe in case someone ELSE driving an SUV crashes INTO us. Are you starting to appreciate the irony?)

“So what,” I can hear you saying, “Buying more hardware is cheaper than fixing a whole language, right?”

Yes, it is. And that’s the problem.

Because there are other, more insidious, global impacts of this wasteful computing philosophy. If you need a wickedly fast CPU and a few gigs of Ram to run a Ruby on Rails server, might as well turf out the old servers, right? Those old servers end up as e-waste in developing nations. (HEADLINE: “Lazy coding kills children in the third world”)…

Now, I’m not espousing a return to the good-ol-days of hand-coded assembler, or even web apps written in pure C. But I’ve managed 10,000 http requests per second on a single server (yes, including DB) – simply by taking the extra day or so to tune the database, install some byte-code cacheing – oh, and not running RoR.

Even if you don’t care about the 12 year old kids dying in Thailand while they bake your discarded motherboard over a camel-dung campfire – at least think about the abuse you’re putting your electrons through.

(Editor’s note: Many thousands of electrons were tortured in the writing of this blog post. And yes, this is deliberately provocative link-bait for my overly-zealous RoR-fanatic friends. Which doesn’t make it any less true.)

, , , , , , , , , ,

  1. #1 by Ian on 13Nov08 - 12:42 am

    That’s why I switched to merb… ;-)

  2. #2 by Britt Selvitelle on 13Nov08 - 1:19 am

    A well written article, and it fantastically ties modern software development to energy activism. I agree on all accounts. Frankly though, by pinpointing Ruby on Rails, you take focus away from the core content. You shouldn’t need, for example, the ending statement:

    “And yes, this is deliberately provocative link-bait for my overly-zealous RoR-fanatic friends. Which doesn’t make it any less true.”

    If I were to rewrite it, I would focus on the underlying argument, and then follow up with the seemingly boundless examples of wasteful computing. That being said, an obscure topic like this probably demands feet being held to the fire, and the act of calling out one amongst many will hopefully lead to further conversation. Can’t wait for followup articles.

  3. #3 by Jeff Ward on 13Nov08 - 2:08 pm

    Oh no you dih-ehnt :)

  4. #4 by Doug Ransom on 15Nov08 - 8:12 am

    It is true to make computers do more operations has increased energy use – though speed and energy use are two things the industry is always working on. We can see examples of improvement, like the fact you can run an IPod for hours — how much energy can that take? — and flash memory competing with magnetic storage for larger and larger applications.

    Fortunately, you live in a heating climate 6 months of the year, so your computers at home are only wasting energy 6 months of the year. At a data center, well they are always cooling.

    There are some interesting economics to think through:
    - you use wasteful rails to produce something of value – that is a huge social benefit. People pay you money to make their lives better. Maybe you would never be profitable if you spend 45 times development cost to build your product in C . Or even started.
    - you will always be looking for ways to be more profitable. If your product on rails is so profitable that computer cycles become a major expense for your solution, you are going to find a way to make it cheaper. By rewriting it, by moving to a data center with cheaper operating costs (because they have less cooling costs, or a cheaper energy source). If operating more hardware is the most profitable approach, it is the best approach for the environment and the economy. The good news is you just need to focus on profits to maximize social benefits.

    As far as foreign workers being exposed to hazards, I think it is the role of their foreign governments and not pressure (or thinly-disguised trade barriers)from US or Canada to protect their workers. I have no doubt as China’s economy evolves and improves their environmental regulations, or enforcement of existing regulations will improve. China’s government will attempt to do the best for China. Though I would like to see them adopt a constitution protecting Life, Liberty, and Pursuit of (insert corollary of liberty here).

    Going through an industrialization/pollution/cleanup cycle seems to be the way modern economies emerge. China is moving through these phases more rapidly than we did.

  5. #5 by Jeremy Dunck on 10Dec08 - 10:27 am

    You can argue for efficiency to reduce supply-chain inefficiencies, but it’s more effective in manufacturing due to its scale and different deployment (i.e. not every driver is a mechanic).

    I hear ecologically-aware people argue that the Green Revolution was a bad thing– it’s certain we’ll have hard times ahead unless we find some alternate tech post haste– but I’d argue that maybe the other billion people are also useful.

    As far as energy consumption, I place my near-term bet on SSD, and mid-term bets on memristors. Long-term, we’ll need to be off petro. If you’re arguing that entropy in general, is bad, I agree, but we can’t change it– we can only channel the flow towards eventual heat death.

    I don’t know how much of our e-waste is due to cheap-driven e-lust hardware turnover and how much is actual at-scale failure and replacement. That’d be interesting to see. If our only at-scale solution is to stop using computers, well, that’s a tough call.

  6. #6 by Chad on 14Feb09 - 12:29 am

    Amen to that! I still believe we can end up with expressive languages _and_ a high computation to watt ratio. Maybe someday I’ll end up working on that.

  7. #7 by Joel Franusic on 14Feb09 - 12:45 am

    Speaking of old computers, I just got rid of a bunch. In the process of finding recyclers, I ran across this outfit http://www.crc.org/ – they seem pretty cool?

(will not be published)

Close
E-mail It