创建一个脚本来测试服务器(它能够超过100K并发TCP套接字)。在达到65536时,客户端停止尝试建立连接。不知道为什么。
for(vec in output) {
write(format(vec, scientific=FALSE), file="test2.txt", append=TRUE, sep="\t", ncolumns=length(vec))
}
为了记录,我在Ubuntu 14.04(linux 3.19.0)上以root身份运行它,use AnyEvent;
use EV;
use AnyEvent::Handle;
use IO::Socket::UNIX;
use Time::HiRes qw( gettimeofday );
use Data::Dumper;
my $count = 0;
my @hds = ();
my $cv = AnyEvent->condvar;
my $ips = ["192.168.1.11", "192.168.1.12","192.168.1.13","192.168.1.14"];
my $i;
my $j = 0;
for ($i=0; $i<1000; $i++) {
kickoff();
}
$cv->recv;
sub kickoff {
my $hdl = new AnyEvent::Handle
connect => ["192.168.1.1", 80],
on_error => sub {
my ($hdl, $fatal, $msg) = @_;
print "error when count=$count, $!\n";
$hdl->destroy;
$cv->send;
},
on_connect => sub {
$count ++;
if ($count > 65000) {
print "$count\n";
} elsif (($count % 1000) == 0) {
print "$count\n";
}
if ($count >= 100000) { return; }
kickoff();
},
on_prepare => sub {
my $hdl = shift;
#print Dumper($hd); exit;
mybind($hdl->{fh}, $ips->[$j%4]);
$j ++;
},
on_read => ::handleData;
push @hds, $hdl;
}
sub getTS {
my ($seconds, $microseconds) = gettimeofday;
return $seconds + (0.0+ $microseconds)/1000000.0;
}
sub mybind {
my ($sock, $ip) = @_;
my $local_host=inet_aton($ip) or return undef;
my $local = sockaddr_in(0, $local_host);
bind($sock,$local) or print 'Couldn\'t bind to local\n';
}
显示100000.
知道为什么吗?
UPDATE1
根据评论进行一些更新。谢谢你们。
ulimit -a
但没有配置net.ipv4.netfilter.ip_conntrack_max