Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

It seems clear that whatever the language used, an optimized application consumes fewer resources than a poorly written application, and require fewer servers to manage a similar number of requests for a site with heavy traffic.

Similarly, I like to assume that an application written in a compiled language like C++ or. NET require fewer servers than if it were written in PHP, for example, for the same performance reasons. That may be why Facebook has designed a compiler for the application written in PHP.

Now, Facebook has recently opened the architecture of its data centers to the public to provoke thought for a reduction in their ecological footprint, but I'm not sure that the equipment is solely responsible if an optimized code needs less servers to address a number of requests.

That's why I wonder if quantitative studies have been conducted, with supporting figures to show how the optimization of the code could save resources and machinery thereby reducing the ecological footprint of data centers dedicated to single application like Facebook. If there are examples like "to do or not do" for languages, as well as tips to make the code more "green", I'd be very interrested.

Do you have any resources on this or thoughts to share?

share|improve this question
9  
Just be sure to take account of the energy consumed by the additional programmers needed to writing web apps in C++, especially the treatment and perks to keep those poor souls sane and in good mood. –  delnan Apr 9 '11 at 21:20
1  
When I read the title, I thought about suggesting you to change your syntax highlighter style options. –  user1827 Apr 9 '11 at 22:31
    
@delnan: I must be an odd beast then, since I quite like C++ but strongly abhor php... –  Matthieu M. Apr 10 '11 at 12:19
    
@Laurent: I think Facebook compiling its code has more to do with economy than ecology, they'll find a use for their servers. –  Matthieu M. Apr 10 '11 at 12:23
    
@Matthieu: Do you write web applications in C++? If so, you are indeed odd. –  delnan Apr 10 '11 at 13:22
show 3 more comments

4 Answers

up vote 6 down vote accepted

If you want to be "greener" I don't think code optimisation is the way to go. As Stephen says in his answer there are higher level issues to consider. In addition to his points I would add that you need to consider:

  1. Designing an architecture that scales well, so you only run the minimum numbber of servers you need to at any given time. When you don't need a server spin it down and when you need another spin a new one up.
  2. Running in the most efficient data centre you can find, one with all the modern features discused by the likes of James Hamilton. E.g. Air side economisation, high cpu running temps etc.

Both these are very hard to do on your own, but if you look at cloud computing you might find that the hard work has been done for you.

share|improve this answer
add comment

Optimization does not make code "greener", and trying to look at it through that lens (in my opinion) offers a poor view of the landscape.

Yes, it is true that an optimized process or program may lead to fewer resources consumed when measured on a per item basis. I say "may" because it depends for what one is optimizing. Although this might translate into $$$ savings, this does not necessarily translate into "green" savings. This is because of human behaviour.

As the code gets optimized and fewer resources are consumed, there becomes room available to run and do other things. And other things will be run and done--because the resources to do it are now available. (This is similar to "work expands to fill the allotted time" saying.) So, although the resources per process has decreased, the total amount of resources may temporarily drop, but will probably soon rise to higher levels because the "savings" will be "re-invested" to do even more.

share|improve this answer
    
Right on. You've basically described en.wikipedia.org/wiki/Jevons_paradox, which means that making your code "green" will actually result in it getting used even more, and burning up more watts of energy. –  whatsisname Apr 9 '11 at 23:05
1  
How much harder do 4 servers have to work to consume as much power as 5? –  JeffO Apr 9 '11 at 23:06
    
you saved me typing my own post. While energy saving is certainly a good thing, one must not think that one can "freeze" so to speak the current state of the world except that energy efficiency increases and thus reduce absolute energy consumption. Hence, the whole thing is an economic question and has nothing to do with "green" - whatever the public relations manager will tell you. –  Ingo Apr 10 '11 at 1:13
add comment

Similarly, I like to assume that an application written in a compiled language like C++ or. NET require fewer servers than if it were written in PHP, for example, for the same performance reasons.

Unfortunately, that doesn't follow. The efficiency of a service (especially a large-scale one) is going to depend more strongly on:

  • the system's macro architecture, particular in the way that scaling and load balancing are handled,
  • the architecture / design of the service components, and
  • the work performed done to tune the system.

It should also be noted that "fast" and "green" are not necessarily the same thing. For instance, a couple of the common techniques for making large-scale serviced faster are implementing a large in-memory result cache and replicating the database. But these approaches also mean that you are using more hardware, and (at least) relatively greater power consumption during periods of low user load.

share|improve this answer
1  
@Stephen C: I don't quite understand your remark I fear. We are talking about computing faster here, and though you are right about architectural decisions etc, using faster code will always consume less resources than using slower one, all other things being equal –  Matthieu M. Apr 10 '11 at 12:21
    
@Matthieu M: I think Stephen C's point is that the most common and beneficial optimizations often aren't faster code, or compiled languages, but faster access to information (caching/lookups, spreading the DB over multiple machines, etc.) which often includes the use of extra hardware -> thus more power consumption. –  Steve Evers Apr 10 '11 at 16:42
    
It is likely that I was traumatized during my first jobs: I wonder if like me, many have had to deal with managers who, to compensate for specific problems of performance, advanced the idea of ​​"replacing the hardware by a more powerful ", despite developers who advises to optimize code ... –  Larry Apr 10 '11 at 19:16
    
@Laurent - That can be a bad thing. On the other hand, there are situations where that is the best short-term solution; e.g. when the developers' time is needed on some other project. (But the manager shouldn't get into the habit of doing that, because it is likely to impact on the company's bottom line in the long run.) –  Stephen C Apr 11 '11 at 4:20
    
@Matthieu - that is true. But don't forget that developers and their workstations also have a carbon footprint. Choice of implementation technology and the amount of effort to put into optimization will affect the size of development teams, project timelines, your ability to deal with long term scaling issues, and so on. These decisions are not simple. Besides, my main thesis is that C++ vs PHP (for example) is often a lot less important for "greenness" than other factors. (And also that faster doesn't necessarily mean greener.) –  Stephen C Apr 11 '11 at 4:37
show 1 more comment

If you want "greener" in the narrowminded definition of "using less energy", write an application that instantly fries any computer it's installed on and make it go viral on facebook. The only way for any facebook kids (and there's hundreds of millions of them) to do anything after that is using pencil and paper, so they won't use any electricity whatsoever.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.