… | |
… | |
451 | .el .IP "\f(CWEVBACKEND_SELECT\fR (value 1, portable select backend)" 4 |
451 | .el .IP "\f(CWEVBACKEND_SELECT\fR (value 1, portable select backend)" 4 |
452 | .IX Item "EVBACKEND_SELECT (value 1, portable select backend)" |
452 | .IX Item "EVBACKEND_SELECT (value 1, portable select backend)" |
453 | This is your standard \fIselect\fR\|(2) backend. Not \fIcompletely\fR standard, as |
453 | This is your standard \fIselect\fR\|(2) backend. Not \fIcompletely\fR standard, as |
454 | libev tries to roll its own fd_set with no limits on the number of fds, |
454 | libev tries to roll its own fd_set with no limits on the number of fds, |
455 | but if that fails, expect a fairly low limit on the number of fds when |
455 | but if that fails, expect a fairly low limit on the number of fds when |
456 | using this backend. It doesn't scale too well (O(highest_fd)), but its usually |
456 | using this backend. It doesn't scale too well (O(highest_fd)), but its |
457 | the fastest backend for a low number of fds. |
457 | usually the fastest backend for a low number of (low\-numbered :) fds. |
|
|
458 | .Sp |
|
|
459 | To get good performance out of this backend you need a high amount of |
|
|
460 | parallelity (most of the file descriptors should be busy). If you are |
|
|
461 | writing a server, you should \f(CW\*(C`accept ()\*(C'\fR in a loop to accept as many |
|
|
462 | connections as possible during one iteration. You might also want to have |
|
|
463 | a look at \f(CW\*(C`ev_set_io_collect_interval ()\*(C'\fR to increase the amount of |
|
|
464 | readyness notifications you get per iteration. |
458 | .ie n .IP """EVBACKEND_POLL"" (value 2, poll backend, available everywhere except on windows)" 4 |
465 | .ie n .IP """EVBACKEND_POLL"" (value 2, poll backend, available everywhere except on windows)" 4 |
459 | .el .IP "\f(CWEVBACKEND_POLL\fR (value 2, poll backend, available everywhere except on windows)" 4 |
466 | .el .IP "\f(CWEVBACKEND_POLL\fR (value 2, poll backend, available everywhere except on windows)" 4 |
460 | .IX Item "EVBACKEND_POLL (value 2, poll backend, available everywhere except on windows)" |
467 | .IX Item "EVBACKEND_POLL (value 2, poll backend, available everywhere except on windows)" |
461 | And this is your standard \fIpoll\fR\|(2) backend. It's more complicated than |
468 | And this is your standard \fIpoll\fR\|(2) backend. It's more complicated |
462 | select, but handles sparse fds better and has no artificial limit on the |
469 | than select, but handles sparse fds better and has no artificial |
463 | number of fds you can use (except it will slow down considerably with a |
470 | limit on the number of fds you can use (except it will slow down |
464 | lot of inactive fds). It scales similarly to select, i.e. O(total_fds). |
471 | considerably with a lot of inactive fds). It scales similarly to select, |
|
|
472 | i.e. O(total_fds). See the entry for \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR, above, for |
|
|
473 | performance tips. |
465 | .ie n .IP """EVBACKEND_EPOLL"" (value 4, Linux)" 4 |
474 | .ie n .IP """EVBACKEND_EPOLL"" (value 4, Linux)" 4 |
466 | .el .IP "\f(CWEVBACKEND_EPOLL\fR (value 4, Linux)" 4 |
475 | .el .IP "\f(CWEVBACKEND_EPOLL\fR (value 4, Linux)" 4 |
467 | .IX Item "EVBACKEND_EPOLL (value 4, Linux)" |
476 | .IX Item "EVBACKEND_EPOLL (value 4, Linux)" |
468 | For few fds, this backend is a bit little slower than poll and select, |
477 | For few fds, this backend is a bit little slower than poll and select, |
469 | but it scales phenomenally better. While poll and select usually scale |
478 | but it scales phenomenally better. While poll and select usually scale |
470 | like O(total_fds) where n is the total number of fds (or the highest fd), |
479 | like O(total_fds) where n is the total number of fds (or the highest fd), |
471 | epoll scales either O(1) or O(active_fds). The epoll design has a number |
480 | epoll scales either O(1) or O(active_fds). The epoll design has a number |
472 | of shortcomings, such as silently dropping events in some hard-to-detect |
481 | of shortcomings, such as silently dropping events in some hard-to-detect |
473 | cases and rewiring a syscall per fd change, no fork support and bad |
482 | cases and rewiring a syscall per fd change, no fork support and bad |
474 | support for dup: |
483 | support for dup. |
475 | .Sp |
484 | .Sp |
476 | While stopping, setting and starting an I/O watcher in the same iteration |
485 | While stopping, setting and starting an I/O watcher in the same iteration |
477 | will result in some caching, there is still a syscall per such incident |
486 | will result in some caching, there is still a syscall per such incident |
478 | (because the fd could point to a different file description now), so its |
487 | (because the fd could point to a different file description now), so its |
479 | best to avoid that. Also, \f(CW\*(C`dup ()\*(C'\fR'ed file descriptors might not work |
488 | best to avoid that. Also, \f(CW\*(C`dup ()\*(C'\fR'ed file descriptors might not work |
480 | very well if you register events for both fds. |
489 | very well if you register events for both fds. |
481 | .Sp |
490 | .Sp |
482 | Please note that epoll sometimes generates spurious notifications, so you |
491 | Please note that epoll sometimes generates spurious notifications, so you |
483 | need to use non-blocking I/O or other means to avoid blocking when no data |
492 | need to use non-blocking I/O or other means to avoid blocking when no data |
484 | (or space) is available. |
493 | (or space) is available. |
|
|
494 | .Sp |
|
|
495 | Best performance from this backend is achieved by not unregistering all |
|
|
496 | watchers for a file descriptor until it has been closed, if possible, i.e. |
|
|
497 | keep at least one watcher active per fd at all times. |
|
|
498 | .Sp |
|
|
499 | While nominally embeddeble in other event loops, this feature is broken in |
|
|
500 | all kernel versions tested so far. |
485 | .ie n .IP """EVBACKEND_KQUEUE"" (value 8, most \s-1BSD\s0 clones)" 4 |
501 | .ie n .IP """EVBACKEND_KQUEUE"" (value 8, most \s-1BSD\s0 clones)" 4 |
486 | .el .IP "\f(CWEVBACKEND_KQUEUE\fR (value 8, most \s-1BSD\s0 clones)" 4 |
502 | .el .IP "\f(CWEVBACKEND_KQUEUE\fR (value 8, most \s-1BSD\s0 clones)" 4 |
487 | .IX Item "EVBACKEND_KQUEUE (value 8, most BSD clones)" |
503 | .IX Item "EVBACKEND_KQUEUE (value 8, most BSD clones)" |
488 | Kqueue deserves special mention, as at the time of this writing, it |
504 | Kqueue deserves special mention, as at the time of this writing, it |
489 | was broken on all BSDs except NetBSD (usually it doesn't work reliably |
505 | was broken on all BSDs except NetBSD (usually it doesn't work reliably |
… | |
… | |
501 | kernel is more efficient (which says nothing about its actual speed, of |
517 | kernel is more efficient (which says nothing about its actual speed, of |
502 | course). While stopping, setting and starting an I/O watcher does never |
518 | course). While stopping, setting and starting an I/O watcher does never |
503 | cause an extra syscall as with \f(CW\*(C`EVBACKEND_EPOLL\*(C'\fR, it still adds up to |
519 | cause an extra syscall as with \f(CW\*(C`EVBACKEND_EPOLL\*(C'\fR, it still adds up to |
504 | two event changes per incident, support for \f(CW\*(C`fork ()\*(C'\fR is very bad and it |
520 | two event changes per incident, support for \f(CW\*(C`fork ()\*(C'\fR is very bad and it |
505 | drops fds silently in similarly hard-to-detect cases. |
521 | drops fds silently in similarly hard-to-detect cases. |
|
|
522 | .Sp |
|
|
523 | This backend usually performs well under most conditions. |
|
|
524 | .Sp |
|
|
525 | While nominally embeddable in other event loops, this doesn't work |
|
|
526 | everywhere, so you might need to test for this. And since it is broken |
|
|
527 | almost everywhere, you should only use it when you have a lot of sockets |
|
|
528 | (for which it usually works), by embedding it into another event loop |
|
|
529 | (e.g. \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR or \f(CW\*(C`EVBACKEND_POLL\*(C'\fR) and using it only for |
|
|
530 | sockets. |
506 | .ie n .IP """EVBACKEND_DEVPOLL"" (value 16, Solaris 8)" 4 |
531 | .ie n .IP """EVBACKEND_DEVPOLL"" (value 16, Solaris 8)" 4 |
507 | .el .IP "\f(CWEVBACKEND_DEVPOLL\fR (value 16, Solaris 8)" 4 |
532 | .el .IP "\f(CWEVBACKEND_DEVPOLL\fR (value 16, Solaris 8)" 4 |
508 | .IX Item "EVBACKEND_DEVPOLL (value 16, Solaris 8)" |
533 | .IX Item "EVBACKEND_DEVPOLL (value 16, Solaris 8)" |
509 | This is not implemented yet (and might never be). |
534 | This is not implemented yet (and might never be, unless you send me an |
|
|
535 | implementation). According to reports, \f(CW\*(C`/dev/poll\*(C'\fR only supports sockets |
|
|
536 | and is not embeddable, which would limit the usefulness of this backend |
|
|
537 | immensely. |
510 | .ie n .IP """EVBACKEND_PORT"" (value 32, Solaris 10)" 4 |
538 | .ie n .IP """EVBACKEND_PORT"" (value 32, Solaris 10)" 4 |
511 | .el .IP "\f(CWEVBACKEND_PORT\fR (value 32, Solaris 10)" 4 |
539 | .el .IP "\f(CWEVBACKEND_PORT\fR (value 32, Solaris 10)" 4 |
512 | .IX Item "EVBACKEND_PORT (value 32, Solaris 10)" |
540 | .IX Item "EVBACKEND_PORT (value 32, Solaris 10)" |
513 | This uses the Solaris 10 event port mechanism. As with everything on Solaris, |
541 | This uses the Solaris 10 event port mechanism. As with everything on Solaris, |
514 | it's really slow, but it still scales very well (O(active_fds)). |
542 | it's really slow, but it still scales very well (O(active_fds)). |
515 | .Sp |
543 | .Sp |
516 | Please note that solaris event ports can deliver a lot of spurious |
544 | Please note that solaris event ports can deliver a lot of spurious |
517 | notifications, so you need to use non-blocking I/O or other means to avoid |
545 | notifications, so you need to use non-blocking I/O or other means to avoid |
518 | blocking when no data (or space) is available. |
546 | blocking when no data (or space) is available. |
|
|
547 | .Sp |
|
|
548 | While this backend scales well, it requires one system call per active |
|
|
549 | file descriptor per loop iteration. For small and medium numbers of file |
|
|
550 | descriptors a \*(L"slow\*(R" \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR or \f(CW\*(C`EVBACKEND_POLL\*(C'\fR backend |
|
|
551 | might perform better. |
519 | .ie n .IP """EVBACKEND_ALL""" 4 |
552 | .ie n .IP """EVBACKEND_ALL""" 4 |
520 | .el .IP "\f(CWEVBACKEND_ALL\fR" 4 |
553 | .el .IP "\f(CWEVBACKEND_ALL\fR" 4 |
521 | .IX Item "EVBACKEND_ALL" |
554 | .IX Item "EVBACKEND_ALL" |
522 | Try all backends (even potentially broken ones that wouldn't be tried |
555 | Try all backends (even potentially broken ones that wouldn't be tried |
523 | with \f(CW\*(C`EVFLAG_AUTO\*(C'\fR). Since this is a mask, you can do stuff such as |
556 | with \f(CW\*(C`EVFLAG_AUTO\*(C'\fR). Since this is a mask, you can do stuff such as |
524 | \&\f(CW\*(C`EVBACKEND_ALL & ~EVBACKEND_KQUEUE\*(C'\fR. |
557 | \&\f(CW\*(C`EVBACKEND_ALL & ~EVBACKEND_KQUEUE\*(C'\fR. |
|
|
558 | .Sp |
|
|
559 | It is definitely not recommended to use this flag. |
525 | .RE |
560 | .RE |
526 | .RS 4 |
561 | .RS 4 |
527 | .Sp |
562 | .Sp |
528 | If one or more of these are ored into the flags value, then only these |
563 | If one or more of these are ored into the flags value, then only these |
529 | backends will be tried (in the reverse order as given here). If none are |
564 | backends will be tried (in the reverse order as given here). If none are |
… | |
… | |
755 | overhead for the actual polling but can deliver many events at once. |
790 | overhead for the actual polling but can deliver many events at once. |
756 | .Sp |
791 | .Sp |
757 | By setting a higher \fIio collect interval\fR you allow libev to spend more |
792 | By setting a higher \fIio collect interval\fR you allow libev to spend more |
758 | time collecting I/O events, so you can handle more events per iteration, |
793 | time collecting I/O events, so you can handle more events per iteration, |
759 | at the cost of increasing latency. Timeouts (both \f(CW\*(C`ev_periodic\*(C'\fR and |
794 | at the cost of increasing latency. Timeouts (both \f(CW\*(C`ev_periodic\*(C'\fR and |
760 | \&\f(CW\*(C`ev_timer\*(C'\fR) will be not affected. Setting this to a non-null bvalue will |
795 | \&\f(CW\*(C`ev_timer\*(C'\fR) will be not affected. Setting this to a non-null value will |
761 | introduce an additional \f(CW\*(C`ev_sleep ()\*(C'\fR call into most loop iterations. |
796 | introduce an additional \f(CW\*(C`ev_sleep ()\*(C'\fR call into most loop iterations. |
762 | .Sp |
797 | .Sp |
763 | Likewise, by setting a higher \fItimeout collect interval\fR you allow libev |
798 | Likewise, by setting a higher \fItimeout collect interval\fR you allow libev |
764 | to spend more time collecting timeouts, at the expense of increased |
799 | to spend more time collecting timeouts, at the expense of increased |
765 | latency (the watcher callback will be called later). \f(CW\*(C`ev_io\*(C'\fR watchers |
800 | latency (the watcher callback will be called later). \f(CW\*(C`ev_io\*(C'\fR watchers |