Happy Coding
使用 redis-benchmark 压测自建的 kv 存储引擎

给自建 kv 存储引擎做性能测试不难,使用 redis-benchmark 压测的目的是,测试结果能与 redis-server 的结果做横向对比。

redis-benchmark

redis-benchmark 支持如下指令的 benchmark。其中 GET/SET 指令可用于 kv 存储引擎的压测。

redis-benchmark -q
PING_INLINE: 102669.41 requests per second, p50=0.247 msec
PING_MBULK: 102880.66 requests per second, p50=0.231 msec
SET: 101936.80 requests per second, p50=0.239 msec
GET: 101626.02 requests per second, p50=0.239 msec
INCR: 102249.49 requests per second, p50=0.239 msec
LPUSH: 100603.62 requests per second, p50=0.255 msec
RPUSH: 101626.02 requests per second, p50=0.255 msec
LPOP: 102354.15 requests per second, p50=0.255 msec
RPOP: 102249.49 requests per second, p50=0.255 msec
SADD: 101522.84 requests per second, p50=0.247 msec
HSET: 100603.62 requests per second, p50=0.255 msec
SPOP: 102249.49 requests per second, p50=0.247 msec
ZADD: 102564.10 requests per second, p50=0.255 msec
ZPOPMIN: 103412.62 requests per second, p50=0.247 msec
LPUSH (needed to benchmark LRANGE): 94607.38 requests per second, p50=0.263 msec
LRANGE_100 (first 100 elements): 27964.21 requests per second, p50=0.855 msec
LRANGE_300 (first 300 elements): 11193.19 requests per second, p50=2.135 msec
LRANGE_500 (first 450 elements): 7649.94 requests per second, p50=3.159 msec
LRANGE_600 (first 600 elements): 5884.78 requests per second, p50=4.103 msec
MSET (10 keys): 93283.58 requests per second, p50=0.423 msec

redcon

Redis compatible server framework for Go.

tidwall/redcon

这个库兼容了 redis-server 的协议。个人要做的是封装下对存储引擎的调用。

只要兼容了服务端协议,就可以使用 redis-benchmark, redis-cli 等工具去连接了。

测试结果

redis-server

$ redis-benchmark -t set,get --csv
"test","rps","avg_latency_ms","min_latency_ms","p50_latency_ms","p95_latency_ms","p99_latency_ms","max_latency_ms"
"SET","82850.04","0.322","0.144","0.295","0.455","0.655","1.999"
"GET","82236.84","0.321","0.160","0.295","0.495","0.655","2.007"

go hashmap

内置的 map。

$ redis-benchmark -t set,get --csv
"test","rps","avg_latency_ms","min_latency_ms","p50_latency_ms","p95_latency_ms","p99_latency_ms","max_latency_ms"
"SET","73421.44","0.356","0.144","0.311","0.535","1.111","2.511"
"GET","79681.27","0.329","0.152","0.303","0.463","0.575","0.935"

goleveldb

syndtr/goleveldb

$ redis-benchmark -t set,get --csv
"test","rps","avg_latency_ms","min_latency_ms","p50_latency_ms","p95_latency_ms","p99_latency_ms","max_latency_ms"
"SET","57636.89","0.475","0.096","0.439","0.679","1.007","3.687"
"GET","79302.14","0.333","0.152","0.303","0.471","0.687",”2.711"

bitcask(自制土炮版)

性能差了一大截。

$ redis-benchmark -t set,get --csv
"test","rps","avg_latency_ms","min_latency_ms","p50_latency_ms","p95_latency_ms","p99_latency_ms","max_latency_ms"
"SET","44662.79","1.033","0.040","1.167","1.535","2.367","36.095"
"GET","52137.64","0.523","0.088","0.503","0.687","1.199","6.327"

可视化对比 p99_latency_ms 这个指标:

总结

使用 redis-benchmark 作为性能测试框架。在相同的测试用例下,通过对照比较其他存储引擎的测试结果,了解自己需要进步的空间。


Last modified on 2021-04-19