Zbr's days.
July
Sun Mon Tue Wed Thu Fri Sat
    1
   
2008
Months
Jul
Oct Nov Dec

About TODO Blog RSS Old blog Projects Gallery Notes

Tue, 01 Jul 2008

Why is blocking sending considered harmful?

I frequently hear that whatever server you implement, it has to be non-blocking, since in case of parallel sending it allows to send multiple requests to fast servers, while not-sending data to slow server, since non-blocking socket will return EAGAIN.

This is only half-right solution: when we have to put given data to all servers, and can not free it until all servers replied with acknowledge, non-blocking mode can bring more damage than gain.

Mainly because it allows to eat all the memory for requests, which are still in the queue to be sent to slow server, and which was already sent to fast ones. In this case higher-level application (consider simple application which generates some data and writes it into the file in distributed filesystem, which writes file to several servers) will never block since transfer to fast servers completes quickly, and will provide more and more data, which will consume all RAM.

It is possible to deadlock system in this case, since to send some data to remote server we always have to allocate at least some data to put network headers into. With non-blocking solution we will consume all memory and kick itself into the coma.

/devel/networking :: Link / Comments (2)

Jon Smirl wrote at 2008-07-01 18:34:

Compare the performance of web servers that use blocking sends and lots of threads, with ones using a single thread and poll. The single threaded ones win by a wide margin.

You need to implement some flow control smarts to avoid eating all of memory. A lot of web servers handle dial up modems by putting a proxy server in the chain. The main server quickly sends the data to the proxy server, then the proxy server slowly spools it out to the dial up clients. That frees the resources on your main server.

Zbr wrote at 2008-07-01 18:42:

It is not about web server, since it can not eat all the memory, since it lives in userspace, which is ratelimited (amount of ram, opened files, stack and so on). Filesystem contrary is not limited and can hold pages for arbitrary long period of time.

Please solve this captcha to be allowed to post (need to reload in a minute): 47 * 72

Name:
URL (optional):
Captcha:
Comments: