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

后端 未结 3 1915
花落未央
花落未央 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:44

    If you have only a single socket, what's the point of polling in the first place? Wouldn't the best performance then be by just using blocking read/write?

    Wrt. the performance, with only a single file descriptor I don't think there is much, if any, difference between the various approaches. If you really care, I suppose you could measure, but I find it difficult that this would particularly matter for the overall performance of your program.

    Level/edge triggering. Consider you're monitoring a signal, for simplicity say some voltage in a line. Edge triggering means that something triggers when the voltage goes over or under some specific limit. Level triggering means that something is considered to be in a triggered state as long as the voltage is over/under the limit. That is, edge triggering triggers when some event happens (crossing some threshold), level triggering reflects the state of some "thing" (in this case, voltage).

    To get back to network programming, and edge triggered system might be one where you get some kind of signal when a packet is received. If you don't handle the event then the signal is lost. A level triggered system, OTOH, is something like asking "is there data waiting in the buffer for me?"; if you don't handle the event and ask again, the data will still be there waiting for you.

    0 讨论(0)
  • 2021-02-01 08:49

    According to the link: http://www.intelliproject.net/articles/showArticle/index/io_multiplexing.

    If you use only one descriptor:

    • select: 201 micro seconds.
    • poll: 159 micro seconds.
    • epoll: 176 micro seconds.

    Seems poll will be a better solution in such situation.

    0 讨论(0)
  • 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)

    0 讨论(0)
提交回复
热议问题