Redis之介绍

##################################

Redis 作为优秀的内存数据库,其拥有非常高的性能,

  • 单个Redis实例的OPS能够达到10W左右;性能极高 – Redis能读的速度是110000次/s,写的速度是81000次/s 。 

 

 

 

 

 

 Redis基准测试:redis-cli  --intrinsic-latency 60

命令:redis-cli --intrinsic-latency 60:

[work@a8-dba-cloud-db00.wh ~]$ ./redis_8001/bin/redis-cli  -a jJAV0kTokNb8iZvwfqniCxmFZEsbOH5n -h 192.168.31.33 -p 8001 --intrinsic-latency 60
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
Max latency so far: 1 microseconds.
Max latency so far: 9 microseconds.
Max latency so far: 10 microseconds.
Max latency so far: 11 microseconds.
Max latency so far: 18 microseconds.
Max latency so far: 24 microseconds.
Max latency so far: 30 microseconds.
Max latency so far: 33 microseconds.
Max latency so far: 38 microseconds.
Max latency so far: 435 microseconds.

1482768102 total runs (avg latency: 0.0405 microseconds / 40.46 nanoseconds per run).
Worst run took 10750x longer than the average latency.
[work@a8-dba-cloud-db00.wh ~]$ 

 

命令:redis-cli --latency-hostory -i 1

[work@a8-dba-cloud-db00.wh ~]$ ./redis_8001/bin/redis-cli  -a jJAV0kTokNb8iZvwfqniCxmFZEsbOH5n -h 192.168.31.33 -p 8001 --latency-history -i 1
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
min: 0, max: 1, avg: 0.23 (97 samples) -- 1.01 seconds range
min: 0, max: 1, avg: 0.31 (96 samples) -- 1.00 seconds range
min: 0, max: 1, avg: 0.27 (96 samples) -- 1.00 seconds range
min: 0, max: 1, avg: 0.39 (96 samples) -- 1.01 seconds range
min: 0, max: 1, avg: 0.28 (96 samples) -- 1.00 seconds range
min: 0, max: 1, avg: 0.23 (96 samples) -- 1.00 seconds range
min: 0, max: 1, avg: 0.23 (96 samples) -- 1.00 seconds range
min: 0, max: 1, avg: 0.22 (96 samples) -- 1.00 seconds range
min: 0, max: 1, avg: 0.30 (96 samples) -- 1.00 seconds range
min: 0, max: 1, avg: 0.32 (96 samples) -- 1.01 seconds range
min: 0, max: 1, avg: 0.34 (96 samples) -- 1.00 seconds range
min: 0, max: 1, avg: 0.29 (96 samples) -- 1.00 seconds range
min: 0, max: 1, avg: 0.38 (96 samples) -- 1.00 seconds range
min: 0, max: 1, avg: 0.27 (96 samples) -- 1.00 seconds range
min: 0, max: 1, avg: 0.34 (96 samples) -- 1.00 seconds range
min: 0, max: 1, avg: 0.35 (96 samples) -- 1.00 seconds range
min: 0, max: 1, avg: 0.29 (96 samples) -- 1.01 seconds range
min: 0, max: 1, avg: 0.33 (96 samples) -- 1.00 seconds range
min: 0, max: 1, avg: 0.28 (96 samples) -- 1.01 seconds range
min: 0, max: 1, avg: 0.34 (96 samples) -- 1.00 seconds range
min: 0, max: 1, avg: 0.29 (96 samples) -- 1.00 seconds range
min: 0, max: 1, avg: 0.24 (96 samples) -- 1.00 seconds range
min: 0, max: 1, avg: 0.35 (96 samples) -- 1.01 seconds range
min: 0, max: 1, avg: 0.24 (96 samples) -- 1.01 seconds range
min: 0, max: 1, avg: 0.23 (96 samples) -- 1.00 seconds range
min: 0, max: 1, avg: 0.35 (96 samples) -- 1.00 seconds range
min: 0, max: 1, avg: 0.33 (96 samples) -- 1.01 seconds range

 

 

 redis慢的原因:

  • 使用了复杂度超过O(N)的命令;
  • 客户端返回了过多的数据;
  • 插入或删除bigkey;
  • 键集中过期,需要大量删除过期 key 的情况;
  • 内存达到了实例的maxmemory;
  • fork耗时严重;
  • 碎片整理耗时严重;
  • 网络带宽过载;
  • 频繁短连接;

 

 

 

 

优化思路:

  • 尽量不使用 O(N) 以上复杂度过高的命令,对于数据的聚合操作,放在客户端做;
  • 执行 O(N) 命令,保证 N 尽量的小(推荐 N <= 300),每次获取尽量少的数据,让 Redis 可以及时处理返回;

 

 查找bigkey:

[work@a8-dba-cloud-db00.wh ~]$ ./redis_8001/bin/redis-cli  -a jJAV0kTokNb8iZvwfqniCxmFZEsbOH5n -h 192.168.31.33 -p 7001 --bigkeys -i 0.01
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

# Scanning the entire keyspace to find biggest keys as well as
# average sizes per key type.  You can use -i 0.1 to sleep 0.1 sec
# per 100 SCAN commands (not usually needed).

[00.00%] Biggest string found so far '"mykey84336"' with 5 bytes
[00.00%] Biggest list   found so far '"mylist170898"' with 1 items
[00.00%] Biggest hash   found so far '"obj135479"' with 1 fields
[00.00%] Biggest string found so far '"mykey345061"' with 6 bytes
[02.00%] Biggest list   found so far '"mylist"' with 410013 items
[25.94%] Biggest hash   found so far '"obj"' with 410014 fields

-------- summary -------

Sampled 615176 keys in the keyspace!
Total key length in bytes is 6395083 (avg len 10.40)

Biggest   list found '"mylist"' has 410013 items
Biggest   hash found '"obj"' has 410014 fields
Biggest string found '"mykey345061"' has 6 bytes

205144 lists with 615156 items (33.35% of keys, avg size 3.00)
205110 hashs with 615123 fields (33.34% of keys, avg size 3.00)
204922 strings with 1173982 bytes (33.31% of keys, avg size 5.73)
0 streams with 0 entries (00.00% of keys, avg size 0.00)
0 sets with 0 members (00.00% of keys, avg size 0.00)
0 zsets with 0 members (00.00% of keys, avg size 0.00)
[work@a8-dba-cloud-db00.wh ~]$ 

 

 

 

 

 

#############################

posted @ 2023-02-22 12:46  igoodful  阅读(37)  评论(0编辑  收藏  举报