With a single file descriptor, Is there any performance difference between select, poll and epoll and …?

后端 未结 3 1908
花落未央
花落未央 2021-02-01 08:28

The title really says it all.

The and ... means also include pselect and ppoll..

The server project I\'m working on basically structured with multiple threads.

3条回答
  •  独厮守ぢ
    2021-02-01 08:54

    The main difference between epoll vs select or poll is that epoll scales a lot better when run in a single thread. I don't know how this would compare to using a multithreaded server using select or poll. Look at this http://monkey.org/~provos/libevent/libevent-benchmark2.jpg

    The reason for this(as far as I can tell) is that when you are using select or poll you must loop through all the connected sockets to determine which ones have data to be read. When you are using epoll, it keeps a seperate array which contains references only to sockets which have data to be read. This saves you lots of loop cycles, and the difference becomes more and more noticeable the more sockets that are connected.

    Another thing to look into if performance ever becomes a major issue is io completion ports(windows only) and kqueue(FreeBSD only). It's also important to remember that epoll is linux only. In most cases select or poll will work just fine.

    In the case of a single file descriptor, select and poll are more efficient than epoll due to being much simpler. (epoll has some overhead which doesn't make itself useful with only a single socket)

提交回复
热议问题