Facebook Chat usage has increased steadily since its launch last year, and this week we reached 1 billion messages sent per day. As a team we’ve been looking forward to this milestone; we track lots of statistics in the course of maintaining and improving Chat, but this number measures Chat’s progress toward its ultimate goal: increasing communication between our users. We’ve invested a lot in making Chat stable and scalable in the past, and we continue making improvements even now. We’ve increased the capacity of our load balancers so we can accept more concurrent users, and we’re investigating ways to make the backend and frontend more robust against failures. We’ve also made an enhancement to the channel servers that reduces their memory load. We noticed that each HTTP request used more memory than strictly necessary. The data structure that represents each HTTP request contains a socket, the version and method (GET, POST, etc.), the path, and most importantly the request headers. We need the headers to decide how to service the request, but we don’t need them to construct the response. The HTTP process’s heap, complete with the user’s cookies and other headers, is compacted and stored while it waits for a new message. However Erlang can’t detect that we won’t use the headers on wake, so we save them all. We changed the code to discard the headers explicitly and saved a lot of memory. We can use that newly-freed memory to serve more users per machine.
As an engineer it’s exciting to launch a product used by so many people, but it’s even more rewarding to watch it grow week over week and month after month. There are still improvements to make and features to launch, so we still have plenty of work to do. Here’s to a year of Chat even better than the first!