forked from cloudbase/EHS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ehs-chunktest.pl
executable file
·125 lines (87 loc) · 2.45 KB
/
ehs-chunktest.pl
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/perl
#
# ehs-stress.pl was written by Michal Pleban
#
use LWP::UserAgent;
use HTTP::Request;
if ( @ARGV < 1 ) {
PrintHelp ( );
exit;
}
my %UserAgentOptions;
$SERVER = shift @ARGV;
$PROCESSES = 10;
$HITS = 10;
while ( my $arg = shift @ARGV ) {
if ( $arg eq "-p" ) {
PrintHelp ( ) and exit if @ARGV == 0;
$PROCESSES = shift @ARGV;
} elsif ( $arg eq "-c" ) {
PrintHelp ( ) and exit if @ARGV == 0;
$HITS = shift @ARGV;
} elsif ( $arg eq "-k" ) {
$UserAgentOptions { keep_alive } = 1;
}
}
print "Starting $0 against $SERVER with $PROCESSES processes each performing $HITS queries\n";
$start_time = time;
my $chunk_count = 20;
my $excpected = "";
sub chunk {
if ($chunk_count) {
$chunk_count--;
my $ret = "foo bar baz daz faz blaz ";
$expected .= $ret;
return $ret;
}
$chunk_count = 20;
return "";
}
for($i = 0; $i < $PROCESSES; $i++)
{
print "Starting process " . ($i + 1) . "\n";
if(!($kidpid = fork()))
{
$ua = LWP::UserAgent->new ( %UserAgentOptions );
$ua->agent("ehs-stress_" . $kidpid);
$failed = 0;
$requestsperformed = 0;
for($j = 0; $j < $HITS || $HITS == -1; $j++)
{
$l = int rand 16384;
print "Sending request " . ($j + 1) . " from process $i\n" if ($j + 1) % 100 == 0;
$r = HTTP::Request->new("POST", "http://" . $SERVER . "/");
$r->content(\&chunk);
$expected = "";
$response = $ua->request($r);
$failed = 1 and last if !($response->header('Date') || ($response->content eq $expected));
$requestsperformed++;
}
`echo $requestsperformed >/tmp/$$`;
exit ( $failed );
} else {
$kids{$kidpid}++;
}
}
$totalrequests = 0;
for($i = 0; $i < $PROCESSES; $i++)
{
$Pid = wait();
if ( $? == 0 ) {
printf "PID $Pid exited successfully\n";
} else {
printf "PID $Pid failed\n";
}
# load number of requests from /tmp
$totalrequests += `cat /tmp/$Pid`;
`rm /tmp/$Pid`;
}
print "performed $totalrequests total requests\n";
$end_time = time;
$total_time = $end_time - $start_time;
$avg_time = $totalrequests != 0 ? $total_time / $totalrequests : 0;
print "It took $total_time seconds to run $totalrequests queries for an avg o $avg_time second / request\n";
sub PrintHelp
{
print "Usage: $0 <hostname>:<port> [-p <processes>] [-c <requests>] [-k]\n\t-p: number of processes to spawn (default 10)\n\t-c: request count per process (default 10)\n\t-k: if specified, persistent connections are used\n";
}