General explanation of how epoll works?
Asked Answered
C

1

8

I'm doing a technical write-up on switching from a database-polling (via synchronous stored procedure call) to a message queue (via pub/sub). I'd like to be able to explain how polling a database is vastly different and much heavier than setting up a connection to a AMQP broker and configuring a message handler.

Can someone maybe provide an explanation here, or point me to a good high level tutorial on how epoll works when notifying of new data becoming available on a socket?

Cullie answered 12/12, 2012 at 17:48 Comment(2)
Have you read http://en.wikipedia.org/wiki/Epoll, or http://www.kernel.org/doc/man-pages/online/pages/man4/epoll.4.html, both of which have general explanations? Also, I'm not sure how explaining epoll will help explain the difference you're discussing. You can epoll an inotify on the database file, or you can epoll the queue underneath your messaging system, so… what are you aiming at?Institutionalize
Sorry, I was posted the question too early, by mistake. I've updated it. Does that clarify things?Cullie
I
8

I assume by "how epoll works" you're referring to how it works from the user point of view (as in, how your code gets notified, and should deal with it), as opposed to the kernel point of view (as in, how epoll is implemented).

The short version is very simple: It's just like poll, except for two things:

  1. It uses a handle to an opaque data structure so you're not passing as much data back and forth across the kernel boundary.
  2. It has options that poll doesn't have (notably edge triggering and one-shot notifications) that can let you write more efficient code in certain situations.

(There's also the fact that it only works on linux. BSD and related systems have kqueue, a significantly different way to get some of the same advantages, Solaris has /dev/poll, etc., and some *nixes have nothing equivalent. So if you want to write portable code, you either have to use poll, or use some higher-level library like libevent, or write the equivalent of libevent yourself.)

If you already understand select and poll, the the Wikipedia article and the blog post linked in its References should, between them, tell you almost everything you need to know, and the man page will fill in any gaps.

If not, go learn about poll first, and only then will it make sense to learn how epoll is different.

I'm still not sure how this relates to your main question at all. You can epoll an inotify on a database file, or a pipe or socket underlying a messaging system, or just about anything else that can be represented as a file descriptor in linux, so I'm not sure how understanding epoll will help you explain the differences between polling a database vs. polling a message queue. There are of course vast differences between the two, but the event-triggering mechanism is not one of them.

Institutionalize answered 12/12, 2012 at 19:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.