Friday, October 16, 2009

Systems programming in "scripting" languages

Whenever someone thinks about building databases, web servers or other high performance pieces of server software the natural assumption is that it has to be written in C or C++ (or maybe java). The argument is usually something along the lines of only C or C++ provides the necessary performance, scalability etc. I think this is fundamentally missing the point of what makes high performance and highly scalable server software.

Most server software that is performance bound is limited by I/O, poor multithreading concurrency, or some finite kernel resource (threads, open files etc). None of these have much to do with the implementation language. Efficient I/O can be initiated just as easily from Python as from C++. Libevent and other ways to demultiplex concurrent I/O can be done just as well by Python as C++.

Now consider the common problems with server software -- security, maintainability and porting. Exactly the three things that higher level languages like Python can make a lot easier.

Now, there's one potential down side. Most of these alternative languages are garbage collected and potentially can expose your application to arbitrary and long pauses while the garbage collector runs. In practice, this is less of a problem than you might think. Concurrent garbage collectors work well. Python's reference counting + mark&sweep strategy results in very little volatility in latency in practice.

If I were building a server application designed to handle billions of requests across a large farm of servers I'd definitely be thinking of building it in Python instead of C/C++.
blog comments powered by Disqus