What are the underlying differences among select, epoll, kqueue, and evport?
Asked Answered
P

1

18

I am reading Redis recently. Redis implements a simple event-driven library based on I/O multiplexing. Redis says it would choose the best multiplexing supported by the system, and gives the following code:

/* Include the best multiplexing layer supported by this system.
 * The following should be ordered by performances, descending. */
#ifdef HAVE_EVPORT
#include "ae_evport.c"
#else
    #ifdef HAVE_EPOLL
    #include "ae_epoll.c"
    #else
        #ifdef HAVE_KQUEUE
        #include "ae_kqueue.c"
        #else
        #include "ae_select.c"
        #endif
    #endif
#endif

I wanna know whether they have fundamental performance differences? If so, why?

Best regards

Plasticize answered 17/10, 2014 at 8:29 Comment(0)
B
30

In general, all Async I/O subsystems have different internals, but in current specific case these concrete async I/O libs are used to support as much platforms as possible. That is:

  • evport = Solaris 10
  • epoll = Linux
  • kqueue = OS X, FreeBSD
  • select = usually installed on all platforms as a fallback

Evport, Epoll, and KQueue have O(1) descriptor selection algorithm complexity, and they all use internal kernel space memory structures. Also they can serve lots (hundreds of thousands) file descriptors.

Apart the others, select can only serve up to 1024 descriptors, and does full scan of descriptors (so every time it iterates all descriptors to chose one to work with), so the complexity is O(n).

Braze answered 17/10, 2014 at 15:22 Comment(2)
Thanks. I found this article helps. eecs.berkeley.edu/~sangjin/2012/12/21/epoll-vs-kqueue.htmlPlasticize
Should be noted that Illumos (The open source Solaris derivative) also supports (Linux style) epoll: illumos.org/man/5/epollAffiche

© 2022 - 2024 — McMap. All rights reserved.