Debian Codegraph @

t/bench/http

raw
1 #!/usr/bin/perl
2 # Test configuration: IP, 1/100 simultaneous connections
3 # WHAT THREADS SPEED CPU:
4 # IO::Stream 1 2600/sec 60%
5 # IO::Stream 100 3100/sec 72%
6 # POWER::Event::IO 1 2300/sec 70%
7 # POWER::Event::IO 100 2900/sec 75%
8 use warnings;
9 use strict;
10
11 use Socket;
12 use Data::Dumper;
13
14 use blib;
15 use EV;
16 use IO::Stream;
17
18 use Carp::Heavy;
19 $SIG{PIPE} = 'IGNORE';
20 $EV::DIED = \&EV::unloop;
21
22 warn "Testing IO::Stream-$IO::Stream::VERSION\n";
23
24 sub new_http {
25 IO::Stream->new({
26 host => '127.0.0.1',
27 # host => 'localhost',
28 port => $ARGV[0] || 80,
29 cb => \&http,
30 wait_for => EOF,
31 out_buf => "GET http://127.0.0.1/ HTTP/1.0\r\nHost: 127.0.0.1\r\n\r\n",
32 in_buf_limit=> 1024000,
33 })
34 };
35 new_http() for 1 .. 100;
36
37 my $RUNS = 0;
38 my $alarm = 15;
39
40 my $t = EV::timer $alarm, 0, sub {
41 warn sprintf "RUNS=%d (%d/sec)\n", $RUNS, $RUNS/$alarm;
42 EV::unloop;
43 };
44 EV::loop;
45 die "out of loop(): $@\n";
46
47 sub http {
48 my ($io, $e, $err) = @_;
49 die "err=$err\n" if $e != EOF;
50 # warn "length = ".length($io->{in_buf})." bytes = $io->{in_bytes}\n";
51 # warn $io->{in_buf}; exit;
52 warn "bad length: $io->{in_bytes}\n"
53 if $io->{in_bytes} != 314;
54 $io->close();
55 new_http();
56 $RUNS++;
57 }
58