Friday, October 17th, 2008
Richard Jones has started an interesting series to talk about scaling comet web applications using MochiWeb:
In this series I will detail what I found out empirically about how mochiweb performs with lots of open connections, and show how to build a comet application using mochiweb, where each mochiweb connection is registered with a router which dispatches messages to various users. We end up with a working application that can cope with a million concurrent connections, and crucially, knowing how much RAM we need to make it work.
In part one:
- Build a basic comet mochiweb app that sends clients a message every 10 seconds.
- Tune the Linux kernel to handle lots of TCP connections
- Build a flood-testing tool to open lots of connections (ye olde C10k test)
- Examine how much memory this requires per connection.
Future posts in this series will cover how to build a real message routing system, additional tricks to reduce memory usage, and more testing with 100k and 1m concurrent connections.
Richard walks through the code and setup, step by step and measures the scalable performance, leading too:
That was a reasonable first attempt. 45KB per-connection seems a bit high – I could probably cook something up in C using libevent that could do this with closer to 4.5KB per connection (just a guess, if anyone has experience please leave a comment). If you factor in the amount of code and time it took to do this in Erlang compared with C, I think the increased memory usage is more excusable.
In future posts I’ll cover building a message router (so we can uncomment lines 25 and 41-43 in mochiconntest_web.erl) and talk about some ways to reduce the overall memory usage. I’ll also share the results of testing with 100k and 1M connections.
Posted by Dion Almaer at 6:26 am