-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark2.pl
executable file
·134 lines (101 loc) · 3.64 KB
/
benchmark2.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
126
127
128
129
130
131
132
133
134
#!/usr/bin/perl -Ilib
use strict;
use warnings;
use threads;
use threads::shared;
use File::Basename;
use Time::HiRes qw(usleep);
use List::Util qw(sum min max);
use Statistics::Descriptive;
use ContainerScale::Aux qw(:DEFAULT);
my $HOST_IP="172.17.0.1";
my $MAX_INSTANCES=50;
my $INCREMENT=1;
my $CLIENT_THREADS=25;
my $THINK_TIME=150;
my $REPETITIONS=1;
$SIG{INT} = \&signal_handler;
$SIG{TERM} = \&signal_handler;
sub signal_handler {
die "benchmark terminates due to signal $!";
}
my @files :shared = map(basename($_), glob('noise/httpd/images/*.jpg'));
my $running :shared;
my @ports :shared;
print STDERR "Starting workload\n";
for (my $num_instances=1; $num_instances<=$MAX_INSTANCES; $num_instances+=$INCREMENT)
{
my $WEB_PORT=create_acmeair_instance($HOST_IP, $num_instances);
push @ports, $WEB_PORT;
# initialize the database
my $res;
do {
sleep 2;
$res = `curl -s http://$HOST_IP:$WEB_PORT/rest/api/loader/load?numCustomers=10000`;
print STDERR "$res\n";
} until ($res =~ /Database Finished Loading/ || $res =~/Already loaded/);
sleep 2;
#print "http://9.3.45.218:$WEB_PORT/flights.html\n";
print STDERR "Workload started\n";
# make one run to warm system up
system("docker run --rm -i -t -e APP_PORT_9080_TCP_ADDR=$HOST_IP -e APP_PORT_9080_TCP_PORT=$WEB_PORT -e LOOP_COUNT=100 -e NUM_THREAD=$CLIENT_THREADS --name acmeair_workload acmeair/workload >&2 2>/dev/null");
# benchmark loop
my $i=0;
my @threads;
print STDERR "Starting noise clients\n";
$running=1;
for (my $num = 1; $num <= $num_instances; $num++) {
push @threads, threads->create(sub {
my $PORT = $ports[$num-1];
# run the workload client for measurement
my $requests;
my $time;
my $throughput;
my $avg;
my $min;
my $max;
my $perc90;
my $perc95;
my $perc99;
my $err=1;
open my $pipe, "docker run -i -t -e APP_PORT_9080_TCP_ADDR=$HOST_IP -e APP_PORT_9080_TCP_PORT=$PORT -e LOOP_COUNT=200 -e NUM_THREAD=$CLIENT_THREADS --name acmeair_workload$num acmeair/workload |";
while (my $line = <$pipe>) {
chomp ($line);
print STDERR "$line\n";
if ($line =~ /^summary =\s*(\d+) in\s*(\d*\.?\d+)s =\s*(\d*\.?\d+)\/s Avg:\s*(\d+) Min:\s*(\d+) Max:\s*(\d+) Err:\s*(\d+).*$/) {
$requests=$1;
$time=$2;
$throughput=$3;
$avg=$4;
$min=$5;
$max=$6;
$err=$7;
}
}
if ($err > 0) {
die "MEASUREMENT INVALID, WORKLOAD ENCOUNTERED $err ERRORS\n";
}
# fetch data file
system("docker cp acmeair_workload$num:/var/workload/acmeair-nodejs/logs/AcmeAir1.jtl AcmeAir$num.jtl");
system("docker rm acmeair_workload$num 2>/dev/null");
$perc90 = percentile("AcmeAir$num.jtl", 90);
$perc95 = percentile("AcmeAir$num.jtl", 95);
$perc99 = percentile("AcmeAir$num.jtl", 99);
system("rm -f AcmeAir$num.jtl");
print "$num\t$throughput\t$avg\t$min\t$max\t$perc90\t$perc95\t$perc99\n";
print STDERR "client thread exits\n";
});
}
# let all threads join
foreach my $thread (@threads) {
$thread->join();
}
# print newline to make a new group in GNUplot...
print STDERR "\n";
}
END {
print STDERR "Starting cleanup\n";
system("docker ps -a --filter 'name=acmeair*' --format {{.Names}} | xargs docker rm -f 2>/dev/null >&2");
system("docker ps -a --filter 'name=mongo*' --format {{.Names}} | xargs docker rm -f 2>/dev/null >&2");
print STDERR "Cleanup complete\n";
}