… | |
… | |
389 | epoll scales either O(1) or O(active_fds). The epoll design has a number |
389 | epoll scales either O(1) or O(active_fds). The epoll design has a number |
390 | of shortcomings, such as silently dropping events in some hard-to-detect |
390 | of shortcomings, such as silently dropping events in some hard-to-detect |
391 | cases and requiring a system call per fd change, no fork support and bad |
391 | cases and requiring a system call per fd change, no fork support and bad |
392 | support for dup. |
392 | support for dup. |
393 | |
393 | |
|
|
394 | Epoll is also notoriously buggy - embedding epoll fds should work, but |
|
|
395 | of course doesn't, and epoll just loves to report events for totally |
|
|
396 | I<different> file descriptors (even already closed ones) than registered |
|
|
397 | in the set (especially on SMP systems). Libev tries to counter these |
|
|
398 | spurious notifications by employing an additional generation counter and |
|
|
399 | comparing that against the events to filter out spurious ones. |
|
|
400 | |
394 | While stopping, setting and starting an I/O watcher in the same iteration |
401 | While stopping, setting and starting an I/O watcher in the same iteration |
395 | will result in some caching, there is still a system call per such incident |
402 | will result in some caching, there is still a system call per such incident |
396 | (because the fd could point to a different file description now), so its |
403 | (because the fd could point to a different file description now), so its |
397 | best to avoid that. Also, C<dup ()>'ed file descriptors might not work |
404 | best to avoid that. Also, C<dup ()>'ed file descriptors might not work |
398 | very well if you register events for both fds. |
405 | very well if you register events for both fds. |
399 | |
|
|
400 | Please note that epoll sometimes generates spurious notifications, so you |
|
|
401 | need to use non-blocking I/O or other means to avoid blocking when no data |
|
|
402 | (or space) is available. |
|
|
403 | |
406 | |
404 | Best performance from this backend is achieved by not unregistering all |
407 | Best performance from this backend is achieved by not unregistering all |
405 | watchers for a file descriptor until it has been closed, if possible, |
408 | watchers for a file descriptor until it has been closed, if possible, |
406 | i.e. keep at least one watcher active per fd at all times. Stopping and |
409 | i.e. keep at least one watcher active per fd at all times. Stopping and |
407 | starting a watcher (without re-setting it) also usually doesn't cause |
410 | starting a watcher (without re-setting it) also usually doesn't cause |