Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why shouldn't I use async (evented) IO

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?

James

like image 781
James Avatar asked Nov 10 '10 02:11

James


2 Answers

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.

like image 57
Tobu Avatar answered Oct 13 '22 00:10

Tobu


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.

like image 42
chrisaycock Avatar answered Oct 12 '22 23:10

chrisaycock