问题描述
关于Azure Redis的性能问题,在官方文档中,可以查看到不同层级Redis的最大连接数,每秒处理请求的性能。
基本缓存和标准缓存
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
高级缓存
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
但以上的数据只是官方发布的数据,如果在排除业务的情况下,如何单独对Redis服务器进行测试呢?如果需要验证Redis的性能,如何来做呢?
答案就是使用redis-benchmark.exe,在Azure Redis的常规问答中,有简单的提到如何来做性能测试,但只是一句话,一个命令一晃而过。
如何进行基准检验和测试缓存的性能?
- 启用缓存诊断,以便可以监视缓存的运行状况。 可以在 Azure 门户中查看指标,也可以使用所选的工具下载和查看这些指标。
- 可以使用 redis-benchmark.exe 对 Redis 服务器进行负载测试。
- 确保负载测试客户端和 Azure Redis 缓存位于同一区域。
- 使用 redis-cli.exe,并使用 INFO 命令监视缓存。
- 如果负载导致出现大量内存碎片,则你应该扩展为更大的缓存大小。
- 有关下载 Redis 工具的说明,请参阅如何运行 Redis 命令?部分。
本章的内容就是从下载Redis-benchmark.exe开始,到使用命令完成测试。
一:下载Redis-benchmark.exe
在Github中找到Redis:https://github.com/microsoftarchive/redis/releases,下载最新的ZIP包并解压( 如:Redis-x64-3.2.100.zip)
二:使用Azure Reids的访问密钥开启测试
从Azure的Redis门户中复制出连接字符串,把redis name和access key填充到如下命令
redis-benchmark.exe -h **yourcache**.redis.cache.chinacloudapi.cn -a **yourAccesskey** -c 10 -n 10
以上命令只是简单的发起一轮默认命令的测试(如ping,set,get,pop,push等),-c表示10个并发,-n表示10个请求。
在本机中运行redis-benchmark命令测试:
同时,我们也可以使用-t来指定用于测试的操作,如set,get。参考命令如下:
redis-benchmark.exe -h **yourcache**.redis.cache.chinacloudapi.cn -a **yourAccesskey** -t SET -n 1000000 -d 1024 -P 50 redis-benchmark.exe -h **yourcache**.redis.cache.chinacloudapi.cn -a **yourAccesskey** -t GET -n 1000000 -d 1024 -P 50
如需要使用SSL对Azure Redis进行6380端口的性能测试,则需要先确保本地安装了stunnel.exe并配置好redis-cli客户端信息
- 下载stunnel.exe
- 启动并配置redis-cli连接 (https://docs.azure.cn/zh-cn/azure-cache-for-redis/cache-how-to-redis-cli-tool#enable-access-for-redis-cliexe)
- 使用redis-cli确认是否已经连接
- 如能成功访问到6380端口,则可以使用如下命令开始测试
redis-benchmark.exe -a **your access key** -c 10 -n 10 -p 6380
测试的效果对比如下
6379 非SSL测试 | 6380 SSL测试 |
C:\redis>redis-benchmark.exe -h yourredisname.redis.cache.chinacloudapi.cn -a **youraccesskey** -c 10 -n 10 ====== PING_INLINE ====== 10 requests completed in 0.47 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 198 milliseconds 50.00% <= 219 milliseconds 60.00% <= 238 milliseconds 100.00% <= 261 milliseconds 21.46 requests per second ====== PING_BULK ====== 10 requests completed in 0.49 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 198 milliseconds 20.00% <= 200 milliseconds 30.00% <= 205 milliseconds 40.00% <= 228 milliseconds 50.00% <= 230 milliseconds 60.00% <= 235 milliseconds 100.00% <= 236 milliseconds 20.62 requests per second ====== SET ====== 10 requests completed in 0.46 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 198 milliseconds 20.00% <= 201 milliseconds 30.00% <= 203 milliseconds 40.00% <= 204 milliseconds 50.00% <= 206 milliseconds 80.00% <= 210 milliseconds 90.00% <= 212 milliseconds 100.00% <= 215 milliseconds 21.79 requests per second ====== GET ====== 10 requests completed in 0.44 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 205 milliseconds 50.00% <= 218 milliseconds 60.00% <= 222 milliseconds 80.00% <= 223 milliseconds 90.00% <= 224 milliseconds 100.00% <= 228 milliseconds 22.68 requests per second ====== INCR ====== 10 requests completed in 0.44 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 197 milliseconds 20.00% <= 203 milliseconds 30.00% <= 205 milliseconds 40.00% <= 216 milliseconds 70.00% <= 218 milliseconds 90.00% <= 227 milliseconds 100.00% <= 233 milliseconds 22.99 requests per second ====== LPUSH ====== 10 requests completed in 0.44 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 199 milliseconds 30.00% <= 204 milliseconds 60.00% <= 209 milliseconds 90.00% <= 227 milliseconds 100.00% <= 227 milliseconds 22.68 requests per second ====== RPUSH ====== 10 requests completed in 0.43 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 197 milliseconds 40.00% <= 207 milliseconds 50.00% <= 208 milliseconds 60.00% <= 209 milliseconds 90.00% <= 211 milliseconds 100.00% <= 218 milliseconds 23.47 requests per second ====== LPOP ====== 10 requests completed in 0.43 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 198 milliseconds 20.00% <= 199 milliseconds 80.00% <= 207 milliseconds 90.00% <= 208 milliseconds 100.00% <= 208 milliseconds 23.42 requests per second ====== RPOP ====== 10 requests completed in 0.42 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 200 milliseconds 30.00% <= 201 milliseconds 60.00% <= 202 milliseconds 70.00% <= 207 milliseconds 80.00% <= 209 milliseconds 90.00% <= 211 milliseconds 100.00% <= 211 milliseconds 24.04 requests per second ====== SADD ====== 10 requests completed in 0.43 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 196 milliseconds 20.00% <= 197 milliseconds 40.00% <= 199 milliseconds 50.00% <= 200 milliseconds 60.00% <= 203 milliseconds 70.00% <= 204 milliseconds 90.00% <= 210 milliseconds 100.00% <= 218 milliseconds 23.26 requests per second ====== SPOP ====== 10 requests completed in 0.41 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 203 milliseconds 20.00% <= 204 milliseconds 50.00% <= 205 milliseconds 60.00% <= 206 milliseconds 90.00% <= 209 milliseconds 100.00% <= 210 milliseconds 24.15 requests per second ====== LPUSH (needed to benchmark LRANGE) ====== 10 requests completed in 0.41 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 203 milliseconds 20.00% <= 204 milliseconds 30.00% <= 208 milliseconds 40.00% <= 209 milliseconds 50.00% <= 213 milliseconds 70.00% <= 214 milliseconds 80.00% <= 215 milliseconds 100.00% <= 215 milliseconds 24.15 requests per second ====== LRANGE_100 (first 100 elements) ====== 10 requests completed in 0.44 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 198 milliseconds 30.00% <= 199 milliseconds 40.00% <= 200 milliseconds 50.00% <= 201 milliseconds 60.00% <= 210 milliseconds 80.00% <= 211 milliseconds 90.00% <= 212 milliseconds 100.00% <= 212 milliseconds 22.88 requests per second ====== LRANGE_300 (first 300 elements) ====== 10 requests completed in 0.45 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 196 milliseconds 20.00% <= 197 milliseconds 40.00% <= 202 milliseconds 50.00% <= 203 milliseconds 60.00% <= 207 milliseconds 80.00% <= 208 milliseconds 90.00% <= 209 milliseconds 100.00% <= 210 milliseconds 22.27 requests per second ====== LRANGE_500 (first 450 elements) ====== 10 requests completed in 0.43 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 196 milliseconds 20.00% <= 197 milliseconds 30.00% <= 198 milliseconds 40.00% <= 212 milliseconds 80.00% <= 226 milliseconds 100.00% <= 227 milliseconds 23.15 requests per second ====== LRANGE_600 (first 600 elements) ====== 10 requests completed in 0.46 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 199 milliseconds 30.00% <= 223 milliseconds 50.00% <= 225 milliseconds 70.00% <= 229 milliseconds 90.00% <= 232 milliseconds 100.00% <= 242 milliseconds 21.88 requests per second ====== MSET (10 keys) ====== 10 requests completed in 0.43 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 202 milliseconds 50.00% <= 217 milliseconds 70.00% <= 219 milliseconds 80.00% <= 228 milliseconds 90.00% <= 233 milliseconds 100.00% <= 234 milliseconds 23.20 requests per second |
C:\redis>redis-benchmark.exe -a **youraccesskey** -c 10 -n 10 -p 6380 ====== PING_INLINE ====== 10 requests completed in 0.88 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 597 milliseconds 20.00% <= 615 milliseconds 30.00% <= 827 milliseconds 40.00% <= 841 milliseconds 50.00% <= 842 milliseconds 80.00% <= 868 milliseconds 90.00% <= 869 milliseconds 100.00% <= 869 milliseconds 11.30 requests per second ====== PING_BULK ====== 10 requests completed in 0.96 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 646 milliseconds 20.00% <= 651 milliseconds 30.00% <= 671 milliseconds 40.00% <= 678 milliseconds 50.00% <= 679 milliseconds 60.00% <= 712 milliseconds 70.00% <= 868 milliseconds 80.00% <= 869 milliseconds 90.00% <= 948 milliseconds 100.00% <= 963 milliseconds 10.37 requests per second ====== SET ====== 10 requests completed in 0.89 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 628 milliseconds 20.00% <= 629 milliseconds 50.00% <= 632 milliseconds 70.00% <= 633 milliseconds 80.00% <= 851 milliseconds 90.00% <= 865 milliseconds 100.00% <= 887 milliseconds 11.25 requests per second ====== GET ====== 10 requests completed in 0.88 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 618 milliseconds 30.00% <= 643 milliseconds 50.00% <= 847 milliseconds 70.00% <= 848 milliseconds 80.00% <= 852 milliseconds 90.00% <= 882 milliseconds 100.00% <= 882 milliseconds 11.33 requests per second ====== INCR ====== 10 requests completed in 0.89 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 612 milliseconds 30.00% <= 620 milliseconds 40.00% <= 645 milliseconds 50.00% <= 663 milliseconds 60.00% <= 672 milliseconds 70.00% <= 866 milliseconds 90.00% <= 872 milliseconds 100.00% <= 894 milliseconds 11.17 requests per second ====== LPUSH ====== 10 requests completed in 0.93 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 616 milliseconds 20.00% <= 638 milliseconds 30.00% <= 666 milliseconds 40.00% <= 810 milliseconds 50.00% <= 848 milliseconds 60.00% <= 864 milliseconds 70.00% <= 885 milliseconds 90.00% <= 919 milliseconds 100.00% <= 920 milliseconds 10.73 requests per second ====== RPUSH ====== 10 requests completed in 0.99 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 587 milliseconds 20.00% <= 611 milliseconds 30.00% <= 623 milliseconds 40.00% <= 627 milliseconds 50.00% <= 676 milliseconds 60.00% <= 806 milliseconds 70.00% <= 807 milliseconds 80.00% <= 827 milliseconds 90.00% <= 913 milliseconds 100.00% <= 971 milliseconds 10.15 requests per second ====== LPOP ====== 10 requests completed in 0.88 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 644 milliseconds 30.00% <= 651 milliseconds 60.00% <= 655 milliseconds 70.00% <= 847 milliseconds 90.00% <= 865 milliseconds 100.00% <= 874 milliseconds 11.43 requests per second ====== RPOP ====== 10 requests completed in 2.65 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 687 milliseconds 20.00% <= 688 milliseconds 30.00% <= 766 milliseconds 50.00% <= 775 milliseconds 60.00% <= 916 milliseconds 70.00% <= 917 milliseconds 80.00% <= 923 milliseconds 90.00% <= 1576 milliseconds 100.00% <= 2647 milliseconds 3.78 requests per second ====== SADD ====== 10 requests completed in 0.98 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 636 milliseconds 20.00% <= 637 milliseconds 40.00% <= 653 milliseconds 50.00% <= 708 milliseconds 70.00% <= 897 milliseconds 80.00% <= 945 milliseconds 90.00% <= 946 milliseconds 100.00% <= 946 milliseconds 10.26 requests per second ====== SPOP ====== 10 requests completed in 0.95 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 607 milliseconds 20.00% <= 634 milliseconds 30.00% <= 661 milliseconds 40.00% <= 669 milliseconds 50.00% <= 671 milliseconds 60.00% <= 681 milliseconds 70.00% <= 843 milliseconds 80.00% <= 927 milliseconds 100.00% <= 946 milliseconds 10.55 requests per second ====== LPUSH (needed to benchmark LRANGE) ====== 10 requests completed in 0.90 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 614 milliseconds 20.00% <= 630 milliseconds 30.00% <= 641 milliseconds 40.00% <= 642 milliseconds 60.00% <= 646 milliseconds 70.00% <= 857 milliseconds 80.00% <= 893 milliseconds 90.00% <= 896 milliseconds 100.00% <= 896 milliseconds 11.05 requests per second ====== LRANGE_100 (first 100 elements) ====== 10 requests completed in 0.92 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 573 milliseconds 20.00% <= 605 milliseconds 30.00% <= 606 milliseconds 40.00% <= 624 milliseconds 50.00% <= 634 milliseconds 60.00% <= 671 milliseconds 70.00% <= 800 milliseconds 80.00% <= 804 milliseconds 90.00% <= 805 milliseconds 100.00% <= 897 milliseconds 10.89 requests per second ====== LRANGE_300 (first 300 elements) ====== 10 requests completed in 1.00 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 630 milliseconds 20.00% <= 671 milliseconds 40.00% <= 888 milliseconds 70.00% <= 954 milliseconds 80.00% <= 984 milliseconds 90.00% <= 995 milliseconds 100.00% <= 995 milliseconds 10.03 requests per second ====== LRANGE_500 (first 450 elements) ====== 10 requests completed in 0.85 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 572 milliseconds 20.00% <= 573 milliseconds 30.00% <= 579 milliseconds 40.00% <= 594 milliseconds 60.00% <= 604 milliseconds 70.00% <= 780 milliseconds 80.00% <= 802 milliseconds 100.00% <= 819 milliseconds 11.72 requests per second ====== LRANGE_600 (first 600 elements) ====== 10 requests completed in 0.91 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 566 milliseconds 30.00% <= 629 milliseconds 40.00% <= 634 milliseconds 50.00% <= 812 milliseconds 60.00% <= 836 milliseconds 70.00% <= 851 milliseconds 80.00% <= 867 milliseconds 90.00% <= 873 milliseconds 100.00% <= 880 milliseconds 10.96 requests per second ====== MSET (10 keys) ====== 10 requests completed in 0.89 seconds 10 parallel clients 3 bytes payload keep alive: 1 10.00% <= 606 milliseconds 20.00% <= 619 milliseconds 30.00% <= 625 milliseconds 40.00% <= 667 milliseconds 60.00% <= 851 milliseconds 70.00% <= 875 milliseconds 80.00% <= 878 milliseconds 90.00% <= 886 milliseconds 100.00% <= 888 milliseconds 11.24 requests per second |
PS: 在SSL的情况下,每秒处理请求的能下有明显的下降。
三:对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)//默认情况下,都使用6379端口,因Azure Redis默认只开通了6380端口,进行SSL通信。所以需要在Azure Redis门户中允许6379端口的非SSL访问。 -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> Use random keys for SET/GET/INCR, random values for SADD Using this option the benchmark will expand the string __rand_int__ inside an argument with a 12 digits number in the specified range from 0 to keyspacelen-1. The substitution changes every time a command is executed. Default tests use this to hit random keys in the specified range. -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.
参考资料:
Redis Release: https://github.com/microsoftarchive/redis/releases
如何进行基准检验和测试缓存的性能: https://docs.azure.cn/zh-cn/azure-cache-for-redis/cache-management-faq#how-can-i-benchmark-and-test-the-performance-of-my-cache
How fast is Redis: https://redis.io/topics/benchmarks