3

I am using the poll mechanism to manage upto 100 connections. Is there any standard practice for what the time out value for the poll() call should be or how to determine it.

My case details -

I have one dispatcher thread listening on all the connections. Once a connection becomes read ready, I disable it for polling and forward the connfd to a thread pool processing reads. The dispatcher thread goes back to polling.

The thread pool consumes the read on the connfd and posts it back to the dispatcher so it can add it for polling next. But the dispatcher wouldn't be able to add it for polling until it returns from the poll() call. I need the dispatcher to periodically check if it needs to re-enable polling for any connfd.

What is a good timeout value so the dispatcher thread can periodically stop polling and update its pollfd list.

siri
  • 123
  • 1
  • 13

1 Answers1

0

You don't need to use the timeout (just set it to INF).

Timeout is basically used when an explicit timer operation is needed (some async IO libraries handles this for you).

To wake up a thread sleeping in poll, use the self-pipe trick. On Linux, eventfd is also available for use.

Using timerfd (Linux only), timeout can be completely obsoleted.

Tatsuyuki Ishi
  • 3,883
  • 3
  • 29
  • 41