使用单个文件描述符,select,poll和epoll和...之间是否有任何性能差异? [英] With a single file descriptor, Is there any performance difference between select, poll and epoll and ...?

查看:218
本文介绍了使用单个文件描述符,select,poll和epoll和...之间是否有任何性能差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题真的说明了一切。

和...也包括pselect和ppoll ..

The and ... means also include pselect and ppoll..

我工作的服务器项目基本上是用多线程结构化的。每个
线程处理一个或多个会话。所有的线程都是相同的。协议
负责哪个线程将主持会话。

The server project I'm working on basically structured with multiple threads. Each thread handles one or more sessions. All the threads are identical. The protocol takes care of which thread will host the session.

我使用一个内部套接字类来包装。感兴趣的是一个调用poll(linux)或select(windows)的checkread调用。

I'm using an inhouse socket class that wraps things up. The point of interest is a checkread call which calls either poll (linux) or select (windows).

总而言之,每个线程都在一个套接字上调用poll。从我可以告诉,使用epoll只会有好处,如果这个线程正在查看多个套接字,如你会说,一个HTTP服务器。这不是我在我的情况下。并且该类一次只处理一个套接字。

In summary each thread currently calls poll on a single socket. From what I can tell, using epoll would only be of benefit if this thread was looking at multiple sockets such as what you'd get in say an HTTP server. That's not what I'm doing in my case. And the class only handles a single socket at a time.

在epoll的手册页中有一些关于边沿和电平触发的简要讨论。我不知道这是什么意思。在套接字类中,我看到在代码的窗口部分的优化,使用ioctlsocket& FIONREAD来检查是否有任何数据。想知道如果返回> 0,即使一个完整的UDP数据包在呼叫时没有到达。这是什么边缘触发是在epoll?

There is some brief discussion about edge and level triggering in the man pages for epoll. I'm not really sure what it means. In the socket class I see an optimization in the windows part of the code that shortcuts the select call with an ioctlsocket & FIONREAD to check if there is any data. Wondering if that would return > 0 even if a complete UDP packet hadn't arrived at the time of the call. Is this what edge triggering is in epoll?

在一些基本测试中,我也看到使用select和poll之间没有明显的区别。

In some rudimentary testing, I'm also seeing no noticeable difference between using select and poll.

我可以看到,使用ppoll可能是有益的,因为更大的超时精度。有任何想法吗?

I can see that using ppoll might be of benefit though due to greater precision in the timeout. Any thoughts?

是的,我试图为接收大量数据的会话优化吞吐量。服务器是更多的网络&磁盘绑定比CPU。

And yes, I am trying to optimize throughput for a session that is receiving lots of data. The server is more Network & Disk bound than CPU.

推荐答案

epoll vs select或poll的主要区别是epoll在运行时单线程。我不知道这将如何比较使用select或poll的多线程服务器。
查看此 http://monkey.org/~provos/libevent/libevent-benchmark2.jpg

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

这个的原因(据我所知)是,当你使用select或poll时,你必须循环通过所有连接的套接字,以确定哪些具有要读取的数据。当你使用epoll时,它保持一个单独的数组,其中只包含有要读取数据的套接字。这节省了大量的循环周期,并且差异变得越来越明显的是连接的套接字越多。

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.

另一件事来看性能是否成为一个主要问题是io完成端口(仅限Windows)和kqueue(仅限FreeBSD)。同样重要的是要记住epoll只是linux。在大多数情况下,select或poll会正常工作。

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.

在单个文件描述符的情况下,select和poll比epoll更有效由于更简单。 (epoll有一些开销,它本身不能用于只有一个套接字)

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)

这篇关于使用单个文件描述符,select,poll和epoll和...之间是否有任何性能差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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