常见运维操作 - 性能测试命令

优质
小牛编辑
133浏览
2023-12-01
  1. redis-benchmark -q -r 100000 -n 100000 -c 50

比如:开100条线程(默认50),SET 1千万次(key在0-1千万间随机),key长21字节,value长256字节的数据。-r指的是使用随机key的范围。

  1. redis-benchmark -t SET -c 100 -n 10000000 -r 10000000 -d 256

也可以直接执行lua脚本模拟客户端

  1. redis-benchmark -n 100000 -q script load "redis.call('set','foo','bar')"

注意:Redis-Benchmark的测试结果提供了一个保证你的 Redis-Server 不会运行在非正常状态下的基准点,但是你永远不要把它作为一个真实的“压力测试”。压力测试需要反应出应用的运行方式,并且需要一个尽可能的和生产相似的环境。

Redis-benchmark还有一个作用就是灌数据,例如下列测试场景,我们对某个系统常用redis API进行测试,下列是一个测试hget、hset的过程,我们首先利用rand_int进行随机整数获取,对myhash这个key进行测试数据灌入(这也就测试了hset性能),然后再对其进行hget:

  1. MSMSAPP1:/tmp # ./redis-benchmark -a pass -h 40.XXX.XXX.141 -p 16XXXX -r 500000 -n 500000 hset myhash __rand_int__ __rand_int__
  2. ====== hset myhash __rand_int__ __rand_int__ ======
  3. 500000 requests completed in 18.74 seconds
  4. 50 parallel clients
  5. 3 bytes payload
  6. keep alive: 1
  7. 23.53% <= 1 milliseconds
  8. 95.84% <= 2 milliseconds
  9. 97.62% <= 3 milliseconds
  10. 97.71% <= 4 milliseconds
  11. 97.80% <= 5 milliseconds
  12. 97.84% <= 6 milliseconds
  13. 97.84% <= 8 milliseconds
  14. 97.85% <= 9 milliseconds
  15. 97.85% <= 10 milliseconds
  16. 97.85% <= 11 milliseconds
  17. 97.86% <= 12 milliseconds
  18. 97.88% <= 13 milliseconds
  19. 97.90% <= 14 milliseconds
  20. 97.92% <= 15 milliseconds
  21. 97.94% <= 16 milliseconds
  22. 97.94% <= 20 milliseconds
  23. 97.95% <= 21 milliseconds
  24. 97.95% <= 22 milliseconds
  25. 97.99% <= 23 milliseconds
  26. 98.01% <= 24 milliseconds
  27. 98.11% <= 25 milliseconds
  28. 98.43% <= 26 milliseconds
  29. 98.85% <= 27 milliseconds
  30. 99.17% <= 28 milliseconds
  31. 99.43% <= 29 milliseconds
  32. 99.54% <= 30 milliseconds
  33. 99.68% <= 31 milliseconds
  34. 99.77% <= 32 milliseconds
  35. 99.81% <= 33 milliseconds
  36. 99.85% <= 34 milliseconds
  37. 99.85% <= 35 milliseconds
  38. 99.87% <= 36 milliseconds
  39. 99.88% <= 37 milliseconds
  40. 99.89% <= 38 milliseconds
  41. 99.90% <= 39 milliseconds
  42. 99.90% <= 40 milliseconds
  43. 99.91% <= 44 milliseconds
  44. 99.91% <= 45 milliseconds
  45. 99.91% <= 46 milliseconds
  46. 99.92% <= 47 milliseconds
  47. 99.92% <= 48 milliseconds
  48. 99.93% <= 49 milliseconds
  49. 99.93% <= 50 milliseconds
  50. 99.95% <= 51 milliseconds
  51. 99.96% <= 52 milliseconds
  52. 99.96% <= 53 milliseconds
  53. 99.97% <= 54 milliseconds
  54. 99.98% <= 55 milliseconds
  55. 100.00% <= 55 milliseconds
  56. 26679.47 requests per second
  57. MSMSAPP1:/tmp # ./redis-benchmark -a pass 40.XXX.XXX.141 -p 16XXXX -r 500000 -n 500000 hget myhash __rand_int__ __rand_int__
  58. ====== hget myhash __rand_int__ __rand_int__ ======
  59. 500000 requests completed in 13.83 seconds
  60. 50 parallel clients
  61. 3 bytes payload
  62. keep alive: 1
  63. 74.29% <= 1 milliseconds
  64. 98.29% <= 2 milliseconds
  65. 98.45% <= 3 milliseconds
  66. 98.45% <= 4 milliseconds
  67. 98.45% <= 5 milliseconds
  68. 98.46% <= 11 milliseconds
  69. 98.46% <= 12 milliseconds
  70. 98.48% <= 15 milliseconds
  71. 98.49% <= 16 milliseconds
  72. 98.50% <= 22 milliseconds
  73. 98.50% <= 23 milliseconds
  74. 98.57% <= 24 milliseconds
  75. 98.81% <= 25 milliseconds
  76. 99.16% <= 26 milliseconds
  77. 99.45% <= 27 milliseconds
  78. 99.71% <= 28 milliseconds
  79. 99.84% <= 29 milliseconds
  80. 99.91% <= 30 milliseconds
  81. 99.94% <= 31 milliseconds
  82. 99.94% <= 32 milliseconds
  83. 99.95% <= 33 milliseconds
  84. 99.96% <= 34 milliseconds
  85. 99.96% <= 44 milliseconds
  86. 99.96% <= 45 milliseconds
  87. 99.97% <= 49 milliseconds
  88. 99.97% <= 50 milliseconds
  89. 99.99% <= 55 milliseconds
  90. 100.00% <= 56 milliseconds
  91. 100.00% <= 56 milliseconds
  92. 36145.45 requests per second

注意:上述测试由于是取的随机值,因此hget可能没有命中,同时payload比较小,所以这是个极限性能。

另外,还有一个工具是RedisLab放出来的,我并没有进行测试
参见:https://github.com/RedisLabs/memtier_benchmark