Created
June 22, 2014 05:41
-
-
Save mattsta/f597c1dbc781839d2d5c to your computer and use it in GitHub Desktop.
Quick Redis speed comparison script
This file contains 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
#!/usr/bin/perl | |
use warnings; | |
use strict; | |
use IO::All; | |
use IO::Socket::UNIX qw( SOCK_STREAM ); | |
use Benchmark ':hireswallclock'; | |
use Redis; | |
use RedisDB; | |
use Redis::Fast; | |
use Cache::Memcached::Fast; | |
# Lazy copy/paste create independent connections | |
my $rsocka = IO::Socket::UNIX->new(Type => SOCK_STREAM, Peer => "/tmp/redis.sock"); | |
my $rsockb = IO::Socket::UNIX->new(Type => SOCK_STREAM, Peer => "/tmp/redis.sock"); | |
my $rsockc = IO::Socket::UNIX->new(Type => SOCK_STREAM, Peer => "/tmp/redis.sock"); | |
my $rsockd = IO::Socket::UNIX->new(Type => SOCK_STREAM, Peer => "/tmp/redis.sock"); | |
my $rsocke = IO::Socket::UNIX->new(Type => SOCK_STREAM, Peer => "/tmp/redis.sock"); | |
my $rsockf = IO::Socket::UNIX->new(Type => SOCK_STREAM, Peer => "/tmp/redis.sock"); | |
my $mca = IO::Socket::UNIX->new(Type => SOCK_STREAM, Peer => "/tmp/memcached.sock"); | |
my $mcb = IO::Socket::UNIX->new(Type => SOCK_STREAM, Peer => "/tmp/memcached.sock"); | |
my $mcc = IO::Socket::UNIX->new(Type => SOCK_STREAM, Peer => "/tmp/memcached.sock"); | |
my $mcd = IO::Socket::UNIX->new(Type => SOCK_STREAM, Peer => "/tmp/memcached.sock"); | |
my $redisdb = RedisDB->new(path => "/tmp/redis.sock"); | |
my $redismod = Redis->new(sock => "/tmp/redis.sock"); | |
my $redis = Redis::Fast->new(sock => '/tmp/redis.sock', encoding => undef); | |
$redis->set('foo', 'bar'); | |
my $words = io("/usr/share/dict/words")->slurp; | |
$redis->set('larger', $words); | |
my $memcache = Cache::Memcached::Fast->new({ | |
servers => [ '/tmp/memcached.sock' ], | |
utf8 => 0, | |
nowait => 0, | |
max_size => 4096 * 4096 | |
}); | |
$memcache->set('foo', 'bar'); | |
$memcache->set('larger', $words); | |
my $i = 0; | |
print "Large Benchmarks\n"; | |
my $result = Benchmark::timethese(4_000, { | |
'Redis-Raw-Inline' => sub { print $rsockb "GET larger\r\n"; $rsockb->read($_, substr($rsockb->getline, 1)+2); $rsockb->flush; }, | |
'Redis-Raw-Bulk' => sub { print $rsockc "*2\r\n\$3\r\nGET\n\n\$6\r\nlarger\r\n"; $rsockc->read($_, substr($rsockc->getline, 1)+2); $rsockc->flush; }, | |
'Redis' => sub { $redis->get('larger'); }, | |
'RedisDB' => sub { $redisdb->get('larger'); }, | |
'RedisMod' => sub { $redismod->get('larger'); }, | |
'Memcache' => sub { $memcache->get('larger'); }, | |
'Memcache-Raw' => sub { $mca->flush; print $mca "get larger\r\n"; my @parts = split /\s/, $mca->getline; $mca->read($_, $parts[3]+2); $mca->getline; } | |
}); | |
print "Results:\n"; | |
Benchmark::cmpthese $result; | |
print "\n\n"; | |
print "Small Benchmarks\n"; | |
$result = Benchmark::timethese(1_000_000, { | |
'Redis-Raw-Bulk' => sub { $rsockf->flush; print $rsocke "*2\r\n\$3\r\nGET\n\n\$3\r\nfoo\r\n"; $rsocke->getline; $rsocke->getline; }, | |
'Redis-Raw-Inline' => sub { $rsockf->flush; print $rsockf "GET foo\r\n"; $rsockf->getline; $rsockf->getline; }, | |
'RedisDB' => sub { $redisdb->get('foo'); }, | |
'RedisMod' => sub { $redismod->get('foo'); }, | |
'Redis' => sub { $redis->get('foo'); }, | |
'Redis-DNE' => sub { $redis->get('bar'); }, | |
'Memcached' => sub { $memcache->get('foo'); }, | |
'Memcached-DNE' => sub { $memcache->get('bar'); }, | |
'Memcache-Raw' => sub { print $mcb "get foo\r\n"; $mcb->getline; $mcb->getline; $mcb->getline; }, | |
}); | |
print "Result:\n"; | |
Benchmark::cmpthese $result; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results on my laptop: