Accept 惊群现象测试perl脚本
# (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:$!";
}
最新文章
- Docker Container 配置独立IP
- IT求职中,笔试、面试的算法准备
- Mockito自定义verify参数Matcher
- 第4章 jQuery的事件和动画(1)——事件篇
- linux下软件安装的方法
- AOP在 .NET中的七种实现方法
- [译]LINT TO SQL 介绍(数据库查询) - Part.3
- hdu 3646
- Exercise: Rot13 Reader
- 第七篇、CSS3新增属性
- 【iOS知识学习】_如何判断手机是否为静音模式
- javascript中的__proto__和prototype
- 一款好用的软件easyUI
- Linux命令行增强版
- Linux LVM扩容和缩容
- 没有 iOS 开发者账号的情况下部署到真机的方法
- 详解如何在 Linux 中安装最新的 Python 3.6 版本
- 远程图片转化为base64
- Java - 26 Java 数据结构
- Solr系列五:solr搜索详解(solr搜索流程介绍、查询语法及解析器详解)
热门文章
- 2018.10.10 Java的The superclass ";javax.servlet.http.HttpServlet"; was not found on the Java Build Path 错误
- SqlSugar之SqlQueryDynamic返回值处理
- EF执行SQL语句
- c语言描述的直接插入排序法
- svg了解一下
- CSS&;JS定位器
- CentOS 7安装Oracle (CentOS Linux release 7.5.1804)
- javascript跳转页面
- window.location.href 跳转无历史记录
- c c++面试----c工程开发之链接