serving large file using select, epoll or kqueue

Posted by xask on Stack Overflow See other posts from Stack Overflow or by xask
Published on 2010-03-29T17:40:10Z Indexed on 2010/03/29 17:43 UTC
Read the original article Hit count: 455

Filed under:
|
|
|

Nginx uses epoll, or other multiplexing techniques(select) for its handling multiple clients, i.e it does not spawn a new thread for every request unlike apache.

I tried to replicate the same in my own test program using select. I could accept connections from multiple client by creating a non-blocking socket and using select to decide which client to serve. My program would simply echo their data back to them .It works fine for small data transfers (some bytes per client)

The problem occurs when I need to send a large file over a connection to the client. Since i have only one thread to serve all client till the time I am finished reading the file and writing it over to the socket i cannot resume serving other client.

Is there a known solution to this problem, or is it best to create a thread for every such request ?

© Stack Overflow or respective owner

Related posts about epoll

Related posts about nginx