General explanation of how epoll works?

☆樱花仙子☆ 提交于 2019-12-06 02:41:28

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/13845634/general-explanation-of-how-epoll-works

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!