Facebook (PHP) is not very Kopenhagen

  • Posted by koen
  • Thursday, December 17, 2009 @ 12:42

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.

Tags:
109 comments
  • Posted by anonymous
  • 12 years ago
Who The fuck said developing in C++ takes more time and I am really frustrated that no one has contradicted it.
When it comes to a desktop app you have c++ with QT library and development time is almost 75 % lower than in java and .net, performance is super fast yielding about 80% increase in performance (tested personally). .net is so slow (development time and performance) and java can be compared to the speed of a tortoise. In terms of portability you can run it on Linux , Mac , Windows , to mobiles running symbian , android (necessitas) , harmattan , Embedded Linux , Maemo, MeeGo , Windows CE, Mobile , Wayland , iPhone (experimental) , webOS (experimental) , BlackBerry , Amazon Kindle DX (experimental).
After all this the industry runs behind java and .net.

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 power
So Learn and speak. Dont blabber.
  • Posted by anonymous
  • 12 years ago
Also I have converted a reasonably founded vb programmer to a c++ with reasonably good qt programmer in a about a month.
  • Posted by anonymous
  • 12 years ago
Also you fuckers you dont have to consider pains displaying content in various web browsers. All in one solution. God I am going to use this wt instead of php. I am a Qt fan.
  • Posted by anonymous
  • 12 years ago
Also When you come to critical complexities which do not occur for a simple application be it web based or desktop based, but which occur in serous applications then you have to consider multiple inheritance which is absent in java as far as I know and which is a pain to work with in .net Interface. Also java will kill you with garbage collection.
Also From My perception (JUST MINE) I see web apps as normal desktop apps with users using it with remote screens ( for which all the network issues arises , and html , javascript , ajax plays its role)
  • Posted by anonymous
  • 12 years ago
It looks like that the discussion diverged a little bith from the original topic... so I am going to add some fuel to this fire :¬)
Spoiler: I am *both* a C++ and Perl developer (and I love both... but for different things).
I believe that, the coice between PHP/scripting and C++:
- For a company depends mainly on what you need to do, the time that you have, the competencies that you have and the code that you can reuse.
- For an individual on the personal taste.
I am going to comment only on the first one because, the fact that someone decides to write his own blog/tools/whatever during his spare time in language X could be driven just by personal reasons (for instance, learning X is a very good one).
Let's go back to my first point:
- What you need to do: if the application is really just I/O bound or it is doing almost no computation at all, as a thin layer between the DB and the UI, you can do that in a scripting language if this simplify you life (aka: less code to write, less code to test, less code to review...). If the application is computational intensive and there is not a specialized scripting/domain specific language available (e.g., Perl for RegExp), you should go for C++ (or whatever).
- The time that you have: scripting languages provide high-level abstraction and this usually means less code to be written, tested, etc. Using C++ could mean that you need to write a lot of code for things that can be trivially addressed in a scripting language.
- The competencies that you have: if in your company, everyone ignores how to program C++, just don't use it. Use whatever thing you know. You can invest time and money in learning new programming languages but it is unlikely that after a 3 days crash course in C++ you can call yourself a C++ programmer. If you need C++ in your project: hire C++ programmers if you do not have in your company.
- The code that you can reuse: in the majority of the cases, you do not write an application from scratch, you use you own framework, libraries, etc. How much did they cost to you? Can you afford the cost of throwing away everything to start doing everything in another language from scratch?
Of course, FB has enough people/money to throw away everything and start from scratch: can you?
-- Francesco
  • Posted by anonymous
  • 14 years ago
What about Google's 500k+ servers compared to FB's current 60k?
  • Posted by anonymous
  • 14 years ago
Good things
  • Posted by anonymous
  • 14 years ago
PLEASE READ THIS ONE:
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)?
  • Posted by anonymous
  • 14 years ago
I'm a C++ programmer and I fart alot, 1000:1 compared to an everage PHP programmer. This should be taken into account also.
  • Posted by anonymous
  • 14 years ago
It would definitely save CO2 from servers, but
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 :)

  • Posted by anonymous
  • 14 years ago
thanks for this nice article.
  • Posted by anonymous
  • 14 years ago
Why not use Assembly? Or develop a dedicated hardware architecture...
  • Posted by koen
  • 14 years ago
Since C++ is very similar to PHP (perhaps even a bit easier), and since most PHP developers are quite clever (as evident from the many highly informative comments on slashdot), it's fair to argue that most PHP developers could easily switch to C++. I'm not sure how long it would take a PHP developer to start doing ASIC design in VHDL or Verilog, examine netlists for timing problems, or doing PCB design.

Or am I underestimating the average PHP developer now ?
  • Posted by anonymous
  • 9 years ago
> Or am I underestimating the average PHP developer now ?
Yes. There are some great PHP developers with deep understanding of PHP both as language and as an architecture. But *average* PHP programmer is not very good. In PHP they can usually make less dangerous mistakes. Trust me, I worked with them.
  • Posted by anonymous
  • 14 years ago
Important to say that PHP allows you to easily write native extensions in C/C++, and Facebook does it a lot. Using PHP just to call the C/C++ routines.
  • Posted by anonymous
  • 14 years ago
Wikipedia is also written in PHP. What do you say about that?
  • Posted by koen
  • 14 years ago
Wikipedia is obviously a web site requiring much less computations (it is an online database, versus Facebook an interactive social application). And Wikipedia can benefit from successful caching (hit rate of 75%) of entire web pages, while Facebook does not do any caching of PHP generated content (as explained by Jeff Rothschild, reference [5] of the post), but rather uses a large array of memcaches for data. But even in the case of wikipedia, the majority of their servers is dedicated to PHP, as you can see from: http://meta.wikimedia.org/wiki/Wikimedia_servers.
  • Posted by anonymous
  • 14 years ago
Servers don't output CO2. Fossil fuel power plants do. So either go nuclear or use reusable energy. I'm not saying you shouldn't make things more efficient, but that doesn't solve anything in the long run when still burning coal, oil or gas. So get your priorities right.
  • Posted by anonymous
  • 14 years ago
And you don't think the mining-process or the enrichment-process puts out any CO2 ?!
  • Posted by anonymous
  • 14 years ago
nuclear is not clean energy. remember the huge construction and it manufacturing for nuclear. all these materials need to be mined, processed and transported.
  • Posted by sickletickle
  • 14 years ago
> nuclear is not clean energy.

Only if you build the plants using antiquated designs. Modern designs are worlds different.
  • Posted by anonymous
  • 14 years ago
Facepalm. If they used less servers, they'd use less power, and thus less requirement for consumption of resources and energy.

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.
  • Posted by anonymous
  • 14 years ago
a good example of a commonly used web application is called World of Warcraft. Instead of a PHP intrepreter, they use C++. The difference of course is that, instead of the website rendering text, it renders binary to it's browser -- in the form of a game client. The amount of database activity and computational algorithms is far more than facebook every will be. For PHP and Ruby zealots to say "PHP only accounts for 5% of the overhead" is baseless. It's not just "glue" -- its the core of the application. Nobody can ever, ever argue that PHP is comparable to C++ in terms of performance. The 10:1 factor is woefully innacurate; it's more like 1000:1. Go benchmark. And, using compiled SQL scripts instead of on-the-fly SQL is much faster, too. Microsoft SQL with its compiled procedures stands testament to it. C++ with compiled SQL using procedural parameters instead of PHP with ad lib scripts will be a LOT faster. PHP and ad lib scripts is possibly the slowest form of webserver. Its beaten even by VB.net and MSSQL.
  • Posted by anonymous
  • 14 years ago
actually it would be best for the work if facebook just shut down. it wouldnt even take one overpayed c++ developer to do it and would save the most co2 of all the scenarios discussed here. who need fb anyway?
  • Posted by anonymous
  • 14 years ago
How about overpaid PHP developers that can't spell?
  • Posted by anonymous
  • 14 years ago
Old-fashioned ANSI-C scripts (G-WAN Web server) leave PHP in the dust (up to 7,500 times faster).

And they are crash-proof, even on Linux.
  • Posted by sickletickle
  • 14 years ago
Crash-proof? hah :)
  • Posted by anonymous
  • 14 years ago
Why not comparing then the fficiency to plain C language?
  • Posted by anonymous
  • 14 years ago
Gotta take into account the gas emitted from programmers driving to and from work to write Facebook in C++ etc etc
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
  • Posted by anonymous
  • 14 years ago
You weaving a story out of random opinions, benchmarks and some facts is interesting. You C/C++ programmers wanting to use your beloved too for *everything* will have you become old sages that go read the holy scriptures of C coding on days of worship. If you were doing technical analysis, for instance, you would be much better using C libraries and of course you would have to use C libraries just because thinking about implementing a lot of CPU-intensive algorithms on PHP is laughable.

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*
  • Posted by rakotomandimby
  • 14 years ago
I quite agree being against PHP. This langage is particularily bad. About C++, I dont completely agree. I would suggest (just suggestion) trying OCaml over OCsigen. A complex web application such as Facebook should really consider this.
  • Posted by anonymous
  • 14 years ago
I think you just bunched the panties on the PHP community. Having built C++ web based servers, i can attest that they tend to smoke PHP if written correctly. When I talk to Grail developers and PHP developers about the numbers, they say that lower performance if offset by high developer productivity. I disagree. A QT based framework certainly increases the productivity of a C++ developer.

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.
  • Posted by anonymous
  • 14 years ago
This is just plain dumb. Facebook and any site of significant size uses APC or some such to cache compiled versions of each script. Additionally, almost every piece of HTML is cached, so PHP is rarely run at all, much less compiled on the fly.

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.
  • Posted by anonymous
  • 14 years ago
Yes, as mentioned, they are also running around 800 memcached servers and a few thousands (1800 was the last actual number) database servers. But literally, as the post says, the bulk of their servers runs PHP.
  • Posted by anonymous
  • 14 years ago
As he just said, they probably use APC.
  • Posted by anonymous
  • 14 years ago
And still they need that many webservers running PHP. As the Facebook director of Engineering just said (http://www.infoq.com/presentations/Facebook-Software-Stack): "For each single request, we need about 19ms for PHP just to load all the include files" and "PHP is not the fastest programming language, and this is mildly put". And yes, they use APC to cache intermediate code, which is quite different from machine code (it still needs to be interpreted).
  • Posted by anonymous
  • 14 years ago
Wow, this event has stirred up quite a controversy!

<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

  • Posted by anonymous
  • 14 years ago
I agree with this poster: modern C++ idioms and expertise make most of the traditional complaints go away. Libraries and good abstractions all but erase the benefits of "scripting languages" for Web applications once you accept that the initial start-up cost is dwarfed by the long-term costs-- things you'll incur no matter what language you use.
  • Posted by anonymous
  • 14 years ago
It's simple: PHP Programmers are cheap, C++-Pros are not.

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
  • Posted by anonymous
  • 14 years ago
Thanks for breaking it down like that... I had forgotten how hard up for cash Facebook is until you so bluntly reminded me.
  • Posted by anonymous
  • 14 years ago
My understanding is that they still have a negative cash flow...so realistically, spending tens of millions of dollars to refactor and port their entire code base over to C++ doesn't seem as high of a priority as paying off investors and generating revenue.
  • Posted by koen
  • 14 years ago
Actually, in reference [5] it is said that they are working on a system to use code source translation to translate their PHP to C++, with promising results, and one of the reasons he [Facebook] cites for this is that it is business-wise a good idea (30000 servers is quite a big investment!).
  • Posted by anonymous
  • 12 years ago
..............
  • Posted by anonymous
  • 14 years ago
Your analysis is completely wrong. The role PHP plays is not CPU bound, but I/O bound. Therefore, your estimated ratio of 10:1 is way off. If you include time waiting on I/O (network, database queries), the ratio is probably very close to 1:1. And PHP costs a lot less to develop than C++, so using PHP over C++ is a no-brainer here.
  • Posted by koen
  • 14 years ago
The number that Jeff Rothschild of Facebook is citing for performance ratio of PHP versus C++, is that PHP is being slower with a factor between 50 and 60. You are right, that is way off my estimated ratio of 10:1.
  • Posted by anonymous
  • 14 years ago
If they were I/O bound would they not rather increase the number of memcached (<1000) or database servers (a few thousands) instead of PHP servers? Or do you believe that modern OS'es really freeze when a process is waiting on I/O instead of task switching to another thread ?
I did not read any argument about money but simply about the hip and trendy CO2 emissions.
  • Posted by anonymous
  • 14 years ago
i dare say that, while they might save on some servers, i sincerely doubt, when the dust settles in this hypothetical situation, it is anywhere near the factor you suggest. there are a million speed bumps you hit along the way, so its easy enough to make such claims from the comfort of your armchair.
  • Posted by anonymous
  • 14 years ago
Mate,

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.
  • Posted by koen
  • 14 years ago
The information on PHP performance and Facebook architecture comes directly from Facebook. You might want to check the references before making clueless accusations.
  • Posted by anonymous
  • 14 years ago
This assumes that PHP is responsible for 100% of the overhead for running large scale applications like Facebook. Usually, the overhead in these kinds of applications is in the database or file i/o. The purpose of the 30000+ servers is usually to replicate and cache pages and data.

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.
  • Posted by anonymous
  • 14 years ago
You should read up on the Facebook architecture. The bulk of their servers are dedicated web servers (running PHP), and in addition they have around 800 memcached servers and a few thousand database servers. The purpose of the 25000+ servers is only to fetch data from the memcached layer, stitch it together and send it to the user.
  • Posted by anonymous
  • 14 years ago
Your reference is a shootout of a number of set tests on a single intel chip on a standalone server.

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.
  • Posted by koen
  • 14 years ago
My other references are Facebook discussing their experience with deploying PHP on tens of thousands of servers. And they are quoting a factor of 50 to 60 for the efficiency of PHP versus C++.
  • Posted by anonymous
  • 14 years ago
Wow, nice work falsifying data right there.
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.
  • Posted by anonymous
  • 14 years ago
Another PHP hit job.
  • Posted by anonymous
  • 14 years ago
For anyone who does not know this: C++ is just more efficient than PHP. End of story. Compared to C++, PHP eats up mass amounts of CPU cycles. C++ is simply more efficient. Yes, it is a much harder language to learn to use efficiently in a short amount of time. Yes, as a whole it is a harder language to code with overall, but it can operate at a level closer to hardware, with less over-head, thus being more efficient on the system as a whole, and being much faster computationally.
  • Posted by anonymous
  • 14 years ago
php is an interpreter built in c/c++, just as c++ is a language layer on top of assembler/machine code. thus, writing it in assembler is more efficient than c++ or php... if you know what you are doing, that is. i think the main argument against this is that efficiency takes more work and leads to a more complex system. the cost of doing that may very well outweigh the benefits.
  • Posted by anonymous
  • 14 years ago
assuming you are ignoring the environmental cost when calculating your benefits!
  • Posted by anonymous
  • 14 years ago
Two random notes:

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.
  • Posted by anonymous
  • 14 years ago
You do realise that the entire climate thing is a complete load of bollocks. C'mon are we scientists or not?
  • Posted by anonymous
  • 14 years ago
In your case: Not.
  • Posted by anonymous
  • 14 years ago
FTW!
  • Posted by anonymous
  • 14 years ago
A few more things to consider:

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).
  • Posted by anonymous
  • 14 years ago
Let's also consider that a large part of what they'd be doing in the C++ is repeating exactly what they are doing in PHP - how much of a -real- difference are you going to get in efficiency if you generate a web page in C++ vs in PHP? I suppose one could test this on a very basic case, by testing the speed of outputting a web page via C++ or the identical page via PHP echo ...
  • Posted by anonymous
  • 14 years ago
A /lot/. Just try it. :-)
(By the way, I am not associated with the Wt or PHP teams.)
  • Posted by anonymous
  • 14 years ago
I've heard that Facebook is working on a PHP to C++ translator to run well-optimized machine code in the end. No idea what the status is or if it's true.

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.
  • Posted by anonymous
  • 14 years ago
Reference [1] (facebook) claims that the bulk of the computers is dedicated to Apache/PHP though. What is the other 2/3 of the CPU time on these machine spent on then?
  • Posted by anonymous
  • 14 years ago
For one, not all machines are there for CPU use... ~1000 run memcache for purely serving cache requests. For two, there are a lot of database machines, and this is where a lot of the CPU use is required
  • Posted by anonymous
  • 14 years ago
The last reported number on their number of mysql servers is 1800. Since, they have heavily invested in offloading most of the traffic to memcached which they indeed have ~1000. That leaves us easily with 25000 doing only PHP ?
  • Posted by anonymous
  • 14 years ago
Hi

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
  • Posted by anonymous
  • 14 years ago
How did that s wander 20 letters to the left?

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.
  • Posted by anonymous
  • 14 years ago
I agree with many of the comments, that the I/O is more likely to be a bottleneck than the PHP. Also, the Facebook blog even states that they use C++ for parts of the backend where performance is required.
  • Posted by anonymous
  • 14 years ago
If I/O was a problem, then the percentage of pure PHP servers in their server centers wouldn't be as big. And if just external connection handling is the problem, C++ will again be faster.

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.
  • Posted by anonymous
  • 14 years ago
You do realize the benchmark you used to get 10:1 uses tests that have almost nothing at all to do with presenting a web page, right? Most are pure number crunching. Unless Facebook calculates the digits of Pi everytime it renders a page, that ratio is just completely arbitrary. The biggest bottleneck is most likely database queries, which really has nothing to do with the language you are using.
  • Posted by anonymous
  • 14 years ago
You are hopefully aware that the 10:1 estimate is rather pessimistic? Read the darn linked sources. Facebook -themselves- cite a higher number. =/
  • Posted by anonymous
  • 14 years ago
Surely, while waiting for I/O (such as doing a database query response), the CPU is allowed to process another request? If they need that many machines, it's not to keep around CPUs that are simply waiting for I/O ?
  • Posted by anonymous
  • 14 years ago
In case somebody actually takes this serious, here's some stuff to factor in:
- 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)
  • Posted by anonymous
  • 14 years ago
"PHP is not very efficient" was taken from the referenced blog post itself. I suggest you argue with them on the inefficiency of PHP ? Why do you think their servers are not busy actually processing ? Do you believe they do not run a multi-tasking OS or have somehow disabled multi-tasking in their Linux kernels ?
  • Posted by anonymous
  • 14 years ago
You're absolutely right.
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


  • Posted by anonymous
  • 14 years ago
lol. Compiling takes time, therefore we should use scripting languages. Compiling takes an insignificant fraction of the time facebook spends processing requests.

Downtime due to pointer errors, I think you've shown that you're not a C++ dev.
  • Posted by anonymous
  • 14 years ago
Last time I read about such a piece of shit is ... wait, I've never read such a piece of shit. Btw, posting and reading this shit wastes CO2, too. Better you shut your server off.
  • Posted by anonymous
  • 14 years ago
If you're answering the autor of this site: Maybe, at least C++ ist to static, especially if aren't allowed to put executables on your server.
  • Posted by anonymous
  • 14 years ago
WhatisthisIdon'teven
  • Posted by anonymous
  • 14 years ago
C++ sucks referring to fast program changes. Try Pike instead, a very fast (also compared to Python and Ruby) interpreter language.

English Wiki says it is used by Opera Mini for this reason.

http://pike.ida.liu.se/
  • Posted by anonymous
  • 14 years ago
What you forget in your calculation: Programming C++ takes longer than programming PHP, which is why you have to add all the CO2 produced by the additional programmers :P
  • Posted by anonymous
  • 14 years ago
Yeah, but on the other hand you have to pay more admins and security hole fixers using php.
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.
  • Posted by anonymous
  • 14 years ago
There is problem with your blog. When I am reading some posts at full, I can't go back to Blog main page. Please kindly fix that and plz tell us how to do so when we use Wt to do own blogs. Thanks.
  • Posted by anonymous
  • 14 years ago
ASFAIK, this has been fixed in the lastest version of Wt, but hasn't been deployed yet here.
  • Posted by anonymous
  • 14 years ago
Ehhhmmm.. I do not believe that global warming is caused by men :P

What can I say , I watch South Park and "Penn and Teller's Bullshit" too much :D

Regards,
Dushan
  • Posted by anonymous
  • 14 years ago
correct, it is caused by women
  • Posted by anonymous
  • 14 years ago
That's pretty funny.
C++ is greener then PHP.
Yet another reason that PHP sucks LOL
  • Posted by anonymous
  • 14 years ago
and assembler is greener then c++, debug that!
  • Posted by anonymous
  • 14 years ago
and hardcoded hardware programs are greener, build that. :P
  • Posted by anonymous
  • 14 years ago
and genetically manipulated cells are even greener. evolute that!!
  • Posted by anonymous
  • 14 years ago
To eliminate carbon based life is even greener. Apocalypse that.
  • Posted by anonymous
  • 14 years ago
rofl. This just made my day! Thanks!
  • Posted by anonymous
  • 14 years ago
Best.Post.
  • Posted by anonymous
  • 14 years ago
Lets start with just the humans OK?
  • Posted by anonymous
  • 14 years ago
Facebook uses some opcode caching like Zend Accelerator or APC for sure, which makes PHP a lot faster.

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.
  • Posted by anonymous
  • 14 years ago
You think they are lying about what their servers are doing ? When they say that the bulk are web servers fetching data from an array of memcached servers (~1000) that off-load another few thousand of mysql servers, somehow you read inbetween the lines that actually most of these servers are actually database servers ?
  • Posted by anonymous
  • 14 years ago
Keep the amount of concurrent users and persistent HTTP connections in mind - isn't it possible that a vast amount of front-ends are going to be required no matter which language is used for middle-tier code?
  • Posted by anonymous
  • 14 years ago
No, unless you are willing to ignore the existence of multi-tasking and techniques such as asynchronous I/O. But then you need to run MS DOS on your web servers?
  • Posted by anonymous
  • 14 years ago
Base conclusions on real data, not guesses.
  • Posted by anonymous
  • 14 years ago
I agree, but this entire post is based on supposition... we just don't know what programs the server farms are running at any time.
  • Posted by anonymous
  • 14 years ago
Certainly not if we are ignoring whatever information they share about it.
  • Posted by anonymous
  • 14 years ago
This blog post was based on guesses too... I've seen idiots implement shit algorithms in c++ that ran faster in my php scripts (or perl or python or java). It's about the quality of your engineers, not the language you use... except for C# / .net --- at least they're not running that :)
  • Posted by anonymous
  • 14 years ago
It does list five ways that facebook optimize their PHP in the linked blog post:

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.
  • Posted by anonymous
  • 14 years ago
I'm curious here. What about the memory use after changing to Java? Did it go up? I assume you didn't have memory problems in the first place.
  • Posted by anonymous
  • 14 years ago
Yes, and I rewrote a large java app in C++ and memory usage dropped dramatically and performance increased similarly. The article is really about how you can write apps with easy-to-use but inefficient languages and improve them by making them efficient, thus helping save yourself money and CO2. Of course you'll need better (not cheaper) coders, but that should be your goal in the first place.

Contact us for more information
or a personalised quotation