1 回答

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超4個(gè)贊
我們下面將比較原生啟動(dòng) redis 實(shí)例和使用Docker啟動(dòng)的性能對(duì)比。
測(cè)試機(jī)器:
24 CPUS,48G內(nèi)存的dell 420 物理服務(wù)器
其中redis的配置文件如下:
daemonize yes
port 6379
1、宿主機(jī)直接啟動(dòng)redis實(shí)例:
啟動(dòng)命令:
redis-server /etc/redis.conf
性能測(cè)試命令:
redis-benchmark -h 127.0.0.1 -p 6379 -q -d 100
結(jié)果如下:
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綁定一個(gè)CPU,在宿主機(jī)上啟動(dòng)redis(這也是業(yè)界優(yōu)化redis的一個(gè)偏方):
啟動(dòng)命令:
taskset -c 02 redis-server /etc/redis.conf
性能測(cè)試命令:
redis-benchmark -h 127.0.0.1 -p 6379 -q -d 100
結(jié)果如下:
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)絡(luò)模式啟動(dòng)redis(我們之前介紹的方式):
啟動(dòng)命令:
docker run -v /usr/local/redis.conf:/etc/redis.conf -p 6379:6379 --name myredis -d redis:2.8.19
性能測(cè)試命令:
redis-benchmark -h 127.0.0.1 -p 6379 -q -d 100
結(jié)果如下:
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
是不是結(jié)果令大家大跌眼鏡,為什么官方號(hào)稱(chēng)只有10%的性能損耗,而實(shí)際測(cè)試下來(lái)竟然相差了50%左右,到底哪里出了問(wèn)題呢?
其實(shí)問(wèn)題就出在了Docker的Nat網(wǎng)絡(luò)模式上,如果我們換一種方式啟動(dòng)Docker容器,再看下測(cè)試結(jié)果,是不是能大幅提升性能呢?
4、利用Docker的Host網(wǎng)絡(luò)模式啟動(dòng)redis:
啟動(dòng)命令:
docker run -v /usr/local/redis.conf:/etc/redis.conf --net="host" --name myredis -d redis:2.8.19
性能測(cè)試命令:
redis-benchmark -h 127.0.0.1 -p 6379 -q -d 100
結(jié)果如下:
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
最終第四個(gè)測(cè)試結(jié)果令我們滿(mǎn)意,符合官方所說(shuō)的Docker啟動(dòng)應(yīng)用幾乎沒(méi)有性能損耗的說(shuō)法,這點(diǎn)大家在使用Docker部署應(yīng)用的時(shí)候一定要注意。另外值得一提的是,業(yè)界綁定CPU的偏方似乎并沒(méi)有什么X用,可能在單機(jī)跑多個(gè)redis實(shí)例的情況下,有那么一點(diǎn)點(diǎn)性能提升。
最后,在使用了host模式啟動(dòng)Docker之后,是無(wú)法改變container監(jiān)聽(tīng)的端口號(hào)的,我們可以通過(guò)掛載不同的配置文件來(lái)避免端口沖突的發(fā)生。
- 1 回答
- 0 關(guān)注
- 960 瀏覽
添加回答
舉報(bào)