forked from Netflix-Skunkworks/spectatord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
udp_numbers.pl
110 lines (88 loc) · 2.48 KB
/
udp_numbers.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
#!/usr/bin/perl
#
use warnings;
use v5.16.0;
use List::Util qw/sum/;
die "Need to be root to set kernel max recv buffer size" unless $> == 0;
$SIG{CHLD} = 'IGNORE';
my $result_file_name = shift or die "Usage: sudo $0 <output>";
open my $ofh, '>', $result_file_name or die "$result_file_name: $!";
my @buffers = get_buf_sizes();
# just use one port for now - focus on how rps affects packet drops
my @rps = qw/300000 400000 500000/;
for my $buf (@buffers) {
for my $rps (@rps) {
test_udp( $buf, $rps );
}
}
close $ofh;
sub test_udp {
my ( $buf, $rps ) = @_;
set_rmem_max($buf);
my $pid = fork();
if ( $pid == 0 ) { # child
exec("./bazel-bin/spectatord_main");
}
elsif ( $pid > 0 ) {
my @dropped;
my $prev_dropped = 0;
for ( 1 .. 4 ) {
system("./bazel-bin/metrics_gen -u -r $rps");
# get number of dropped packets
my $sum_dropped = get_dropped();
my $dropped = $sum_dropped - $prev_dropped;
$prev_dropped = $sum_dropped;
say STDERR
"Run #$_ for [$rps, $buf] = $dropped";
push @dropped, $dropped;
sleep 1;
}
# get the average for the runs
my $dropped = avg(@dropped);
say STDERR "Avg for [$rps, $buf] = $dropped (@dropped)";
say $ofh "UDP,$rps,$buf,$dropped";
kill 'KILL' => $pid;
sleep(5);
unlink '/run/spectatord/spectatord.unix';
}
}
sub get_buf_sizes {
my @mb = qw/16 128/;
return map { $_ * 1024 * 1024 } @mb;
}
sub get_dropped {
open my $fh, '<', '/proc/net/udp';
chomp( my @lines = <$fh> );
close $fh;
shift @lines;
my $dropped = 0;
for my $line (@lines) {
$line =~ s/^\s+//;
my @fields = split /[\s:]+/, $line;
my $port = hex( $fields[2] );
next if $port < 1234 || $port > 1250;
$dropped += $fields[-1];
}
$dropped;
}
sub avg {
if ( @_ > 0 ) {
sum(@_) / @_;
}
else {
0;
}
}
sub set_rmem_max {
my $bufsiz = shift;
my $file_name = '/proc/sys/net/core/rmem_max';
say STDERR "Setting rmem_max=$bufsiz";
open my $proc_fh, '>', $file_name or die "$file_name: $!";
print $proc_fh $bufsiz;
close $proc_fh;
# ensure we get the right bufsiz
open $proc_fh, '<', $file_name or die "$file_name: $!";
chomp( my $line = <$proc_fh> );
close $proc_fh;
die "$line != $bufsiz" unless $line == $bufsiz;
}