• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Accept 惊群现象测试perl脚本 - 深入浅出eBPF

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

Accept 惊群现象测试perl脚本

$uname -a
Linux debian-11-34 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt9-3~deb8u1 (2015-04-24) x86_64 GNU/Linux
 
经过测试Debina 8.0 已经解决了Aceept thundering herd 
 
 
# 1) run this script with either "accept" or "select-accept" as the argument
# (the script listens to 127.0.0.1:12345)
# 2) telnet localhost 12345
# 3) if you see "accept failed", there is the thundering herd problem
#
#
use strict;
use warnings;
use IO::Socket::INET;

my $mode = $ARGV[0] || \'\';
if ($mode !~ /^(accept|select-accept)$/) {
    die "Usage: $0 <accept|select-accept>\n";
}
my $listener = IO::Socket::INET->new(
                                     Listen => 5,
                                     LocalPort => 12345,
                                     LocalAddr => \'127.0.0.1\',
                                     Proto => \'tcp\',
                                     ReuseAddr => 1,
                                     ) or die "failed to listen to port 127.0.0.1:12345:$!";

if ($mode eq \'select-accept\') {
    $listener->blocking(0)
    or die "failed to set listening socket to non-blocking mode:$!";
}
my $pid = fork;
die "fork failed:$!"
unless defined $pid;
while (1) {
    if ($mode eq \'select-accept\') {
        while (1) {
            my $rfds = \'\';
            vec($rfds, fileno($listener), 1) = 1;
            if (select($rfds, undef, undef, undef) >= 1) {
                last;
            }
        }
    }
    my $conn = $listener->accept;
    if ($conn) {
        warn "connected!";
        $conn->close;
    } else {
        warn "accept failed:$!";
    }
}

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Linux,find和perl正则替换文件内容、tar解压缩、cp复制、rm删除发布时间:2022-07-22
下一篇:
Perl按行分割文件发布时间:2022-07-22
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap