Tag Archives: performance

Why is Facebook so fast?

It has been a time since my last post.

Truthfully, even now, I have been too busy to make a come-back. But I think a little writing will help this blog doesn’t seems as an abandoned castle.

Well, for sometime, I come across this question on StackOverflow:

Why Facebook performance is so good?

500 millions user, split for america, europe, asia. It means there’s more than a millionpeople viewing pictures, chatting with friends or update status at a time. How can they make it?

The main language of Facebook is PHP & MySQL, which doesn’t have reputation to scale well. AFAIK, people tends to use compiled language(like Java, .NET) for big enterprise application. Those languages enforces good practice like refactoring habit, good architecture,… while PHP does not. Moreover, scripting language can not run faster than compiled one, right?

There’s no single reason, but a whole lot of reasons:

  1. Heavy usage of caching (APC and memcached), which drastically cuts processing time. Slide 12 compares load time with APC (~130 ms) versus without it – 4050 ms. That’s 30x faster!
  2. Usage of HipHop, which converts PHP into C++ code (which is then compiled into much more efficient machine code than actual PHP).
  3. Facebook uses PHP and MySQL, but that’s not the only thing they use. For example, they useErlang for their chat, Hadoop clusters for some of their storage. If you go visit their careers page, you’ll see they are hiring developers with experience in C++, Java, Python, and others.
  4. Facebook has data distributed across many, many servers. In June 2010, FB had 60,000 servers. (think that’s too much? Google had half a million… 5 years ago)
  5. Facebook sends as little traffic as possible: they use static CDNs to deliver static content. Gzip to compress data. Cookies, Javascript, HTML – everything is cut back to reduce the number of bytes sent over the network. They use a technology they call “BigPipe”, which sends partial content rather than the whole page.

to mention a few…