7

I looked at the differences between poll, epoll and select. What I don't understand is when should I use select. I don't see any advantage, given that poll and epoll have everything that select has, and more.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Luke SpringWalker
  • 1,600
  • 3
  • 19
  • 33
  • 3
    `epoll()` is Linux specific. So if you care for portablility, only `select()` and `poll()` remain. – Ingo Leonhardt Aug 02 '13 at 15:41
  • Depends on the number of sockets (FD) you want to monitor. For less than 10 `select` is somehow faster than epoll. Also `epoll` is Unix specific. `select` has a MAX_LIMIT (1024 I think) whereas `epoll` doesn't have. – ja_mesa Aug 02 '13 at 15:46
  • 1
    This is a great summary [poll vs select vs event-based ](http://daniel.haxx.se/docs/poll-vs-select.html) and this is pretty good too [The C10K problem](http://www.kegel.com/c10k.html). `select` and is the most portable, `poll` next and `epoll` is linux only. Using `select` and `poll` is simpler than `epoll` but if need the scalability then go w/ `epoll` if you can. – Shafik Yaghmour Aug 02 '13 at 15:55
  • Should look up and read Beej's guide to networking... it explains it all in a very useful manner. – t0mm13b Aug 02 '13 at 15:57
  • You need to remember that `select()` preceded `poll()` by quite a number of years. – user207421 Mar 11 '21 at 05:04

2 Answers2

0

Historically, select came first in BSD4.2 by 1983. Being first, it has the privilege of being the most prevalent and the most portable.

That said, both select and poll scales terribly. select scales to O(highest_fd), and poll to O(total_fds), according to LIBEV(3). epoll scales much better for a large number of file descriptors, but is specific only to Linux.

Using an event library like libevent, libev, or libuv will provide an abstraction layer and try to use the most performant method on your system, so you shouldn't have to worry about choosing between select, poll, epoll, or kqueue (for MacOS and the BSD's).

Samuel Hunter
  • 527
  • 2
  • 11
-2

select() monitor less file descriptor than poll(). Moreover, some implementation of select() are just using poll().

Kevin L.
  • 17
  • 1