Apache Alternatives – The Era of Asynchronous I/O
We are living in the age where “less is more” is the mantra of the day. This is most true when it comes to technology, and there is a reason for this: less is simple, transparent, and more efficient. For decades the Apache Web Server has reigned as the most popular HTTP server, but now its rule has been challenged by a class of server software that follow this modern mantra. Meet Nginx and Lighttpd, the two Open Source Web Servers that are taking the web development landscape by storm.
Development on the Apache Web Server was commenced circa 1995 and it is based on a traditional model of processing. Apache is a process-based server, which means each simultaneous HTTP request requires a new thread to be created to handle that request. Under light loads this model works without any issues. If the server is under heavy load, however, far too much RAM (memory) is consumed, which gradually degrade performance (operations such as memory swapping make the situation worse). This potential issue can limit the scalability achievable under an Apache based setup.
The newer class of Web Server software follow what is referred to as the event-based or the asynchronous i/o model. In this model, the Web Server uses a single (or at most a few) threads to handle incoming requests. A new thread is not started for each request but rather asynchronous input/output facilities of the underlying Operating System (OS) coupled with event-based processing multiplexes all requests onto a limited number of worker threads. The result is the ability to scale magnitude of times better than Apache while consuming very little memory and CPU. This unique model of processing uses a smaller number of threads to achieve much better performance and throughput. There is a renaissance occurring in the software development world with regards to the Async I/O model-open source tools such as Netty, Thin (Ruby on Rails) and Node.js are all examples of this.
The most popular Web Server software using the newer model are Nginx and Lighttpd. While functionality-wise both of these tools offer the same level of features, Nginx is more popular and widely regarded as the server of choice for high traffic websites. A brief comparison of the two follows.
Nginx is essentially a HTTP reverse proxy and mail proxy server. Initially designed to operate as the front-end load balancer across a cluster of Web Servers, it has now been extended to serve HTTP content by itself. While it caters for both static and dynamic content, it especially excels at serving static content. There are a myriad of plugins available to extend the core functionality of Nginx (in fact the core itself is written as plugins too), ranging from integration with Memcache to scripting support using the Lua programming language. Overall it is a highly recommended software for high traffic websites that need to achieve scalability.
Lighttpd is similar to Nginx but unlike the latter it is a Web Server by design. This is evident from the configuration syntaxes of the two, with Lighttpd’s syntax easier to comprehend for newcomers (this is not to suggest that Nginx’s syntax is cryptic!). One advantage of Lighttpd over Nginx is its built-in support to spawn and manage FastCGI processes. This frees system administrators from the responsibility of starting and monitoring CGI processes themselves, which is a nice convenience. Also, previously much of the documentation of Nginx was in Russian. Although this issue has been mostly resolved, still Lighttpd does not suffer from this with its documentation available in English.
The choice of the most suitable Web Server depends upon the needs of the developer. Apache is the traditional choice with widespread support and availability on most hosting services. Nginx and Lighttpd are two upcoming servers with Nginx more popular, while Lighttpd offering some convenience utilities as well as better documentation.
Safari Books Online has the content you need
Take advantage of these Nginx and Lighttpd resources in Safari Books Online:
|Lighttpd is a secure, flexible, and most importantly, light web server designed and optimized for high performance environments. It is open-source and licensed under the revised BSD license. Lighttpd is your fast guide to getting started and getting inside the Lighttpd web server. Written from a developer’s perspective, this book helps you understand Lighttpd, and get it set up as securely and quickly as possible|
|Nginx HTTP Server serves as a detailed guide to setting up Nginx in different production situations: as standalone server, as reverse proxy, interacting with applications via FastCGI, and more. In addition, the complete directive reference will be your best friend at all stages of the configuration and maintenance processes.|
|Nginx is an open source high-performance web server, which has gained quite some popularity recently. Nginx 1 Web Server Implementation Cookbook covers the whole range of techniques that would prove useful for you in setting up a very effective web application with the Nginx web server. It has recipes for lesser-known applications of Nginx like a mail proxy server, streaming of video files, image resizing on the fly, and much more.|
About the authors
|Salman Ul Haq is a techpreneur, co-founder and CEO of TunaCode, Inc., a startup that delivers GPU-accelerated computing solutions to time-critical application domains. He holds a degree is Computer Systems Engineering. His current focus is on delivering the right solution for cloud security. He can be reached at email@example.com.|
|Shaneeb Kamran is a Computer Engineer from one of the leading universities of Pakistan. His programming journey started at the age of 12 and ever since he has dabbled himself in every new and shiny software technology he could get his hands on. He is currently involved in a startup that is working on cloud computing products.|