Bernd's Memory Leaks

(How to scale) In the multi-processor world

posted: 2008-06-15 22:02
filed under: talk | Joe Armstrong | Erlang | Concurrent Programming | infoq

At the time when I got into application development it was common that GUIs became unresponsive when applications (3D renderers for example) where busy calculating, or that you could not go on scrolling in a text while it was being saved. Multi-threading was the cure to this and threads were used to build multi-tasking applications. Having Threads as a feature in Java was a big plus for moving to it from C++. Off-the-shelve PCs had no more than one processor back then. Multi-core was unknown. It was sufficient to have one thread for the GUI, one for I/O and one or two for computations and you easily had maxed out your machine. Later came thread pools, for multi-plexing database calls, or scaling your web server to more clients.

But eventually, one thread per socket connection was no longer scaling well for a web server, either. There were too many concurrent threads to be handled efficiently by the OS. Every context switch between two threads has an overhead. That's when event-driven frameworks like MINA came to rescue. A thread was only assigned to a connection when there is data to process.

Today, multicore multi-CPU machines are very common. So we no longer need to optimize for our one-and-only processor. Instead, we need to optimize for threads running truely in parallel on the same machine. New sorts of bottlenecks start to appear: One of them is sharing variables between threads. Access to memory happens in a processor's local memory, so state has to be copied around between main memory and CPU-local caches (I am simplifying here).

There is a fascinating presentation by Joe Armstrong about how to scale in the multi-processor world over at InfoQ. He also wrote a book about it (amazon.de link). It's about Erlang, a computer language optimized for running on lots of processors and lots of machines. It is many years old and used in production, but only became better known to a wider public in the last years. And if you don't have enough of it then already, listen to the Erlang interview with Joe Armstrong by se-radio's Markus Voelter.

© 2002-2010 bernd fondermann brainlounge, contact/legal notice