Skip to content

Instantly share code, notes, and snippets.

@toritori0318
Created September 5, 2013 17:32
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 toritori0318/6453417 to your computer and use it in GitHub Desktop.
Save toritori0318/6453417 to your computer and use it in GitHub Desktop.
Parallel::Benchmark + RedisDB
use strict;
use warnings;
use Data::Dumper;
use Parallel::Benchmark;
use RedisDB;
use String::Random;
my $host = shift || 'localhost';
my $port = shift || '6379';
my @ports = split /,/, $port;
my $time = 30;
my $bm = Parallel::Benchmark->new(
setup => sub {
my $self = shift;
my $seq = 0;
for my $port (@ports) {
$self->stash->{redis}->[$seq] = RedisDB->new(host => $host, port => $port);
$seq++;
}
},
benchmark => sub {
my ($self, $id) = @_;
my $rand = int(rand(scalar @{$self->stash->{redis}}));
my $redis = $self->stash->{redis}->[$rand];
my $key = String::Random->new->randregex('[A-Za-z0-9]{12}');
my $value = String::Random->new->randregex('[A-Za-z0-9]{64}');
my $status = $redis->set($key, $value);
#my $status = $redis->lpush('list_key', '{"hyoro":"1234567890"}');
#$self->stash->{result}->{ success }++;
1;
},
teardown => sub {
my $self = shift;
delete $self->stash->{redis};
},
time => $time,
);
for my $c ( 16, 32, 48, 54 ) {
$bm->concurrency($c);
my $result = $bm->run();
#print Dumper $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment