Skip to content

Instantly share code, notes, and snippets.

@tmitz
Created October 4, 2013 10:29
Show Gist options
  • Select an option

  • Save tmitz/6823961 to your computer and use it in GitHub Desktop.

Select an option

Save tmitz/6823961 to your computer and use it in GitHub Desktop.
twemproxyのベンチマーク
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use v5.18.1;
use Benchmark qw/:all/;
use Cache::Memcached::Fast;
use Digest::MD5 qw/md5/;
use RedisDB;
my $memd = &connect_memd();
my $redis = &connect_redis();
my $redis_pipe = &connect_redis();
my $twem_memd = &connect_twem_memd();
my $twem_redis = &connect_twem_redis();
my $data = pack 'c', map { rand 256 } (0..4096);
my $result = timethese(100000, {
memcached => sub {
$memd->set("data" => $data);
$memd->get("data");
},
twemproxy_memd => sub {
$twem_memd->set("data" => $data);
$twem_memd->get("data");
},
redis => sub {
$redis->set('data', $data);
$redis->get('data');
},
redis_pipelining => sub {
$redis_pipe->set('data', $data, RedisDB::IGNORE_REPLY);
$redis_pipe->get('data', RedisDB::IGNORE_REPLY);
},
twemproxy_redis => sub {
$twem_redis->set('data', $data);
$twem_redis->get('data');
},
});
$redis_pipe->mainloop;
sub connect_twem_memd {
return Cache::Memcached::Fast->new({
servers => [
{address => '127.0.0.1:22121', weight => 1},
],
});
}
sub connect_memd {
return Cache::Memcached::Fast->new({
servers => [
{address => '127.0.0.1:11212', weight => 1},
{address => '127.0.0.1:11213', weight => 1},
{address => '127.0.0.1:11214', weight => 1},
{address => '127.0.0.1:11215', weight => 1},
],
namespace => 'memd:',
});
}
sub connect_twem_redis {
return RedisDB->new(host => '127.0.0.1', port => 22123);
}
sub connect_redis {
return RedisDB->new(host => '127.0.0.1', port => 6379);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment