zoukankan      html  css  js  c++  java
  • 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> ";
    }
    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:$!";
        }
    }
  • 相关阅读:
    基于注解的ssh框架之spring配置文件
    hdu 4770 Lights Against Dudely
    便捷开发工具(未完)
    solr 简单搭建 数据库数据同步(待续)
    Nginx对某个文件夹或整个站点进行登录认证的方法
    swift 单例模式
    POJ 2823 Sliding Window(单调队列)
    Android 网络下载图片
    一个表空间offline后alert日志报ORA-01135 和ORA-01110的问题
    [c#]分析器错误消息: 发现不明白的匹配。
  • 原文地址:https://www.cnblogs.com/davad/p/4555228.html
Copyright © 2011-2022 走看看