Sequential code is very readable, but not efficient at scale. If you run a single thread (without the event based approach), each request must wait for preceding requests to finish entirely before running. That can be extremely bad for latency. On the other end, say you run a thread per socket - that's not effective as the memory usage for reserving thread stack space will limit your maximum connection count.
Event programming is useful in that it effectively performs cooperative multitasking without the overhead of thread stack space. Multiple requests can be running in parallel without fully blocking each other. Within a single thread they do serialize, but only by the length of your callbacks. If a request has to do I/O, it will queue up the operation and then yield so that other callbacks can run. Ultimately, it is reasonably fair scheduling-wise, eliminates time wasted on blocking I/O, and is more memory efficient than threading when handling large numbers of simultaneous requests/connections.
- epoll, which was added to the linux kernel ~2002, makes it possible to hang on to potentially hundreds of thousands of concurrent connections on one machine. Just can't do that with threads/processes.
- the desire for real time web applications, which have to hold large numbers of concurrent requests (e.g. friendfeed)
- a focus on lowering web application latency, which can necessitate making data requests in parallel
- advances in software (such as gevent, mentioned below) that reduce the complexity of writing async software
- increasing use of remote services / slow requests over the internet (if you're working in a threading/process model, you'll need a process open for each concurrent request, which can become prohibitive)
- web applications are simply serving more requests than they used to be, and probably have more to gain from being asynchronous
Without async I/O operating a large modern web application would be a lot harder. Lots of huge sites rely on memcache, for example, which would suck if it didn't use event-based IO.
But most apps don't fall into those categories, and I'm not getting any of that vibe from this. It seems that a lot of people sincerely believe that this stuff is "easier" or "better" just because it has the fancy new Spicy Event Sauce. And the truth isn't like that at all, and in fact these are truths that we've all known for years now...
It's one of those things that I've read about different methods here and there, but I've never come across one good source that compared and contrasted the various techniques.
The short answer may very well be no, since it somewhat depends on the programming language one chooses to use. As you'd likely handle I/O differently in something like Haskell, versus python. Anyway, I'm just curious Thanks.
Also, some observations on server design from Jeff Darcy (http://pl.atyp.us/content/tech/servers.html).
Simpler approaches are good enough sometimes, though. There are plenty of services that won't ever need to handle more than a couple simultaneous connections, and that way you don't need to bother with asynchronous IO.
I know what you mean about an event loop complicating error handling from callbacks, though. It feels sort of like writing in continuation-passing-style.
Once you need more than fork-per-connection can easily provide, you're not doing sequential code, you're doing events and/or threads. "Threads suck" is a common theme lately, but both can be pretty complex. (Event-based code obscures control flow, as you note; threaded code is subject to very subtle and hard-to-reproduce bugs.)
And it leads to some nasty state bugs, because conditions that are obvious in sequential code ("parse failed? Return ERROR_PARSE_FAIL to the top level request handler") become subtle (e.g.: parse failed, stash a failure result somewhere to be returned when the socket-is-closed callback happens, but oops! forget to actually close the socket so it lives as a zombie.)
Really, I'm curious. What exactly is it that made this thing the snake oil of the week?