/
tapout_script
executable file
·75 lines (57 loc) · 1.45 KB
/
tapout_script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/perl
use strict;
use warnings;
use IO::Poll;
use POE qw( Component::Client::Keepalive Component::Client::HTTP );
use HTTP::Request;
my $url = "http://localhost/";
POE::Session->create (
inline_states => {
_start => \&start,
process => \&process,
response => \&response,
halt => \&halt,
},
);
POE::Kernel->run();
sub start {
my ($kernel,$heap) = @_[KERNEL,HEAP];
print "Starting\n";
$kernel->alias_set('master');
foreach (1..512) {
my $useragent = "ua_$_";
POE::Component::Client::HTTP->spawn (
Alias => $useragent,
Timeout => 30,
Agent => "Test",
);
$kernel->yield('process',$useragent);
}
$kernel->delay(halt=>30);
}
sub process {
my ($kernel,$heap,$useragent) = @_[KERNEL,HEAP,ARG0];
my $uri = HTTP::Request->new(GET => $url);
$kernel->post($useragent,'request','response',$uri,$useragent);
return;
}
sub response {
my ($kernel,$heap,$request_packet,$response_packet) = @_[KERNEL,HEAP,ARG0,ARG1];
my $request = $request_packet->[0];
my $response = $response_packet->[0];
my $useragent = $request_packet->[1]; ## this is passed with the request call
if ($response->is_success()) {
$heap->{responses}++;
} else {
$heap->{unsuccessful}++;
}
$kernel->yield('process', $useragent);
return;
}
sub halt {
my ($kernel,$heap) = @_[KERNEL,HEAP];
print "debug success($heap->{responses}) unsuccessful($heap->{unsuccessful}) ... " . $kernel->poe_kernel_loop() . "\n";
exit;
return;
}
1;