Take the 2-minute tour ×

I am writing now writing some evented code (In python using gevent) and I use the nginx as a web server and I feel both are great. I was told that there is a trade off with events but was unable to see it. Can someone please shed some light?


share|improve this question
Why shouldn't you? (You have provided no argument either for or against.) –  user166390 Nov 10 '10 at 2:21
I want to know what the trade-off is... –  James Nov 10 '10 at 2:26
cache coherency? code complexity? thread handling? –  J-16 SDiZ Nov 10 '10 at 2:33
add comment

2 Answers

up vote 1 down vote accepted

Biggest issue is that without threads, a block for one client will cause a block for all client. For example, if one client requests a resource (file on disk, paged-out memory, etc) that requires the OS to block the requesting process, then all clients will have to wait. A multithreaded server can block just the one client and continue to serve others.

That said, if the above scenario is unlikely (that is, all clients will request the same resources), then event-driven is the way to go.

share|improve this answer
What you didn't mention is that you can just access the resource you need in a non-blocking way. That way you don't block, can keep answering clients, and will get a callback from your event system when the resource is ready, all in a single thread. –  nosklo Nov 10 '10 at 3:55
second that -- the idea of event-based code is to use asynchronous interfaces for everything: no synchronous I/O. though with python even with gevent, twisted, etc it's fairly easy to accidentally use some blocking call if you're not careful. btw, this is the page everyone cites when talking about threads vs. events: kegel.com/c10k.html –  cce Nov 24 '10 at 6:52
@cce: if c10k is not enough we could try c500k: blog.urbanairship.com/blog/2010/09/29/… –  J.F. Sebastian Nov 27 '10 at 13:53
add comment

The only difficulty of evented programming is that you mustn't block, ever. This can be hard to achieve if you use some libraries that were designed with threads in mind. If you don't control these libraries, a fork() + message ipc is the way to go.

share|improve this answer
add comment

Your Answer


