关于epoll工作原理的一般说明? [英] General explanation of how epoll works?

查看:117
本文介绍了关于epoll工作原理的一般说明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做有关从数据库轮询(通过同步存储过程调用)切换到消息队列(通过pub/sub)的技术文章.我想解释一下,轮询数据库与建立与AMQP代理的连接和配置消息处理程序相比,有很大的不同,而且要重得多.

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.

有人可以在这里提供解释吗,或者指向我一个很好的高级教程,介绍通知套接字上可用的新数据时epoll的工作方式?

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?

推荐答案

我假设"epoll的工作方式"是指从用户的角度来看它的工作方式(例如,如何通知您的代码,以及应该处理它),而不是内核的观点(如epoll的实现方式).

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).

简短版本非常简单:就像poll一样,除了两件事:

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

  1. 它使用一个不透明数据结构的句柄,因此您不会在内核边界之间来回传递太多数据.
  2. 它具有poll没有的选项(特别是边沿触发和单发通知),可以让您在某些情况下编写更有效的代码.
  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.

(还有一个事实,即它仅在linux上运行.BSD和相关系统具有kqueue,这是获得某些相同优势的明显不同的方式,Solaris具有/dev/poll等,而某些* nixes具有因此,如果您想编写可移植的代码,则必须使用poll,或使用某些更高级的库,例如libevent,或者自己编写与libevent类似的代码.)

(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.)

如果您已经了解selectpoll,请参阅 Wikipedia文章和在其参考文献中链接的博客文章 ,告诉您几乎所有您需要了解的内容,以及手册页将填补所有空白.

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.

如果不是,请先学习poll,然后才有必要学习epoll的不同之处.

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

我仍然不确定这与您的主要问题有什么关系.您可以在数据库文件上epollinotify,或者在消息传递系统中使用pipesocket,或者在Linux中可以用文件描述符表示的几乎所有其他内容,因此我不确定了解epoll如何帮助您解释轮询数据库与轮询消息队列之间的区别.两者之间当然有很大的差异,但是事件触发机制并不是其中之一.

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.

这篇关于关于epoll工作原理的一般说明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆