开发者

How Blocking IO Affects A Multithreaded Application/Service In Linux

开发者 https://www.devze.com 2023-04-07 05:13 出处:网络
Am exploring with several concepts for a web crawler in C on Linux. To decide if i\'ll use blocking IO, multiplexed OI, AIO, a certain combination, etc., I esp need to know (I probably should discover

Am exploring with several concepts for a web crawler in C on Linux. To decide if i'll use blocking IO, multiplexed OI, AIO, a certain combination, etc., I esp need to know (I probably should discover it for myself practically via some test code, but for expediency I prefer to know from others) when a call to IO in blocking mode is made, is it the particular th开发者_JAVA百科read (assuming a multithreaded app/svc) or the whole process itself that is blocked? Even more specifically, in a multitheaded (POSIX) app/service can a thread dedicated to remote read/writes block the entire process? If so, how can I unblock such a thread without terminating the entire process?

NB: Whether or not I should use blocking/nonblocking is not really the question here.

Kindly


Blocking calls block only the thread that made them, not the entire process.

Whether to use blocking I/O (with one socket per thread) or non-blocking I/O (with each thread managing multiple sockets) is something you are going to have to benchmark. But as a rule of thumb...

Linux handles multiple threads reasonably efficiently. So if you are only handling a few dozen sockets, using one thread for each is easy to code and should perform well. If you are handling hundreds of sockets, it is a closer call. And for thousands of sockets, you are almost certainly better off using one thread (or process) to manage large groups.

In the latter case, for optimal performance you probably want to use epoll, even though it is Linux-specific.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号