epoll性能

发布于 2024-08-19 00:34:05 字数 533 浏览 6 评论 0原文

谁能帮我回答有关 epoll_wait 的问题。

  1. 使用多个线程在同一个 fd 上调用 epoll_wait 来为大约 100K 活动套接字提供服务是否太过分了?或者只创建 1 个线程来执行 epoll_wait 就足够了吗?

  2. 例如,当只有一个套接字准备好读取数据时,有多少线程将从 epoll_wait 中唤醒?我的意思是,是否会出现这样的情况:2 个或更多线程将从 epoll_wait 中唤醒,但在结果事件中具有相同的 fd?

  3. 在与许多活动客户端(例如 50K+)一起使用的服务器中组织线程的最佳方式是什么。我认为最好的方法是:1 个 I/O 工作线程,它执行 epoll_wait 和 i/o 操作。 + 许多数据处理线程,它们将处理从 I/O 工作线程接收的数据(可能需要很长时间,例如任何游戏逻辑)并为 I/O 工作线程编写新数据以发送到客户。我的这种方法是否正确,或者任何人都可以帮助我找出组织此方法的最佳方法?

预先感谢,瓦伦丁

Can anyone please help me to answer the questions about epoll_wait.

  1. Is it overkill to use many threads that call epoll_wait on the same fds set to serve at about 100K active sockets? or will it just be enough to create only 1 thread to perform epoll_wait?

  2. How many threads will wake up from epoll_wait when for example only one socket is ready to read data? i mean, can there be situation when 2 or more threads will wake up from epoll_wait but will have same fds in resulted events?

  3. What is the best way to organize threads in server that works with many active clients (e.g. 50K+). The best way i think is: 1 I/O Worker Thread which perfroms epoll_wait and i/o operations. + Many Data processing threads which will process the data received from I/O worker thread (can take a long time, such as any game logic) and compose new data for I/O worker thread to send to client. Am I right in this approach, or can anyone help me to find out the best way to organize this?

Thanks in advance, Valentin

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

做个ˇ局外人 2024-08-26 00:34:05
  1. 使用 epoll 时,您希望将线程总数调整为要用于处理的物理 CPU 核心(或超线程调度单元)的数量。仅使用一个线程进行工作意味着一次最多有一个核心处于活动状态。

  2. 这取决于epoll文件描述符的模式。事件可以是“边缘触发”,这意味着它们仅原子地发生一次,也可以是“级别触发”,这意味着如果缓冲区中有空间,任何调用者都会收到事件。

  3. 没有足够的信息可说。为了简单起见,我建议根本不要有特殊用途的线程,而只需在接收事件的线程中处理每个事件的“命令”。但显然这取决于您的应用程序的性质。

  1. When using epoll, you want to size your thread total to the number of physical CPU cores (or hyperthread dispatch units) which you want to use for processing. Using only one thread for work means that at most one core will be active at a time.

  2. It depends on the mode of the epoll file descriptor. Events can be "edge triggered", meaning that they only happen once atomically, or "level triggered" meaning that any caller gets an event if there is space in the buffer.

  3. Not enough information to say. I'd suggest not having special purpose threads at all, for simplicity, and simply handling each event's "command" in the thread in which it is received. But obviously that depends on the nature of your application.

南城旧梦 2024-08-26 00:34:05

我建议您阅读 2006 年的这篇文章:http://www.kegel.com/c10k.html

I recommend you read this article from 2006: http://www.kegel.com/c10k.html

游魂 2024-08-26 00:34:05

实际上,这是 epoll 的错误用例。

绝对不能在线程之间共享 epoll fd。否则,一个线程可能会读取一个 fd 上的部分传入数据,而另一个线程也会读取同一个 fd 上的部分传入数据,而无法知道哪一部分数据在另一部分之前。

只需在每个调用 epoll_wait 的线程中调用 epoll_create 即可。否则 I/O 损坏。

Actually this is a wrong use case of epoll.

You must absolutely not share the epoll fd between threads. Otherwise you have the possibility that one thread read part of incoming data on one fd and another thread too on the same fd without any way to know which part of the data was before the other.

Just call epoll_create in each and every thread that calls epoll_wait. Otherwise the I/O is broken.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文