How LiteSpeed Web Server is Like a Coffee Shop
Let’s talk about the difference between event-driven and process-based web servers. These terms refer to two distinct ways of handling connections, and represent the most significant difference between LiteSpeed and Apache.
LiteSpeed Web Server is event-driven and Apache is process-based.
So, what does that mean, exactly, and why would you prefer one method over another?
The Coffee Shop Analogy
Imagine for a moment that your web server is a busy coffee shop, and the customers in the shop are the requests that the web server must handle. Which type of coffee shop handles its customers more efficiently?
The Process-Based Coffee Shop
In the process-based coffee shop, each employee serves one customer. The employee takes the order, pours the coffee, and collects the payment.
If there are three customers in the shop, there must be three employees to serve those customers, or else a line will form. This is a manageable scenario in a shop that serves few customers, or has a simple menu such as coffee and donuts.
But what happens when there are ten customers in the shop? And each of them wants a decaf soy peppermint mocha latte with no whip, and a heated croissant? The first three customers to place their orders probably get served pretty quickly, but the other seven? They will have a long wait. Many customers will not have that kind of patience, and will go elsewhere for their coffee.
In order to solve the efficiency problem in the process-based coffee shop, you need more employees. And in order to fit all of those extra employees behind the counter, you’ll need to expand your shop. You may need to move to a bigger location.
Such is the case with the process-based Apache web server. In order to deal with a large number of requests, you need more processes, and that means you’ll need to buy more hardware.
The Event-Driven Coffee Shop
Now imagine the same customer load and the same complicated orders, but in the event-driven coffee shop.
In the event-driven coffee shop, each employee serves multiple customers. One employee takes the orders and the payment, and delegates the order-filling tasks to other employees.
The employee at the register gets to all ten customers in a timely manner, because all he or she needs to do is take the order, relay instructions to the baristas on the backend, and take the payment. Meanwhile the backend baristas are pouring coffees, making lattes, and warming up croissants as needed.
This is an ideal solution that scales well, as one employee can do the work of many. You save money on retail space and wages, all while keeping your customers plied with fancy coffees and warm pastries in an efficient manner.
In the same way, LiteSpeed Web Server saves you money. With fewer processes doing the work of many, your server can handle a large number of requests quickly. And without the need for more hardware.
For static content like images, CSS, and HTML, the advantage of an event-driven model is clear. Instead of consuming the overhead required for a new process for each request, LiteSpeed employs its one process to handle the requests as they come in. This is faster and consumes significantly less CPU and memory than Apache.
The coffee-shop metaphor is particularly apt when it comes to dynamic content. Imagine web applications like PHP, and database processes like MySQL. This is how an event-driven model handles their requests:
|LiteSpeed Web Server||A Coffee Shop|
|LiteSpeed Web Server fields a request and forwards it to an external process||A shop employee takes an order and delegates it to a barista|
|LiteSpeed does not wait around for the dynamic responses, but instead continues to field more requests||The employee doesn’t wait for the barista to finish, but instead moves on to take the next order|
|When an external process response is ready, LiteSpeed Web Server gets a callback||When the barista finishes filling the order, the employee is notified|
|LiteSpeed sends the external response back to the requesting client||The employee serves the completed order to the customer|
Learn more about LiteSpeed Web Server’s event-driven architecture, and how it can accelerate your internet.