1 回答

TA貢獻1797條經驗 獲得超6個贊
我們下面將比較原生啟動 redis 實例和使用Docker啟動的性能對比。
測試機器:
24 CPUS,48G內存的dell 420 物理服務器
其中redis的配置文件如下:
daemonize yes
port 6379
1、宿主機直接啟動redis實例:
啟動命令:
redis-server /etc/redis.conf
性能測試命令:
redis-benchmark -h 127.0.0.1 -p 6379 -q -d 100
結果如下:
PING_INLINE: 70224.72 requests per second
PING_BULK: 97276.27 requests per second
SET: 99403.58 requests per second
GET: 99403.58 requests per second
INCR: 100603.62 requests per second
LPUSH: 98425.20 requests per second
LPOP: 98425.20 requests per second
SADD: 100502.52 requests per second
SPOP: 100401.61 requests per second
LPUSH (needed to benchmark LRANGE): 99700.90 requests per second
LRANGE_100 (first 100 elements): 40733.20 requests per second
LRANGE_300 (first 300 elements): 14907.57 requests per second
LRANGE_500 (first 450 elements): 5781.68 requests per second
LRANGE_600 (first 600 elements): 3832.59 requests per second
MSET (10 keys): 63816.21 requests per second
2、利用taskset綁定一個CPU,在宿主機上啟動redis(這也是業(yè)界優(yōu)化redis的一個偏方):
啟動命令:
taskset -c 02 redis-server /etc/redis.conf
性能測試命令:
redis-benchmark -h 127.0.0.1 -p 6379 -q -d 100
結果如下:
PING_INLINE: 73746.31 requests per second
PING_BULK: 99601.60 requests per second
SET: 99700.90 requests per second
GET: 100200.40 requests per second
INCR: 100000.00 requests per second
LPUSH: 99403.58 requests per second
LPOP: 99108.03 requests per second
SADD: 101317.12 requests per second
SPOP: 100502.52 requests per second
LPUSH (needed to benchmark LRANGE): 99304.87 requests per second
LRANGE_100 (first 100 elements): 40883.07 requests per second
LRANGE_300 (first 300 elements): 15015.02 requests per second
LRANGE_500 (first 450 elements): 5262.05 requests per second
LRANGE_600 (first 600 elements): 3892.87 requests per second
MSET (10 keys): 52938.06 requests per second
3、利用Docker的Nat網(wǎng)絡模式啟動redis(我們之前介紹的方式):
啟動命令:
docker run -v /usr/local/redis.conf:/etc/redis.conf -p 6379:6379 --name myredis -d redis:2.8.19
性能測試命令:
redis-benchmark -h 127.0.0.1 -p 6379 -q -d 100
結果如下:
PING_INLINE: 40983.61 requests per second
PING_BULK: 50276.52 requests per second
SET: 49776.01 requests per second
GET: 46533.27 requests per second
INCR: 48309.18 requests per second
LPUSH: 54406.96 requests per second
LPOP: 56369.79 requests per second
SADD: 36153.29 requests per second
SPOP: 44130.62 requests per second
LPUSH (needed to benchmark LRANGE): 49726.51 requests per second
LRANGE_100 (first 100 elements): 21459.23 requests per second
LRANGE_300 (first 300 elements): 6416.01 requests per second
LRANGE_500 (first 450 elements): 4156.97 requests per second
LRANGE_600 (first 600 elements): 3139.32 requests per second
MSET (10 keys): 50787.20 requests per second
是不是結果令大家大跌眼鏡,為什么官方號稱只有10%的性能損耗,而實際測試下來竟然相差了50%左右,到底哪里出了問題呢?
其實問題就出在了Docker的Nat網(wǎng)絡模式上,如果我們換一種方式啟動Docker容器,再看下測試結果,是不是能大幅提升性能呢?
4、利用Docker的Host網(wǎng)絡模式啟動redis:
啟動命令:
docker run -v /usr/local/redis.conf:/etc/redis.conf --net="host" --name myredis -d redis:2.8.19
性能測試命令:
redis-benchmark -h 127.0.0.1 -p 6379 -q -d 100
結果如下:
PING_INLINE: 67613.25 requests per second
PING_BULK: 100908.17 requests per second
SET: 97751.71 requests per second
GET: 98135.42 requests per second
INCR: 101936.80 requests per second
LPUSH: 100000.00 requests per second
LPOP: 99206.34 requests per second
SADD: 100704.94 requests per second
SPOP: 100806.45 requests per second
LPUSH (needed to benchmark LRANGE): 100000.00 requests per second
LRANGE_100 (first 100 elements): 40916.53 requests per second
LRANGE_300 (first 300 elements): 15008.25 requests per second
LRANGE_500 (first 450 elements): 5552.78 requests per second
LRANGE_600 (first 600 elements): 3820.29 requests per second
MSET (10 keys): 70224.72 requests per second
最終第四個測試結果令我們滿意,符合官方所說的Docker啟動應用幾乎沒有性能損耗的說法,這點大家在使用Docker部署應用的時候一定要注意。另外值得一提的是,業(yè)界綁定CPU的偏方似乎并沒有什么X用,可能在單機跑多個redis實例的情況下,有那么一點點性能提升。
最后,在使用了host模式啟動Docker之后,是無法改變container監(jiān)聽的端口號的,我們可以通過掛載不同的配置文件來避免端口沖突的發(fā)生。
- 1 回答
- 0 關注
- 2201 瀏覽
添加回答
舉報