forked from Klomgor/online
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-ha.pl
executable file
·123 lines (104 loc) · 2.8 KB
/
test-ha.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
#!/usr/bin/perl -w
# -*- tab-width: 4; indent-tabs-mode: nil -*-
#
# Copyright the Collabora Online contributors.
#
# SPDX-License-Identifier: MPL-2.0
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
use strict;
use Time::HiRes qw( time );
my $uri = shift @ARGV || die 'pass in URI of server or file to fetch';
my $tmp = '/tmp/downloaded';
my %hitcount;
my %slowcount;
my %timecount;
# Try to detect bad WOPI hosts by bucketing latency.
sub testWOPIServer()
{
for (my $i = 0; $i < 50; $i++)
{
unlink $tmp;
my $begin_time = time();
my $pipe;
open ($pipe, "curl --insecure --stderr - -i -v -m 300 -o $tmp $uri |") || die "Can't launch curl";
my $node = 'unknown';
my $size = 0;
while (<$pipe>) {
my $line = $_;
$line =~ m/^< Set-Cookie:/ || next;
if ($line =~ m/BIGipServerIP[^=]+=([0-9\.]+);/) {
$node = $1;
}
if ($line =~ m/Content-Length: ([0-9]+)/) {
$size = $1;
}
}
close ($pipe);
my $end_time = time();
my $time_taken = $end_time - $begin_time;
if (!defined $slowcount{$node}) {
$hitcount{$node} = 0;
$slowcount{$node} = 0;
$timecount{$node} = 0.0;
}
$hitcount{$node}++;
$timecount{$node} += $time_taken;
my $slow = '';
if ($time_taken > 1.0) {
$slow = ' slow';
$slowcount{$node}++;
}
printf("%.2fs from $node size: $size $slow\n", $time_taken);
}
print "hits\t#slow\ttotal\tNode\n";
for my $node (keys %slowcount) {
printf ("%s\t%s\t%.2fs\t%s\n", $hitcount{$node}, $slowcount{$node}, $timecount{$node}, $node);
}
}
sub randstr()
{
my @hex = ('0' ..'9', 'A' .. 'F');
return join '' => map $hex[rand @hex], 1 .. 8;
}
sub testCoolCluster()
{
my @ids;
my %serverId_by_src;
my $i;
my $size = 0;
my $iters = 50; # number of checks
my $tests = 10; # number of src strings
my $uri_base = "$uri/hosting/capabilities?WOPISrc=";
for ($i = 0; $i < $tests; $i++) {
push(@ids,randstr());
}
printf("Touching $uri_base $iters times\n");
for ($i = 0; $i < $iters; $i++)
{
my $pipe;
my $src = $ids[rand(@ids)];
my $id = 0;
open ($pipe, "curl --insecure -m 500 -s $uri_base$src |") || die "Can't launch curl";
while (<$pipe>) {
my $line = $_;
# printf ("$line\n");
if ($line =~ m/\"serverId\":\"([^"]+)\"/) {
$id = $1;
}
}
close ($pipe);
# printf("id: $id\n");
$serverId_by_src{$src} = $id if (!defined $serverId_by_src{$src});
if ($serverId_by_src{$src} ne $id)
{
die("ERROR: ID mismatch for $id vs. $serverId_by_src{$src} for WOPISrc '$src'\n");
}
}
print ("WOPISrc check with $iters iterations and $tests keys passed cleanly.\n");
}
testCoolCluster();
# vim: set shiftwidth=4 softtabstop=4 expandtab: