# 参数说明: -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 -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 2) --dbnum <db> SELECT the specified db number (default 0) -k <boolean> 1=keep alive 0=reconnect (default 1) -r <keyspacelen> 对SET/GET/INCR使用随机键,对SADD使用随机值使用此选项基准将扩展参数内的字符串_rand_int _uu),该参数的指定范围为0到keyspacelen-1之间的12位数字。 -P <numreq> Pipeline <numreq> requests. Default 1 (no pipeline). -q Quiet. Just show query/sec values --csv Output in CSV format -l Loop. Run the tests forever -t <tests> Only run the comma separated list of tests. The test names are the same as the ones produced as output. -I Idle mode. Just open N idle connections and wait.
# (1) 同时执行 10000 个请求来检测性能(所有默认测试),通过 -q 参数让结果只显示每秒执行的请求数 $ ./redis-benchmark -h 127.0.0.1 -p 6379 -t set,lpush -n 10000 -q $ ./redis-benchmark -n 10000 -q # PING_INLINE: 41493.78 requests per second # PING_BULK: 44843.05 requests per second # SET: 42194.09 requests per second # GET: 44052.86 requests per second # INCR: 43290.04 requests per second # LPUSH: 42194.09 requests per second # RPUSH: 42372.88 requests per second # LPOP: 42194.09 requests per second # RPOP: 42194.09 requests per second # SADD: 43668.12 requests per second # HSET: 42372.88 requests per second # SPOP: 44843.05 requests per second # LPUSH (needed to benchmark LRANGE): 42553.19 requests per second # LRANGE_100 (first 100 elements): 21367.52 requests per second # LRANGE_300 (first 300 elements): 9451.80 requests per second # LRANGE_500 (first 450 elements): 6807.35 requests per second # LRANGE_600 (first 600 elements): 5350.46 requests per second # MSET (10 keys): 36363.64 requests per second
# (2) 运行指定项目的测试,例如我们要求在安静模式下仅运行测试 SET 和 LPUSH 命令 $ redis-benchmark -t set,lpush -n 100000 -q # SET: 74239.05 requests per second # LPUSH: 79239.30 requests per second
# (3) 指定eval脚本命令进行基准测试 $ redis-benchmark -n 100000 -q script load "redis.call('set','foo','bar')" # script load redis.call('set','foo','bar'): 69881.20 requests per second
# Intel(R) Xeon(R) CPU E5520 @ 2.27GHz(带流水线)/ (无流水线) $ ./redis-benchmark -r 1000000 -n 2000000 -t get,set,lpush,lpop -P 16 -q # 优于无流水线。 SET: 552028.75 requests per second GET: 707463.75 requests per second LPUSH: 767459.75 requests per second LPOP: 770119.38 requests per second
$ ./redis-benchmark -r 1000000 -n 2000000 -t get,set,lpush,lpop -q SET: 122556.53 requests per second GET: 123601.76 requests per second LPUSH: 136752.14 requests per second LPOP: 132424.03 requests per second
4) 与使用相同硬件不使用虚拟化的情况相比,Redis 在 VM 上运行速度较慢(推荐物理机按照Redis为首选)
5) 根据平台的不同,unix 域套接字可以实现比 TCP/IP 环回(例如在 Linux 上)多约 50% 的吞吐量。
./redisbench -h -a string #Redis instance address or Cluster addresses. IP:PORT[,IP:PORT] -c int #Clients number for concurrence (default 1) -cluster #true: cluster mode, false: instance mode -d int #Data size in bytes (default 1000) -ma string #addresses for run multiple testers at the same time -mo int #the order current tester is in multiple testers -n int #Testing times at every client (default 1)
$ cpu 相关信息 Model name: Intel(R) Xeon(R) CPU E3-1220 V2 @ 3.10GHz 物理CPU数: 1 逻辑CPU数: 4 CPU核心数: 4
基准测试:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# 测试1.执行1千万次set命令与get命令,其中每次读取得大小为256字节, 请求客户端数默认50。 ~$ redis-benchmark -h 10.102.39.181 -a 123456 -d 256 -t set,get -n 10000000 -q SET: 42445.36 requests per second GET: 49504.70 requests per second # - 测试时 Pod 资源峰值 very 1.0s: kubectl top pod -n database redis-cm-0 Tue Sep 7 20:36:50 2021 NAME CPU(cores) MEMORY(bytes) redis-cm-0 848 18Mi
# 测试2.同样执行1千万次set命令与get命令,其中每次读取得大小为256字节,唯一不同的是采用 流水线 -P 16 进行测试(可以看出每秒set、get请求数显著提升)。 ~$ redis-benchmark -h 10.102.39.181 -a 123456 -d 256 -t set,get -n 10000000 -P 16 -q SET: 96019.98 requests per second GET: 316575.91 requests per second
# - 测试时 Pod 资源峰值 very 1.0s: kubectl top pod -n database redis-cm-0 Tue Sep 7 20:46:50 2021 NAME CPU(cores) MEMORY(bytes) redis-cm-0 457m 337Mi
## redis pipe 方式插入数据 ~/k8s/benchmark$ time ./redis-pipe.sh # 开始时间:1631020862 # All data transferred. Waiting for the last reply... # Last reply received from server. # errors: 0, replies: 100000 # 完成时间: 1631020862
# 为了方便后续演示,握又向数据库中插入了80W条数据,只用了大约4s。 开始时间: 1631022423 All data transferred. Waiting for the last reply... Last reply received from server. errors: 0, replies: 800000 完成时间: 1631022427 real 0m4.023s user 0m0.885s sys 0m0.187s
# 4.日志文件存放目录以及记录redis访问信息。 # debug (a lot of information, useful for development/testing) # verbose (many rarely useful info, but not a mess like the debug level) # notice (moderately verbose, what you want in production probably) 默认 # warning (only very important / critical messages are logged) logfile "/usr/local/redis/redis.log" loglevel verbose
Step 1.vm.overcommit_memory 最佳实践 Redis在启动时可能会出现这样的日志, 然后弄清楚什么是overcommit? 描述: Linux 操作系统对大部分申请内存的请求都回复yes以便能运行更多的程序。因为申请内存后并不会马上使用内存,这种技术叫做overcommit。
1 2 3 4 5 6 7 8
# 如果Redis在启动时有上面的日志,说明`vm.overcommit_memory=0`,Redis提示把它设置为1。 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command'sysctl -w vm.overcommit_memory=1'for this to take effect.
WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
因此Redis日志中建议将此特性进行禁用,禁用方法如下:echo never > /sys/kernel/mm/transparent_hugepage/enabled
Step 4.Transparent Huge Pages Redis在启动时可能会看到如下日志:WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
# You requested maxclients of 10000 requiring at least 10032 max file descriptors. 第一行:Redis建议把open files至少设置成10032,那么这个10032是如何来的呢?因为maxclients的默认是10000,这些是用来处理客户端连接的,除此之外,Redis内部会使用最多32个文件描述符,所以这里的10032 = 10000 + 32。
# Redis can’t set maximum open files to 10032 because of OS error: Operation not permitted. 第二行:Redis不能将open files设置成10032,因为它没有权限设置。
# Current maximum open files is 4096. Maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase ‘ulimit –n’. 第三行:当前系统的open files是4096,所以maxclients被设置成4096-32=4064个,如果你想设置更高的maxclients,请使用ulimit -n来设置。从上面的三行日志分析可以看出open files的限制优先级比maxclients大。
解决办法:
1 2 3 4 5 6 7 8 9
# 临时 ulimit –Sn 10032 # 永久 tee etc/security/limits.conf <<'EOF' * soft nofile 10032 * hard nofile 10032 * soft nproc 65535 * hard nproc 65535 EOF
方式1.请访问本博主的B站【WeiyiGeek】首页关注UP主, 将自动随机获取解锁验证码。
Method 2.Please visit 【My Twitter】. There is an article verification code in the homepage.
方式3.扫一扫下方二维码,关注本站官方公众号
回复:验证码
将获取解锁(有效期7天)本站所有技术文章哟!