Linux上是否存在雷电群问题? [英] Does the Thundering Herd Problem exist on Linux anymore?

查看:104
本文介绍了Linux上是否存在雷电群问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多linux/unix编程书籍和教程都谈到雷声群问题" 当select()调用上阻塞了多个线程或派生时,等待侦听套接字的可读性.当连接进入时,所有线程和派生都被唤醒,但是只有一个"wins"成功调用了"accept()".同时,无缘无故地浪费了很多cpu时间来唤醒所有线程/分支.

Many linux/unix programming books and tutorials speak about the "Thundering Herd Problem" which happens when multiple threads or forks are blocked on a select() call waiting for readability of a listening socket. When the connection comes in, all threads and forks are woken up but only one "wins" with a successful call to "accept()". In the meantime, a lot of cpu time is wasted waking up all the threads/forks for no reason.

我注意到项目提供了修复"(针对Linux内核中的此问题),但这是一个非常古老的补丁.

I noticed a project which provides a "fix" for this problem in the linux kernel, but this is a very old patch.

我认为有两种变体.一种是每个分叉先执行select()然后接受(),然后再执行一次accept().

I think there are two variants; One where each fork does select() and then accept(), and one that just does accept().

在这两种情况下,现代的Unix/Linux内核还是仍然存在雷电群问题?还是只有"select()然后accept()"版本?

Do modern unix/linux kernels still have the Thundering Herd Problem in both these cases or only the "select() then accept()" version?

推荐答案

多年来,大多数unix/linux内核将响应序列化为accept(2),换句话说,如果阻塞了多个线程,则仅唤醒一个线程.针对单个打开的文件描述接受(2).

For years, most unix/linux kernels serialize response to accept(2)s, in other words, only one thread is waken up if more than one are blocking on accept(2) against a single open file description.

OTOH,正如您所描述的那样,许多(即使不是全部)内核仍然在选择接受模式中存在雷电追赶问题.

OTOH, many (if not all) kernels still have the thundering herd problem in the select-accept pattern as you describe.

我写了一个简单的脚本( https://gist.github.com/kazuho/10436253 )进行验证问题的存在,并发现该问题存在于Linux 2.6.32和Darwin 12.5.0(OS X 10.8.5)上.

I have written a simple script ( https://gist.github.com/kazuho/10436253 ) to verify the existence of the problem, and found out that the problem exists on linux 2.6.32 and Darwin 12.5.0 (OS X 10.8.5).

这篇关于Linux上是否存在雷电群问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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