Skip to content

Instantly share code, notes, and snippets.

/minion_bench.pl Secret

Created February 16, 2016 21:23
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/0e0399a70f68a1202a37 to your computer and use it in GitHub Desktop.
Save anonymous/0e0399a70f68a1202a37 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 { });
$minion->add_task(bar => sub { });
my $ENQUEUE = 10000;
my $DEQUEUE = 1000;
my $REPETITIONS = 2;
my $WORKERS = 4;
my $STATS = 100;
my $REPAIR = 100;
$minion->reset;
say "Clean start with $ENQUEUE jobs";
my $before = time;
$minion->enqueue($_ % 2 ? 'foo' : 'bar') for 1 .. $ENQUEUE;
my $elapsed = time - $before;
my $avg = sprintf '%.3f', $ENQUEUE / $elapsed;
say "Enqueued $ENQUEUE jobs in $elapsed seconds ($avg/s)";
sub dequeue {
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";
my $before = time;
$worker->dequeue(0.5)->finish for 1 .. $DEQUEUE;
my $elapsed = time - $before;
my $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";
my $before = time;
waitpid $_, 0 for @pids;
my $elapsed = time - $before;
my $avg = sprintf '%.3f', ($DEQUEUE * $WORKERS) / $elapsed;
say
"$WORKERS workers dequeued $DEQUEUE jobs each in $elapsed seconds ($avg/s)";
}
dequeue() for 1 .. $REPETITIONS;
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