Tuesday, January 25, 2011

Day 5 - nginx is asynchronous but it also manages memory. Introducing buffers and chains

Done with the first chapters. Of course, when I say "done", it means I did a first translation. I still have to review it. And, I don't know why but I have the feeling that when I'm going to come back to this I will be like "I wasn't understanding a word of what I was saying" and will want only one thing: redo it. I guess that's why compilers always have multiple pass: one to get it wrong but get an idea and one to get it right... ;)

These first chapters were general principles about nginx: it's asynchronous (that's why it's so fast and cheap on CPU) and if you code a module, just make sure it is as well if you don't want to break everything. Now, that was not a surprise: after all, nginx home page claims it's one of the few web servers to solve the C10K problem. But it looks like this thing goes much further than that. Being asynchronous is just the tip of the iceberg : it also has its own memory management mechanisms. If you were planning to do malloc/free, just think again. Surprising at first glance but when you come to think of it and you have seen what happens to a good old Apache when you start getting more than 1500 requests per seconds you figure out this is definitely something to be careful with. For those of you who haven't seen Apache 1500 rps (actual number really depends on memory available and configuration), I'll save you the burden of trying: your full system starts swapping and all you can do is start praying that people don't start hitting the infamous F5 key (aka the "it doesn't work but if I keep hitting on it harder and harder may be it's going to work" key).

Anyway, next chapters are about buffers and chains. I'll probably have a look at the C10K article before going there. This buffers/chains thing is the core of the nginx architecture and I know it's going to be difficult to get through it. So, I feel like I need as much preparation as I can get. And the C10K paper is a good start.

No comments:

Post a Comment