Skip to content

Instantly share code, notes, and snippets.

/minion_bench.pl Secret

Created February 16, 2016 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5e228d27b88a94d915ea to your computer and use it in GitHub Desktop.
Save anonymous/5e228d27b88a94d915ea to your computer and use it in GitHub Desktop.
use Mojo::Base -strict;
use Minion;
use Time::HiRes 'time';
my $minion = Minion->new(Pg => 'postgresql://tester:testing@/test');
$minion->add_task(foo => sub { }, bar => sub { });
my $ENQUEUE = 10000;
my $DEQUEUE = 2000;
my $WORKERS = 4;
my $STATS = 500;
my $REPAIR = 50;
$minion->reset;
say "Clean start with $ENQUEUE jobs";
my $before = time;
$minion->enqueue('foo') for 1 .. $ENQUEUE;
my $elapsed = time - $before;
my $avg = sprintf '%.3f', $ENQUEUE / $elapsed;
say "Enqueued $ENQUEUE jobs in $elapsed seconds ($avg/s)";
my @pids;
for (1 .. $WORKERS) {
die "Couldn't fork: $!" unless defined(my $pid = fork);
unless ($pid) {
my $worker = $minion->worker->register;
say "$$ will dequeue $DEQUEUE jobs";
$before = time;
$worker->dequeue(0.5) for 1 .. $DEQUEUE;
$elapsed = time - $before;
$avg = sprintf '%.3f', $DEQUEUE / $elapsed;
say "$$ dequeued $DEQUEUE jobs in $elapsed seconds ($avg/s)";
$worker->unregister;
exit;
}
push @pids, $pid;
}
say "$$ has started $WORKERS workers";
$before = time;
waitpid $_, 0 for @pids;
$elapsed = time - $before;
$avg = sprintf '%.3f', ($DEQUEUE * $WORKERS) / $elapsed;
say "$WORKERS workers dequeued $DEQUEUE jobs each in $elapsed seconds ($avg/s)";
say "Requesting stats $STATS times";
$before = time;
$minion->stats for 1 .. $STATS;
$elapsed = time - $before;
$avg = sprintf '%.3f', $STATS / $elapsed;
say "Received stats $STATS times in $elapsed seconds ($avg/s)";
say "Repairing $REPAIR times";
$before = time;
$minion->repair for 1 .. $REPAIR;
$elapsed = time - $before;
$avg = sprintf '%.3f', $REPAIR / $elapsed;
say "Repaired $REPAIR times in $elapsed seconds ($avg/s)";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment