Redis Pipeline
目次
What's Redis Pipeline?
redis-benchmark 実行時, Pipeline を使用すると QPS が劇的に上がります.
Python でアプリケーションを書くとしまして, 以下のコードで Pipeline が作成できます.
pipe = conn.pipeline()
pipeline メソッドに True を渡すと, コマンドシーケンスを MULTI / EXEC で包み込めという意味になります.
pipeline メソッドに False を渡すと, コマンドシーケンスは MULTI / EXEC で包み込まれなくなり, よりパフォーマンスが上がります.
MULTI / EXEC でコマンドシーケンスを包み込む = トランザクション, と理解して構わないと思います.
なお, 引数を省略すると True を渡したのと同じ意味になります.
Environment
Amazon Linux AMI 2013.09.2 - ami-0d13700c (64-bit)
Redis Server
- m2.4xlarge
Redis Client
- m1.small
Benckmark
$ redis-benchmark -h 'Redis Server' -c 1000 -n 200000 -t set,get -P 16 -q
- Pipeline なし
$ redis-benchmark -h 'Redis Server' -t set,get -q SET: 15772.87 requests per second GET: 15822.78 requests per second
- Pipeline 8
$ redis-benchmark -h 'Redis Server' -t set,get -P 8 -q SET: 138888.89 requests per second GET: 142857.14 requests per second
Pipeline なしの 8.8 倍
- Pipeline 16
$ redis-benchmark -h 'Redis Server' -t set,get -P 16 -q SET: 250000.00 requests per second GET: 153846.16 requests per second
Pipeline なしの 15.8 倍
- Pipeline 32
$ redis-benchmark -h 'Redis Server' -t set,get -P 32 -q SET: 270270.28 requests per second GET: 322580.66 requests per second
Pipeline なしの 17.1 倍
- Pipeline 256
$ redis-benchmark -h 'Redis Server' -t set,get -P 256 -q SET: 212765.97 requests per second GET: 277777.78 requests per second
Pipeline なしの 13.4 倍
リニアにスケールする限界点があるようですね.