0
点赞
收藏
分享

微信扫一扫

redis 安装和测试

8052cf60ff5c 2022-06-23 阅读 60

1)安装

一、以deb包的形式

  1. download gpg

​curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg​

  1. echo source

​echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list​

  1. install redis software

​apt update​

​apt install redis -y​

  1. 确认redis服务是否起来

​systemctl status redis-server​

  1. 看下监听在哪个ip上

​ps -ef|grep redis​

或者

​ss -nlap|grep 6379​

6379是redis的监听端口。通过以上命令可以看到默认监听在127.0.0.1的ip地址上.

  1. 修改/etc/redis/redis.conf配置改变监听地址

redis 安装和测试_redis

重启redis-server服务

​systemctl restart redis-server​

查看已经成功监听在0.0.0.0地址上了

root@nginx-active:~# systemctl status redis-server
● redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; disabled; vendor preset: enabled)
Active: active (running) since Thu 2022-06-23 08:58:16 CST; 5s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Process: 5230 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
Main PID: 5252 (redis-server)
Status: "Ready to accept connections"
Tasks: 5 (limit: 4915)
CGroup: /system.slice/redis-server.service
└─5252 /usr/bin/redis-server 0.0.0.0:6379

二、以snapcraft的方式

​snap install redis​

snapd install method:​​Install snapd​​

2)测试

三、利用redis-benchmark工具测试redis性能

  1. 观察下当前系统的负载、内存情况.top和free -h

内存还剩余11G

total        used        free      shared  buff/cache   available
Mem: 15G 701M 11G 21M 3.3G 14G
Swap: 0B 0B 0B

利用iostat -t 2观察下磁盘性能,间隔2s 以20个并发测试请求100k的request

​redis-benchmark -h 127.0.0.1 -p 6379 -n 100000 -c 20​

结果如下: 由于在本地上,不经过网络,所以没有网络延时的影响,这里最主要的测试结果只能说明redis在memory上的性能

====== PING_INLINE ======
100000 requests completed in 0.63 seconds
20 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 3600 1 300 100 60 10000
host configuration "appendonly": no
multi-thread: no
Summary:
throughput summary: 157728.70 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.096 0.032 0.095 0.151 0.207 0.607
====== PING_MBULK ======
100000 requests completed in 0.60 seconds
20 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 3600 1 300 100 60 10000
host configuration "appendonly": no
multi-thread: no
Summary:
throughput summary: 165837.48 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.094 0.032 0.095 0.143 0.167 0.583
====== SET ======
100000 requests completed in 0.66 seconds
20 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 3600 1 300 100 60 10000
host configuration "appendonly": no
multi-thread: no
Summary:
throughput summary: 151745.08 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.113 0.032 0.111 0.159 0.215 0.703
====== GET ======
100000 requests completed in 0.63 seconds
20 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 3600 1 300 100 60 10000
host configuration "appendonly": no
multi-thread: no
Summary:
throughput summary: 158730.16 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.104 0.032 0.103 0.151 0.191 0.439
====== INCR ======
100000 requests completed in 0.73 seconds
20 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 3600 1 300 100 60 10000
host configuration "appendonly": no
multi-thread: no
Summary:
throughput summary: 137362.64 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.129 0.032 0.127 0.191 0.239 0.663
====== LPUSH ======
100000 requests completed in 0.94 seconds
20 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 3600 1 300 100 60 10000
host configuration "appendonly": no
multi-thread: no
Summary:
throughput summary: 106951.88 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.163 0.048 0.159 0.223 0.335 1.119
====== RPUSH ======
100000 requests completed in 0.71 seconds
20 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 3600 1 300 100 60 10000
host configuration "appendonly": no
multi-thread: no
Summary:
throughput summary: 140056.03 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.117 0.032 0.111 0.183 0.247 0.455
====== LPOP ======
100000 requests completed in 0.69 seconds
20 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 3600 1 300 100 60 10000
host configuration "appendonly": no
multi-thread: no
Summary:
throughput summary: 145348.83 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.116 0.040 0.119 0.167 0.231 0.447
====== RPOP ======
100000 requests completed in 0.67 seconds
20 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 3600 1 300 100 60 10000
host configuration "appendonly": no
multi-thread: no
Summary:
throughput summary: 149700.61 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.110 0.032 0.111 0.159 0.199 0.383
====== SADD ======
100000 requests completed in 0.86 seconds
20 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 3600 1 300 100 60 10000
host configuration "appendonly": no
multi-thread: no
Summary:
throughput summary: 115740.73 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.131 0.032 0.127 0.199 0.255 0.831
====== HSET ======
100000 requests completed in 0.92 seconds
20 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 3600 1 300 100 60 10000
host configuration "appendonly": no
multi-thread: no
Summary:
throughput summary: 109051.26 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.149 0.048 0.151 0.215 0.271 0.639
====== SPOP ======
100000 requests completed in 0.81 seconds
20 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 3600 1 300 100 60 10000
host configuration "appendonly": no
multi-thread: no
Summary:
throughput summary: 123762.38 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.113 0.032 0.111 0.175 0.223 0.583
====== ZADD ======
100000 requests completed in 0.69 seconds
20 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 3600 1 300 100 60 10000
host configuration "appendonly": no
multi-thread: no
Summary:
throughput summary: 144717.80 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.117 0.032 0.119 0.167 0.231 0.911
====== ZPOPMIN ======
100000 requests completed in 0.63 seconds
20 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 3600 1 300 100 60 10000
host configuration "appendonly": no
multi-thread: no
Summary:
throughput summary: 158227.84 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.107 0.032 0.103 0.151 0.223 0.591
====== LPUSH (needed to benchmark LRANGE) ======
100000 requests completed in 0.90 seconds
20 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 3600 1 300 100 60 10000
host configuration "appendonly": no
multi-thread: no
Summary:
throughput summary: 110987.79 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.161 0.040 0.159 0.239 0.311 0.791
====== LRANGE_100 (first 100 elements) ======
100000 requests completed in 1.68 seconds
20 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 3600 1 300 100 60 10000
host configuration "appendonly": no
multi-thread: no
Summary:
throughput summary: 59453.03 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.278 0.088 0.271 0.407 0.471 0.943
====== LRANGE_300 (first 300 elements) ======
100000 requests completed in 4.02 seconds
20 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 3600 1 300 100 60 10000
host configuration "appendonly": no
multi-thread: no
Summary:
throughput summary: 24863.25 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.411 0.136 0.407 0.519 0.583 1.871
====== LRANGE_500 (first 500 elements) ======
100000 requests completed in 5.73 seconds
20 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 3600 1 300 100 60 10000
host configuration "appendonly": no
multi-thread: no
Summary:
throughput summary: 17455.05 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.582 0.144 0.575 0.671 0.815 2.503
====== LRANGE_600 (first 600 elements) ======
100000 requests completed in 6.41 seconds
20 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 3600 1 300 100 60 10000
host configuration "appendonly": no
multi-thread: no
Summary:
throughput summary: 15607.93 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.647 0.112 0.647 0.767 0.903 4.415
====== MSET (10 keys) ======
100000 requests completed in 1.12 seconds
20 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 3600 1 300 100 60 10000
host configuration "appendonly": no
multi-thread: no
Summary:
throughput summary: 89365.51 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.201 0.064 0.191 0.271 0.319 0.591

上面的命令将会对所有的subset进行测试,可以加上参数-t指定subset,例如指定set进行随机的测试。 先flushall下(删除所有)

​redis-cli flushall​

通过pidstat观察下redis进程的内存使用情况

命令:​​pidstat -r -p 5252 2​

​redis-benchmark -t set -r 100000 -n 1000000​

====== SET ======
1000000 requests completed in 7.58 seconds
50 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 3600 1 300 100 60 10000
host configuration "appendonly": no
multi-thread: no
Summary:
throughput summary: 131856.53 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.318 0.080 0.303 0.495 0.583 1.983

查看下大小 redis-cli dbsize

(integer) 99993

pidstat观察到的现象如下

redis 安装和测试_redis_02

总共耗时8.22秒,minflt/s也就是第四列(soft page fault,次缺页错误)开始增多然后下降,这个字段表明redis进程和其它进程存在共用内存区域的情况,不影响,mmu内存管理单元会再次重新进行VA和PA的映射。如果是第五列值增加了(hard page fault)那就会影响性能,因为此时cpu需要从磁盘读取。倒数第二列表明了该进程的内存使用百分比,从0.07增加到0.12增加0.05。也就是增加了8M。也就是dbsize为99995需要占用8M的内存。

举报

相关推荐

0 条评论