Socket programming stop and wait

0 this week, is more than just a gem, it is a new paradigm for many Ruby programmers and is not always easy to just drop into your existing stack. As the socket programming stop and wait suggests, it gives you event-based programming. Apache vs Nginx For the sake of example, I’m going to side-step and look at a switch that you may have already made, from Apache to Nginx.

Did not find what they wanted? Try here

With Apache, if a new client connects, you need a new process, or at least use of process that another client is not using. If the client is slow in sending its HTTP request, then your process will be consumed until that client has finished its role in the request-response cycle. Therefore, with Apache, your throughput is governed by the number of Apache processes you can run simultaneously divided by the average time it takes to process requests. The number of Apache processes you can run simultaneously is dependant on the RAM you have on your machine and RAM is expensive. When Nginx receives a new client connect it simply creates a new socket and not much more. Therefore, the same process can potentially handle tens of thousands requests. Out-Of-The-Box Rails Out of the box, Rails is much like Apache.

It is a single process and any work you do, such as communicating with the client over HTTP or talking to database, is done in a blocking manner. O responses and nothing else can get in during that time. Things like client connections are handled in an event-based manner. Within an event-based application, everything must be non-blocking to get the real benefit of event-based programming. The event-loop is running in a single thread within a single process. Therefore, the first time you do something that is blocking, it causes the whole event loop to stop and wait for you. The Perfect Event Loop The perfect event-loop is one which passes every blocking request to the operating system, via the event library.