views:

2217

answers:

16

Almost everyone has a Facebook account, even people who are not familiar with the Internet. With millions people actively using Facebook, updating their status, replying to messages, uploading photos and so on, how is Facebook's page still loading very fast?

I was told that Facebook was built using only PHP and MySQL, so how can Facebook's performance be so good?

+34  A: 
  1. Facebook uses HipHop, which converts PHP into C++ code (which is then compiled into much more efficient machine code than actual PHP).

  2. Facebook has data distributed across many, many servers. They actually use Hadoop clusters for most of their data storage. In fact I doubt Facebook is using MySQL in any significant way at this point.

NullUserException
My impression from reading that article on Hadoop is that they're using it for archival storage, statistics gathering, data mining, etc., not so much for real-time serving of live content.
David Gelhar
Related : http://www.ustream.tv/recorded/4409735 (It's a talk about HipHop done by the developper of Facebook).
HoLyVieR
Facebook *is* still the largest single user of `MySQL`.
Josh Smith
I have yet to encounter a *good* hiphop performance on Facebook. http://www.rapbasement.com/kanye-west/072910-kanye-west-talks-about-performing-at-facebook-headquarters-watch-and-listen-here-click-now.html
littlegreen
Wow I didn't quite expect this response. I'll update this answer with more details when I get a chance.
NullUserException
All that and it's still slow.
Ed Swangren
NullUserException: I just asked an employee there, and he said that pretty much all their data is stored in MySQL and Hadoop is used for batch processing.
Gabe
I'm skeptical that HipHop would be the #1 reason for their good performance. Most requests on Facebook probably end up being I/O bound, so I doubt HipHop does much to lower the latency. Your #2 is probably more important. Their system architecture and how work gets distributed strikes me as more important than any one component.
Doug
+1  A: 

They have a compiled version of php, in fact. My guess would have to be: insane amounts of crazy hardware, brutally efficient code, and a database structure optimized with caching, denormalization, clustering...

Joachim VR
I don't think they have insane amounts of crazy hardware. Insane amounts of hardware, yes. But like Google, they are relatively cheap computers, but they leverage the power of cloud computing.
NullUserException
@NullUserException Crazy hardware probably wouldn't be a good idea anyway :)
Richard
+3  A: 

Facebook was not only using MySql - it started out using Cassandra, and is migrating over to HBase. Applications like FB need a highly scalable Database.

SB
Cassandra was just an experiment they tried that didn't work out. They didn't start out with it, and they barely ever used it.
Gabe
Really? Wikipedia seems to indicate that they had a 200 node cluster deployed and used it for inbox searches.
SB
SB: Yes, that is exactly correct. They have tens of thousands of MySQL servers running virtually everything except a 200-node cluster used for inbox searches, which to me qualifies as "barely ever used".
Gabe
Yea good point. Didn't realize they went crazy with sharding MySQL.
SB
+20  A: 

Ultimate reason: http://memcached.org/

They claim 98% of everything you see on Facebook is from their massive memcache server cluster.

Xeoncross
Do you have sources?
NullUserException
there is no ultimate reason...
galambalazs
"They claim"... :)
BoltClock
They have 12 clients/users listed on their homepage, non of which is facebook.
John Isaacks
Interestingly, according to their [Post on Septembers 2.5 hour outage](http://www.facebook.com/Engineering#!/notes/facebook-engineering/more-details-on-todays-outage/431441338919) their cache (memcached?) cluster failed.
Stefan Lasiewski
@John : memcached.org may not mention it, but Facebook says that "[Memcached was not originally developed at Facebook, but we have become the largest user of the technology](http://developers.facebook.com/opensource/)".
Stefan Lasiewski
+7  A: 

Check out http://facebook.com/techtalks.

They have some great videos describing many of their various optimizations. For instance, there's a talk on memcached (which helps speed up common key gets) and their front-end optimizations (doing lazy loading of Javascript, etc).

The amazing part is how large everything is at facebook. With millions of users and thousands of servers, even a seemingly small optimization can end up saving them millions of dollars or gigabytes of memory.

Josh Clemm
+1  A: 

Because they have a lot of money. Hiring smart developers and buying tons of servers every week is quite costly.

bobdiaes
+3  A: 

This article talks about the inner workings of Facebook: http://royal.pingdom.com/2010/06/18/the-software-behind-facebook/

mellowsoon
A: 

Maybe a small part of the solution overall, but they also optimize for fast client-side rendering. They contracted CSS expert Nicole Sullivan to do some optimization based on her OOCSS techniques.

Andrew Vit
+1  A: 

Watch this presentation of Aditya Agarwal, Director of Engineering at Facebook, this presentation talks about Facebook’s architecture and its major components (LAMP (PHP, MySQL), Memcache, Thrift, Scribe).

Amirouche Douda
A: 

XHP is a PHP extension which augments the syntax of the language such that XML document fragments become valid PHP expressions. - GIT checkout and Wiki

Phill Pafford
How does this affect site serving performance?
nikic
Here is an overview of performance http://toys.lerdorf.com/archives/54-A-quick-look-at-XHP.html
Phill Pafford
+1  A: 

It's worth looking into how Facebook selectively loads front end JS so that there is very little latency in the responsiveness of the UI.

jerome
+4  A: 

More info at http://highscalability.com/blog/category/facebook

aalvaradoh
+1 That article paints a good picture of the inherent system complexities and importantly (in context of the question) what the system consists of to faciliate speed.
John K
+2  A: 

By

  • Caching
  • Having many servers
  • Having many smart people working on making it fast.
nos
A: 

Last I heard, they had about 7000 + servers. It also helps that Zuckerberg and his employees are geniuses.

broke
A: 

There is a lot of information about their technology in the Facebook Group Facebook Engineering, including discussions of their MySQL cluster, XHP, memcached, etc.

It comes down to having enough money to hire smart staff who write efficient programs running on many many computers.

Stefan Lasiewski
A: 

read about Load Balancing... it gives you some ideas.

takpar