-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoadTest.pl
60 lines (47 loc) · 1.49 KB
/
LoadTest.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
#!/usr/bin/env perl
use feature "say";
use LWP::UserAgent;
use JSON::XS;
use Data::Dumper;
use Thread::Pool::Simple;
use Getopt::Long;
my $coder = JSON::XS->new->ascii->pretty->allow_nonref;
our $mwurl;
sub run2 {
my $revid = shift;
my $lwp = LWP::UserAgent->new();
$lwp->proxy('http', 'http://squid-proxy.local:3128/');
my $apiurl = 'http://' . $mwurl . '/api.php?action=query&format=xml&revids=' . $revid . '&maxlag=5&cllimit=max&prop=categories%7Cinfo%7Crevisions&rvprop=comment%7Ccontent%7Cflags%7Cids%7Ctimestamp%7Cuser';
say "Calling API for url: ".$apiurl;
my $jsonResp = $lwp->request( HTTP::Request->new( 'GET', $apiurl ) );
}
sub run {
say "Run!";
my $pool = Thread::Pool::Simple->new(
min => 2,
max => 4,
load => 4,
do => [ sub {
run2( shift );
} ]
);
my $lwp = LWP::UserAgent->new();
$lwp->proxy('http', 'http://squid-proxy.local:3128/');
my $apiurl = 'http://' . $mwurl . '/api.php?action=query&format=json&list=recentchanges&rclimit=500&rcnamespace=0%7C2%7C4%7C6%7C10%7C14&rcprop=comment%7Cflags%7Cids%7Cloginfo%7Csizes%7Ctimestamp%7Ctitle%7Cuser';
while ( true ) {
say "Calling API for url: ".$apiurl;
my $jsonResp = $lwp->request( HTTP::Request->new( 'GET', $apiurl ) );
my $json = $coder->decode ( $jsonResp->content );
my $i = 0;
foreach ( @{$json->{ "query" }->{ "recentchanges" }} ) {
my $revid = $_->{ 'revid' };
$pool->add( $revid );
$i++; last if ( $i == 10 ) ;
}
sleep(30);
}
}
GetOptions(
"mwurl=s" => \( $mwurl = '' )
);
run();