Skip to main content

How does Facebook achieve good performance?


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?


Source: Tips4allCCNA FINAL EXAM

Comments

  1. There's no single reason, but a whole lot of reasons:


    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!
    Usage of HipHop, which converts PHP into C++ code (which is then compiled into much more efficient machine code than actual PHP).
    Facebook uses PHP and MySQL, but that's not the only thing they use. For example, they use Erlang 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.
    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)
    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...

    ReplyDelete
  2. Ultimate reason: http://memcached.org/

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

    ReplyDelete
  3. 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.

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

    ReplyDelete
  5. By


    Caching
    Having many servers
    Having many smart people working on making it fast.

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

    ReplyDelete
  7. 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.

    ReplyDelete
  8. 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).

    ReplyDelete
  9. 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...

    ReplyDelete

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.