Facebook (PHP) is not very Kopenhagen
Recently, Facebook provided us some information on their server park. They use about 30000 servers, and not surprisingly, most of them are running the PHP code to generate pages full of social info for their users.
We do not yet know what the outcome (if any!) of Kopenhagen will be, but what do these 30000 servers mean in terms of CO2? And what would be the impact of a more sane language instead of PHP?
Since an average server consumes about 200 Watt [1], and with an average SI EER (Site Infrastructure Energy Efficiency Ratio) of 2 [1] this translates to around 400 Watt including cooling and other overhead. In the USA, an average of 560 grams CO2 is emitted per generated Killo Watt hour [2], and this brings us to a total CO2 emission by the Facebook server park of about 59 000 ton of CO2 per year.
To put this number in perspective: The entire CO2 emission of the USA is 5 752 289 000 ton of CO2 per year and 66 693 000 ton for Finland [3]. So, this server park emits an amount of CO2 that is about 1/1000 of the total of CO2 emissions by Finland. I would argue that is not quite negligible.
As they only say that "the bulk" is running PHP (edit: for those of you to lazy to read about the Facebook architecture [1], that is solely Apache/PHP, no database, no memcache, and to quote Jeff Rotschild of Facebook: “the need for those is a function of the runtime efficiency issues of PHP” [5]), let’s assume this to be 25 000 of the 30 000 (edit: and this would be in line with other bits of info that they run around 800 dedicated memcached servers and a few thousand database servers). If C++ would have been used instead of PHP, then 22 500 servers could be powered down (assuming a conservative ratio of 10 for the efficiency of C++ versus PHP code [4]), or a reduction of 49 000 ton.
Of course, it is a bit unfair to isolate Facebook here. Their servers are only a tiny fraction of computers deployed world-wide that are interpreting PHP code.
But I think it is fair to say that using PHP, especially for large deployments, is not very Kopenhagen.
For what it’s all worth.
[1] http://enterprise.amd.com/Downloads/svrpwrusecompletefinal.pdf
[2] http://www.stewartmarion.com/carbon-footprint/html/carbon-footprint-kilowatt-hour.html
[3] http://en.wikipedia.org/wiki/List_of_countries_by_carbon_dioxide_emissions
[4] http://shootout.alioth.debian.org/u32q/benchmark.php?test=all&lang=php&lang2=gpp&box=1
[5] http://video-jsoe.ucsd.edu/asx/JeffRothschildFacebook.asx
In a Web Development platform, it is the library that matters. Although I dont have personal experience with wt it sounds good enough. AND WHY THE HECK DOES ANYONE WANT TO PLAY WITH POINTERS AND C ARRAYS WHEN YOU HAVE GOOD CLASSES IN A LIBRARY. EITHER LEARN STUFF AND SPEAK OR DONT.
IF YOU WANT TO USE POINTERS IN AN OBJECT ORIENTED FRAMEWORK, THEN YOU REALLY NEED IT. I WOULD LIKE TO SEE HOW PHP PROGRAMMERS PLAY WITH POINTER WHEN THEY WANT IT. For designing the visuals of a webpage, as far as I have seen wt supports css_file loading.AND WHEN YOU SAY WT WAS MODELLED ON QT, I DONT THINK THEY MEAN IT. ALL IT MEANS IS THAT THEY HAVE GIVEN SIMILIAR NAMES TO CLASSES AS COMPARED TO QT SO AS TO EASILY BRIDGE THE QT PROGRAMMERS LIKE WWidget IN PLACE OF QWidget.
Also distribution of work and proper coordination along with management and the right set of tools are available for C++ considering its age.No one says, Dont learn HTML , PHP etc.. Understand how it works, and harness the maximum powerSo Learn and speak. Dont blabber.
Of course, FB has enough people/money to throw away everything and start from scratch: can you?-- Francesco
Why not having some beers on Saturday (6th feb) at
Sint-Goriksplein 23, 1000 Brussel, Belgium and discuss about how to build an european book of faces with wt etc (http://www.babelengine.org email: mobi at mobiphil.com)?
less CO2 means:
-less food for plants
-lack of global warming (someone please turn up the heat... it's global cooling...)
-lack of subjects for the enviro-nuts
...although it would all be balanced by the 65000 tons of CO2 that would be released in the process of producing and brewing coffee so that the programmers can re-code :)
Or am I underestimating the average PHP developer now ?
Only if you build the plants using antiquated designs. Modern designs are worlds different.
Also, even if there is caching, an interpreted language will ALWAYS be slower than C++ and even more so with C.
Don't try and pretend that C++/C is comparable to PHP in terms of speed, because it isn't.
And they are crash-proof, even on Linux.
Changing Facebook from PHP to C++ is quite like saving the planet by dumping your 2 year old sedan and buying a newly manufactured hybrid
But when you use PHP as the glue between lots of cached data, I doubt that efficiency is better with C... unless the real reason to be writing this is because you wan to work at facebook and still code C... well, man, life is no about what *you* want... no matter how much you love C... wanna help me patch a kernel next weekend?! *sigh*
In one job, i was hired to replace a perl implementation with a C++ implementation. The perl implementation could handle 2000 simultaneous connections. The C++ implementation could handle 40000.
Most of you critical of this article are just clicking your Ruby heals together and wishing for something that is just not true.
On top of that, most of what this type of site does is fetching data from a database, so a great deal of logic is actually in the SQL or equivalent, not in PHP.
So...no. And, making up ratios like the 10::1 ratio off the top of your head is the icing on the cake. If you don't know, then leave it out. Making stuff up just turns a ridiculous argument into a laughably stupid one.
<rant>
First off, I am not a professional web programmer/engineer. I am a professional console game/3d graphics engineer, where C++ tends to shine. I will apologize in advance if I am a bit naive about web technology and strategy, but that said I am not an idiot.
So I have recently began porting my blog from PHP and WordPress to C++. Why? Because I am much more productive in C++. I have not found anything (after much searching) that would lead me to believe that PHP is going to make me more productive (much less 10x more productive)than C++. I am finding the opposite to be true. I was able to get a source code syntax highlighting solution up and running VERY quickly using witty and some linux source c-based library. It probably took me more time to figure out how to do the same thing with the WordPress plugin manager.. Seems to me that this illusion of magic productivity in PHP just boils down to built in API's, memory management, ease of use for green developers, and just plain old developer's choice. All but one are manageable problems for C++.
Case in point:
What is it about scripted languages that prevent buffer overflows that one with C++ can't also achieve given the proper container ? Don't use C++ raw arrays or the C string API's, and instead use a C++ string API designed for the particular patterns/requirements necessary for web development and you shouldn't have any problems.. I will give you that using fatter, web developer friendly C++ API's may erode at C++'s performance advantage, but that to me just reinforces my point that its not the language but the API's commonly in use. So change the API's then..
There is nothing wrong with web development in C++, given that you have developers willing and able to use it. More than likely this is the core issue with C++ - It's just not popular with most web developers because it has this legacy of being difficult. I am just saying that I believe that C++ itself (the language, not the API's) is not as difficult as this legacy would leave you to believe, given the right choices of API's to go along with it.. Yeah C++ has some dirty, quirky issues when you get deep into its bowels, but I have also seen many, many ingenious, powerful things done with it that the language designers never thought of when they designed it.
</rant>
In conclusion, I am not stating that everyone should use C++ as THE web development platform. I think like anything else it should boil down to choice. I am going to choose C++ because it is what I know, and since I will be doing my own site with it I get to make the decision myself.
If I were doing web sites professionally AND I still had a choice, It would still be C++.
Once I get an opportunity to learn and use D (and perhaps get paid for it), I might switch to that. Until that day comes...
mtm
That said: most of the efficiency of web apps depends on DB design, not algorithmic code. Unfortunately much PHP/Perl/... Web-Development is not as DB-centric as it should be. But thats a question of construction, not one of material.
In that context RoR really has an advantage in developement philosophy, it is geared toward building an application around a database not vice versa. So: start out in Rails, when it gets down to real business, replace your glue with something scaleable - and thats not only number of processes but also eg potentially available human ressources: If you want to just rent coders when needed, head for java.
As for Facebook - Propably it is what it grew to. So I assume miserable efficiency. Not PHPs fault. Replace Facebook with any real-life thing here.
g., fil
I did not read any argument about money but simply about the hip and trendy CO2 emissions.
You should consider pulling this posting off the net. As you can tell you made a rather large arse out of your self making these baseless assumptions and statements.
If the wt c++ thing is any good you have just given it a very big black eye. As you can see for all the postings. You are point blank wrong on your conclusions.
I'm actually embarrassed for you right now.
I think a more realistic view is to assume that PHP would only account for 5% of the overhead. Thus, porting it to C++ would only speed up that 5% by 10, but in the end, it would cost more money and time (and cpu to compile and debug C++) to develop.
Facebook has a set of php scripts across tens of thousands of servers, possibly with different cpu setups, billions if not trillions of db rows with very large numbers of them being selected per second, and trillions of files to pick from.
So yeah obviously a 100% direct comparison of which you can draw accurate conclusions.
a) Facebook ain't just one language buddy
b) They already use C++ extensions where additional performance is needed
c) The reason they need so many servers isn't due to the programatic request handling layer
d) IO, data warehousing, database perhaps?
e) sigh.
PHP was, at least a couple of years ago, stricty plain C only (with all the band-aids not using C++ requires, including macros and passing around pseudo-this-pointers).
The calculation of cost (hard/efficitent language versus easy/inefficient) only holds as long as CO2 emissions don't cost you. Hopefully one day soon they will.
1) Facebook recently hired Andrei Alexandrescu.
2) C++ can be an excellent web development language, it's a matter of libraries and developer proficiency. Again, a domain-specific language is going to be "faster" to get started with, but a good architecture in any language is going to trump short-term "slowness of development" in the long run (at least from an engineering point of view).
(By the way, I am not associated with the Wt or PHP teams.)
I've also seen talks by the Facebook people who've stated that, although PHP computation is significant, it's only something like 1/3 of the process, so even if they make the PHP part infinitely fast, they're still only going to save 33%.
While I agree that their infrastructure is hacky and inefficient (in many respects), I doubt that it's nearly as bad as what you've estimated.
This is one of the most stupids post about computer I have ever read. Has the author ever written something like facebook (btw i did see http://www.suvi.org/adrbook/ but on the main subject) If facebook would be implemented in C++ it would probably 1) not exist 2) more expensive (means more trees killed) for production and maintenance 3) and probably be crashing several time because of some implementation faults.
Cheers suvi
More seriously, please DO READ the damn sources cited in the articles. Pay SPECIAL attention to everything the Facebook people themselves say.
And tell me what you want. Scratching 22500 of the straight PHP servers is going to save so much money that you can hire a considerable staff of high-skilled C++ people for it. Especially if you butcher some of the servers for spare parts, auction off the others, and can scratch most of your server-room cooling.
And if you catch C++ blocks properly they can fail relatively gracefully as well. It's not gonna kill the servers if done right.
If database I/O was the problem, they's be switching larger parts of their database layer for TMS RAMSAN-400s or something. They apparently don't have a problem there, though.
- rewriting Facebook in C++ takes time and resources (also CO2)
- writing a new app in C++ usually takes more resources than writing it in PHP (in PHP, computer does some stuff that C++ programmers have to do manually, like memory management)
- it's quite possible to write inefficient code in C++ as well
- the idea of "C++ is 10x as efficient as PHP" is derived from some synthetical benchmarks; relation to actual Facebook code is not really given
- it is not specified how busy the servers actually are (the server farm is probably designed to handle a certain "peak load", and probably idles during other times)
- usually, servers are not busy with continuous PHP "number
crunching" but perform other operations as well (waiting for incoming HTTP requests, processing HTTP requests in web servers, waiting for database responses)
There are many reasons why not to use a compiler language for web development. Even if FeFe's Blog uses C. He laughs about the idea himself.
Languages like Python, Ruby, Serversided JS and Perl, maybe even Lua and Pike do this job better.
Reasons:
-Compiling takes time
-Downtime due to pointer errors wastes energy
-this is a C++ advertising page
Downtime due to pointer errors, I think you've shown that you're not a C++ dev.
English Wiki says it is used by Opera Mini for this reason.
http://pike.ida.liu.se/
And as said above, there is Pike, which isn't only extremely fast (similar to lua), but also nice to write and easy to extend.
What can I say , I watch South Park and "Penn and Teller's Bullshit" too much :D
Regards,
Dushan
C++ is greener then PHP.
Yet another reason that PHP sucks LOL
Also there is a new project that combines APC with LLVM to generate cached native code :)
That said, I also don't believe all this server time is used for PHP. Most likely most of them are actually database servers.
Lazy loading
Cache priming
More efficient locking semantics for variable cache
Memcache client extension
Asynchrnous event-handling
It also seems to suggest that only the presentation layer is written in PHP although that does make up the lions share of their servers but you wouldn't get much of an improvement moving to C++ if any. I work on Java based servers for a large company and we moved from a C++ based system to a java on and it reduced our server load. Infact we were able to get rid of 40% of our servers.