Green Computing with C++

Dean Michael Berris By Dean Michael Berris
Expert Author
Article Date:

Have you heard of green computing? It’s basically the concept of lowering the energy requirements of computers in order to reduce the carbon footprint of datacenter operations and desktop/mobile applications. The idea is that since computers already suck out a lot of juice from the power grid around the world, at least we should be able to reduce the amount of heat that the computers generate to save on the costs of cooling the machines in data centers.

There are a lot of ways to do this from the external side of the equation – design well ventilated data centers like the ones Google and Yahoo have, consolidate multiple servers into smaller less-power hungry form factors like what SeaMicro have, etc. – but that’s not very interesting from a software developer’s standpoint. C++ to the rescue?

There had been quite some buzz a few months back about Facebook going greener by reducing the computing requirements of their web-facing web servers by developing and releasing HipHop PHP. If you haven’t heard about that yet, basically:

? With HipHop we’ve reduced the CPU usage on our Web servers on average by about fifty percent, depending on the page. Less CPU means fewer servers, which means less overhead. This project has had a tremendous impact on Facebook. We feel the Web at large can benefit from HipHop, so we are releasing it as open source this evening in hope that it brings a new focus toward scaling large complex websites with PHP. While HipHop has shown us incredible results, it’s certainly not complete and you should be comfortable with beta software before trying it out.

HipHop for PHP isn’t technically a compiler itself. Rather it is a source code transformer. HipHop programmatically transforms your PHP source code into highly optimized C++ and then uses g++ to compile it. HipHop executes the source code in a semantically equivalent manner and sacrifices some rarely used features – such as eval() – in exchange for improved performance. HipHop includes a code transformer, a reimplementation of PHP’s runtime system, and a rewrite of many common PHP Extensions to take advantage of these performance optimizations.

Facebook Developer Blog about HipHip

This I think is a testament still to how C++ is able to deliver great performance that has a noticeable impact in the real world. Ask the 500 million or so Facebook users out there. :)

Another company that stepped into going the greener route although not in a drastic manner is Evernote. I use Evernote on Android to keep my notes when I’m on the go. It’s a nifty tool that allows me to start forgetting things and just pile them on to the app. Recently, Evernote moved from C# and WPF to Native C++ on Windows.

Evernote 4 is a major departure from Evernote 3.5 in every way. While 3.5 added tons of great new features, there were some problems we simply couldn’t fix: the blurry fonts, slow startup times, large memory footprint, and poor support for certain graphics cards were all issues that the technology behind 3.5 (Windows .net and WPF) was incapable of resolving. As a result, we ended up chasing down platform bugs rather than adding the great features our users wanted.

So we decided to start over from scratch, with fast, native C++ that we knew we could rely on. As you’ll see, the results are amazing. This new version will set a foundation for rapid improvement.

Evernote Blog announcing Evernote 4

I haven’t used it on Windows yet, but I won’t be surprised that it really would perform a lot better. And these guys are making money off this application and service so I’m thinking this is yet another testament to the power of C++ even in desktop applications where others have been trying to get away from it in that arena.

Still on the web side of things, I know not a lot of people have considered writing their web applications in C++, but there is an interesting project called CppCMS, which is basically a web application framework for C++. From the official project page:

CppCMS is a Free C++ Web Development Framework (not a CMS) aimed for Rapid Web Application Development. It differs from most of other web development frameworks like: Python Django, Java Servlets or C++ Wt in following:

  1. It is designed and tuned to handle extremely high loads.
  2. It uses modern C++ as primary development language in order to achieve first goal.
  3. It is aimed on development of Web Sites rather then “GUI Like” web applications.

This is an interesting project and I’m looking to maybe using it myself for a web forum I’m thinking of developing for the (yet unnamed) company I’m bootstrapping to offer commercial support for The C++ Network Library. Of course, that is until I transition towards using my own web framework I’m thinking of developing. ;)

Green computing isn’t really all just about saving on energy, it’s also about efficiency – if you can do a lot more things in the same amount of time/energy, then technically you’re also saving energy in the long run – or thinking about it in different terms, your carbon footprint per action is lower now, because you get to do more in the same amount of energy used. It’s no secret to C++ developers that C++ is already really efficient as a programming language, an in certain situations, it’s even good enough to write operating systems in. If you like C++, you might like Haiku, a project that picks up from BeOS whose API is written in C++.

Are you working on a project that might require hundreds of servers and tons of data? If so, have you considered using C++ yet for that project? Let me know in the comments!


About Dean Michael Berris
Dean Michael Berris is the writer of C++ Soup! C++ Soup is a blog about what?s new, up-coming, and what?s going on with C++. C++ Developer with years of experience building high performance applications and implementing multi-threaded highly scalable systems.

Leave a Reply

Your email address will not be published. Required fields are marked *

  • 160×600
  • 152X252
  • Newsletter Signup

    Subscribe to our Newsletter

    * Your Email Address:
    * Preferred Format:
       First Name:
       Last Name:
  • 336×280