Last active
June 2, 2021 21:52
-
-
Save yuryu/7264293 to your computer and use it in GitHub Desktop.
ELB Warm-up tool
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!perl | |
use strict; | |
use warnings; | |
use Parallel::ForkManager; | |
use POSIX; | |
use String::Random; | |
my $c_start = 1; | |
my $c_end = 64; | |
my $interval = 10 * 60; | |
my $delta = 1.25; | |
my $user = 'ec2-user'; | |
my @hosts = ('ec2-XXX-XXX-XXX-XXX.compute-1.amazonaws.com', 'ec2-XXX-XXX-XXX-XXX.compute-1.amazonaws.com'); | |
my $nhosts = scalar @hosts; | |
my $url = 'http://ELB-ADDESS.us-east-1.elb.amazonaws.com/1m'; | |
my $nrequests = 100; | |
sub ab { | |
my ($host, $concurrency, $requests, $url) = @_; | |
my $command = "/usr/bin/ab -c $concurrency -n $requests $url"; | |
print "EXEC[$host] $command\n"; | |
system("ssh", "$user\@$host", $command); | |
} | |
my $pm = new Parallel::ForkManager($nhosts); | |
our @pids; | |
$SIG{TERM} = $SIG{INT} = sub { | |
kill 'TERM', @pids; | |
$pm->wait_all_children; | |
}; | |
foreach my $host (@hosts) { | |
my $pid = $pm->start; | |
if($pid) { | |
# parent | |
unshift @pids, $pid; | |
next; | |
} | |
# child | |
$SIG{TERM} = $SIG{INT} = sub { $pm->finish }; | |
my $start = time; | |
my $c = $c_start; | |
srand(time ^ ($$ + ($$ << 15))); | |
my $rs = new String::Random; | |
while(1) { | |
if(time - $start > $interval) { | |
$c = ceil($c * $delta); | |
$c = $c_end if $c > $c_end; | |
$start = time; | |
} | |
ab($host, $c, $nrequests, $url . "?" . $rs->randregex('[a-zA-Z0-9]{16}')); | |
} | |
$pm->finish; | |
} | |
$pm->wait_all_children; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1m っていうのは 1MB のダミーファイルです。