redis性能压测
文章目錄
- redis性能壓測
- redis性能壓測工具--redis-benchmark
- redis-benchmark 壓測結果
- redis-benchmark 壓測踩坑
- 踩坑一:Can't create socket: Too many open files
- 踩坑二:Cannot assign requested address
redis性能壓測
redis性能壓測工具–redis-benchmark
如果要對 redis 進行性能壓測,可以選擇 redis 自帶的壓測工具 redis-benchmark。
進入到 /usr/local/software/redis-6.0.9/src 下,使用如下命令開始 redis 性能壓測:
./redis-benchmark -h 10.0.0.4 -p 6379 -a redis-pass -c 5000 -n 50000 -d 50使用 redis-benchmark -h 命令可以查看 redis-benchmark 相關參數,如下所示:
Usage: redis-benchmark [-h <host>] [-p <port>] [-c <clients>] [-n <requests>] [-k <boolean>]-h <hostname> Server hostname (default 127.0.0.1)-p <port> Server port (default 6379)-s <socket> Server socket (overrides host and port)-a <password> Password for Redis Auth--user <username> Used to send ACL style 'AUTH username pass'. Needs -a.-c <clients> Number of parallel connections (default 50)-n <requests> Total number of requests (default 100000)-d <size> Data size of SET/GET value in bytes (default 3)--dbnum <db> SELECT the specified db number (default 0)--threads <num> Enable multi-thread mode.--cluster Enable cluster mode.--enable-tracking Send CLIENT TRACKING on before starting benchmark.-k <boolean> 1=keep alive 0=reconnect (default 1)-r <keyspacelen> Use random keys for SET/GET/INCR, random values for SADD,random members and scores for ZADD.Using this option the benchmark will expand the string __rand_int__inside an argument with a 12 digits number in the specified rangefrom 0 to keyspacelen-1. The substitution changes every time a commandis executed. Default tests use this to hit random keys in thespecified range.-P <numreq> Pipeline <numreq> requests. Default 1 (no pipeline).-e If server replies with errors, show them on stdout.(no more than 1 error per second is displayed)-q Quiet. Just show query/sec values--precision Number of decimal places to display in latency output (default 0)--csv Output in CSV format-l Loop. Run the tests forever-t <tests> Only run the comma separated list of tests. The testnames are the same as the ones produced as output.-I Idle mode. Just open N idle connections and wait.redis-benchmark 相關參數解釋說明
redis-benchmark 壓測結果
redis-benchmark 壓測結果如下所示:
[root@mq1 src]# ./redis-benchmark -h 10.0.0.4 -p 6379 -a redis-pass -c 5000 -n 50000 -d 50 ====== PING_INLINE ======50000 requests completed in 0.74 seconds5000 parallel clients50 bytes payloadkeep alive: 1host configuration "save": 900 1 300 10 60 10000host configuration "appendonly": yesmulti-thread: no0.00% <= 18 milliseconds 0.11% <= 19 milliseconds 0.30% <= 20 milliseconds 0.78% <= 21 milliseconds 1.13% <= 22 milliseconds 1.36% <= 23 milliseconds 1.71% <= 24 milliseconds 2.31% <= 25 milliseconds 3.44% <= 26 milliseconds 5.26% <= 27 milliseconds 7.53% <= 28 milliseconds 9.69% <= 29 milliseconds 11.74% <= 30 milliseconds 13.81% <= 31 milliseconds 15.82% <= 32 milliseconds 17.74% <= 33 milliseconds 20.13% <= 34 milliseconds 22.83% <= 35 milliseconds 25.27% <= 36 milliseconds 27.70% <= 37 milliseconds 30.22% <= 38 milliseconds 32.75% <= 39 milliseconds 35.68% <= 40 milliseconds 39.77% <= 41 milliseconds 45.01% <= 42 milliseconds 50.80% <= 43 milliseconds 55.11% <= 44 milliseconds 58.44% <= 45 milliseconds 61.85% <= 46 milliseconds 64.59% <= 47 milliseconds 67.36% <= 48 milliseconds 69.99% <= 49 milliseconds 72.79% <= 50 milliseconds 75.65% <= 51 milliseconds 78.24% <= 52 milliseconds 80.39% <= 53 milliseconds 82.34% <= 54 milliseconds 84.34% <= 55 milliseconds 86.57% <= 56 milliseconds 87.80% <= 57 milliseconds 88.93% <= 58 milliseconds 89.99% <= 59 milliseconds 90.70% <= 60 milliseconds 92.08% <= 61 milliseconds 92.78% <= 62 milliseconds 93.35% <= 63 milliseconds 93.93% <= 64 milliseconds 94.44% <= 65 milliseconds 94.70% <= 66 milliseconds 95.02% <= 67 milliseconds 95.29% <= 68 milliseconds 95.53% <= 69 milliseconds 95.73% <= 70 milliseconds 96.04% <= 71 milliseconds 96.34% <= 72 milliseconds 96.64% <= 73 milliseconds 97.06% <= 74 milliseconds 97.44% <= 75 milliseconds 97.78% <= 76 milliseconds 97.90% <= 77 milliseconds 98.17% <= 78 milliseconds 98.32% <= 79 milliseconds 98.49% <= 80 milliseconds 98.71% <= 81 milliseconds 98.78% <= 82 milliseconds 98.97% <= 83 milliseconds 99.12% <= 84 milliseconds 99.26% <= 85 milliseconds 99.41% <= 86 milliseconds 99.57% <= 87 milliseconds 99.72% <= 88 milliseconds 99.86% <= 89 milliseconds 100.00% <= 89 milliseconds 67659.00 requests per second......redis-benchmark 壓測踩坑
踩坑一:Can’t create socket: Too many open files
問題描述:
linux 系統默認 open file 是 1024,程序打開的文件 /socket 連接數量超過系統設定值。可以通過 ulimit -a 命令查看,如下所示:
解決方案:
踩坑二:Cannot assign requested address
問題描述:
這是由于 redis-benchmark 的壓力測試時頻繁的連服務器,數據量較大的時候,因為每次鏈接都在很短的時間內結束,致使不少的 TIME_WAIT,以致于用光了可用的端口號,因此新的鏈接沒辦法綁定端口,即 “Cannot assign requestedaddress”。
解決方案:
執行以下命令:
# 開啟對于TCP時間戳的支持,若該項設置為0,則下面一項設置不起作用 sysctl -w net.ipv4.tcp_timestamps=1 # 表示開啟TCP連接中TIME-WAIT sockets的快速回收 sysctl -w net.ipv4.tcp_tw_recycle=1然而,執行上述命令后,再次使上述命令進行壓測,仍然出現上述問題。因為上述命令設置的請求數和連接數比較大,所以嘗試性的減小了其數值,執行之后成功開啟 redis-benchmark 的壓力測試,如下所示:
總結
- 上一篇: 国家电网调控人工智能创新大赛开启 百度飞
- 下一篇: Android系统编译优化:使用Ninj