| 1 |
root |
1.1 |
# $Id: tcp-poe-raw.pl,v 1.1 2009/01/17 11:29:06 dk Exp $ |
| 2 |
|
|
# An echo client-server benchmark. |
| 3 |
|
|
|
| 4 |
|
|
use warnings; |
| 5 |
|
|
use strict; |
| 6 |
|
|
|
| 7 |
|
|
use Time::HiRes qw(time); |
| 8 |
|
|
use AnyEvent; |
| 9 |
|
|
use AnyEvent::Impl::Perl; |
| 10 |
|
|
use AnyEvent::Socket; |
| 11 |
|
|
|
| 12 |
|
|
my $CYCLES = 500; |
| 13 |
|
|
my $port = 11212; |
| 14 |
|
|
|
| 15 |
|
|
tcp_server undef, $port, sub { |
| 16 |
|
|
my ($fh) = @_ |
| 17 |
|
|
or die "tcp_server: $!"; |
| 18 |
|
|
|
| 19 |
|
|
my $hdl = new AnyEvent::Handle fh => $fh; |
| 20 |
|
|
|
| 21 |
|
|
$hdl->push_read (line => sub { |
| 22 |
|
|
$hdl->push_write ("$_[1]\n"); |
| 23 |
|
|
undef $hdl; |
| 24 |
|
|
}); |
| 25 |
|
|
}; |
| 26 |
|
|
|
| 27 |
|
|
my $t = time; |
| 28 |
|
|
|
| 29 |
|
|
for my $connections (1..$CYCLES) { |
| 30 |
|
|
my $cv = AnyEvent->condvar; |
| 31 |
|
|
|
| 32 |
|
|
tcp_connect "127.0.0.1", $port, sub { |
| 33 |
|
|
my ($fh) = @_ |
| 34 |
|
|
or die "tcp_connect: $!"; |
| 35 |
|
|
|
| 36 |
|
|
my $hdl = new AnyEvent::Handle fh => $fh; |
| 37 |
|
|
|
| 38 |
|
|
$hdl->push_write ("can write $connections\n"); |
| 39 |
|
|
$hdl->push_read (line => sub { |
| 40 |
|
|
undef $hdl; |
| 41 |
|
|
$cv->send; |
| 42 |
|
|
}); |
| 43 |
|
|
}; |
| 44 |
|
|
|
| 45 |
|
|
$cv->recv; |
| 46 |
|
|
}; |
| 47 |
|
|
|
| 48 |
|
|
$t = time - $t; |
| 49 |
|
|
printf "%.3f sec\n", $t; |
| 50 |
|
|
exit; |