Skip to content

Instantly share code, notes, and snippets.

@kazeburo
Created July 26, 2011 09:58
Show Gist options
  • Select an option

  • Save kazeburo/1106412 to your computer and use it in GitHub Desktop.

Select an option

Save kazeburo/1106412 to your computer and use it in GitHub Desktop.
--- memcachedos.pl 2011-07-26 18:57:36.000000000 +0900
+++ dos/memcachedos.pl 2011-07-26 18:39:40.000000000 +0900
@@ -7,21 +7,28 @@
use strict;
use warnings;
+use lib "extlib/lib/perl5";
use AnyEvent;
use AnyEvent::Socket;
+use BSD::Resource;
+use Time::HiRes;
die "$0 <host> <port> <fork num>" unless @ARGV;
+setrlimit(RLIMIT_NOFILE,300000,300000);
+warn getrlimit(RLIMIT_NOFILE);
+
# Options
my $maxconn = 10000;
my $activeconn = 900;
my $start_at = time;
my ($host, $port, $fork_num) = @ARGV;
+warn "$host:$port";
if ($fork_num) {
for (1..$fork_num) {
my $pid = fork;
- if ($pid) { memcachedos() }
+ if ($pid) { Time::HiRes::sleep(int(rand(1))); memcachedos() }
}
} else {
memcachedos();
@@ -38,16 +45,17 @@
my $fh = splice( @fh, $nfh, 1 );
return unless $fh;
my $ready; $ready = AE::io $fh, 1, sub {
- print $fh "stats\n";
+ # print $fh "stats\r\n";
undef $ready;
close $fh;
$closed++;
};
};
-
+ my $prev=$success;
my $logger = AE::timer 0, 3, sub {
- printf "TIME:%s PID:%s Connect:%s Active:%s Success:%s Closed:%s Fail:%s Msg:%s\n", time - $start_at, $$,
- $i, scalar @fh, $success, $closed, $fail, $last_error;
+ printf "TIME:%s PID:%s Connect:%s Active:%s Success:%s QPS:%s Closed:%s Fail:%s Msg:%s\n", time - $start_at, $$,
+ $i, scalar @fh, $success, ($success - $prev)/3, $closed, $fail, $last_error;
+ $prev = $success;
};
# my $t1 = AE::timer 1000, 0, sub { $cv->send };
@@ -66,13 +74,13 @@
push @fh, $fh;
my $ready;
$ready = AE::io $fh, 1, sub {
- print $fh "stats\n";
+ print $fh "stats\r\n";
undef $ready;
};
}, sub { 0.1 }
};
- my $t3 = AE::timer 0, 0.001, sub { $closeconn->() if ( $activeconn < @fh ) };
+ my $t3 = AE::timer 0, 0.0001, sub { $closeconn->() if ( $activeconn < @fh ) };
$cv->recv;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment