Does Nginx block on file IO?

Piotr Sikora piotr.sikora at frickle.com
Mon May 2 09:22:52 MSD 2011


Hi,

> I was always under the impression that Nginx is non-blocking for file
> IO. Then I was told it wasn't.

That depends on your configuration on on capabilities of your operating 
system. Asynchronous file I/O is available on recent versions of Linux, 
Solaris, DragonFly, FreeBSD, NetBSD, MacOSX.

> I'm considering using Nginx to serve static images. Pretty much every
> connection will result in a file IO.

No, it won't. Recently served files should be in your OS's buffer cache.

> If Nginx blocks for file IO, then
> using Nginx here wouldn't be any better than using Apache, right? Every
> connection will lead to a file IO which blocks the entire Nginx process.
> So to serve 500 concurrent connections I'll need 500 Nginx processes.

If that would be the case (buffer cache hit rate would be very low) and you 
would be using magnetic disks, then yes, you'd be better off with a web 
server than uses per-client lightweight processes or threads.

Best regards,
Piotr Sikora < piotr.sikora at frickle.com >




More information about the nginx mailing list