Redis(Remote Dictionary Server ),即远程字典服务,是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。是一种NoSql 数据存储服务。主要解决的是数据库读写压力。也可以作为缓存的一种
安装了opcache之后,发现系统顺溜的不行。【本博也是添加了opcache,作为wordpress内核的博客系统,加上supercache之后虽然是小配置服务器,但是丝滑的堪比大配置服务器的响应速度了】 今天用上次加了opcache测试后的服务器继续做redis的测试
服务器电脑配置:
cpu:i3-7300U [2.4G 双核]
内存:4G
带宽:千兆路由就按照100M带宽算吧
在服务器部署了 LNMP环境 使用的是Nginx 1.16.1 /php7.1 /MySQL 5.6.48
测试的接口数据是之前诗词取名的接口 其中的随机获取古诗词句式然后随机获取2个字符组成姓名。
数据库的数据量是:127376条,数据框架使用的是ThinkPHP5.
使用的压力测试工具是apache的ob;
首先使用测试的电脑在未安装opcache的时候,测试数据100000条数据 ,每次压力 10000条数据;
对比测试链接都是一样的代码就是函数名不同而已,都是去除诗词数据库中某条固定的数据,redis就是使用get后判断了下是否为empty 其他的没有多余的代码。这个我之前就预先访问过了,所以这个访问的第一条记录就是redis的了,不会有带入数据库访问的数据延时。
来看看参数对比
今天用ps将6次的数据都列出来,横向对比后发现数据几乎没有变化 优化前后没有多大差别。
- This is ApacheBench, Version 2.3 <$Revision: 1748469 $>
- Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
- Licensed to The Apache Software Foundation, http://www.apache.org/
-
-
-
- Server Software:
- nginx
-
-
- Server Hostname:
- 192.168.31.31
-
-
- Server Port:
- 80
-
-
- Document Path:
- /api/Get_Poems/testname
-
-
- Document Length:
- 3954 bytes
-
-
- Concurrency Level:
- 1000
-
-
- 416.989 seconds
-
-
- Complete requests:
- 100000
-
-
- Failed requests:
- 0
-
-
- Total transferred:
- 432500000 bytes
-
-
- HTML transferred:
- 395400000 bytes
-
-
- Requests per second:
- 239.81
-
-
- Transfer rate:
- 1012.89 kb/s received
-
-
- Connnection Times (ms)
-
-
-
- avg
-
-
- Connect:
- 0
- 3
- 1036
-
-
- Processing:
- 44
- 4147
- 7303
-
-
- Total:
- 44
- 4150
- 8339
-
-
-
- This is ApacheBench, Version 2.3 <$Revision: 1748469 $>
- Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
- Licensed to The Apache Software Foundation, http://www.apache.org/
-
-
-
- Server Software:
- nginx
-
-
- Server Hostname:
- 192.168.31.31
-
-
- Server Port:
- 80
-
-
- Document Path:
- /api/Get_Poems/testname
-
-
- Document Length:
- 3954 bytes
-
-
- Concurrency Level:
- 1000
-
-
- 403.656 seconds
-
-
- Complete requests:
- 100000
-
-
- Failed requests:
- 0
-
-
- Total transferred:
- 432500000 bytes
-
-
- HTML transferred:
- 395400000 bytes
-
-
- Requests per second:
- 247.74
-
-
- Transfer rate:
- 1046.34 kb/s received
-
-
- Connnection Times (ms)
-
-
-
- avg
-
-
- Connect:
- 0
- 3
- 1003
-
-
- Processing:
- 41
- 4015
- 11450
-
-
- Total:
- 41
- 4018
- 12453
-
-
-
- This is ApacheBench, Version 2.3 <$Revision: 1748469 $>
- Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
- Licensed to The Apache Software Foundation, http://www.apache.org/
-
-
-
- Server Software:
- nginx
-
-
- Server Hostname:
- 192.168.31.31
-
-
- Server Port:
- 80
-
-
- Document Path:
- /api/Get_Poems/testname
-
-
- Document Length:
- 3954 bytes
-
-
- Concurrency Level:
- 1000
-
-
- 439.615 seconds
-
-
- Complete requests:
- 100000
-
-
- Failed requests:
- 0
-
-
- Total transferred:
- 432500000 bytes
-
-
- HTML transferred:
- 395400000 bytes
-
-
- Requests per second:
- 227.47
-
-
- Transfer rate:
- 960.76 kb/s received
-
-
- Connnection Times (ms)
-
-
-
- avg
-
-
- Connect:
- 0
- 4
- 1018
-
-
- Processing:
- 54
- 4369
- 8899
-
-
- Total:
- 54
- 4373
- 9917
-
-
-
- This is ApacheBench, Version 2.3 <$Revision: 1748469 $>
- Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
- Licensed to The Apache Software Foundation, http://www.apache.org/
-
-
-
- Server Software:
- nginx
-
-
- Server Hostname:
- 192.168.31.31
-
-
- Server Port:
- 80
-
-
- Document Path:
- /api/Get_Poems/testnameredis
-
-
- Document Length:
- 3954 bytes
-
-
- Concurrency Level:
- 1000
-
-
- 413.356 seconds
-
-
- Complete requests:
- 100000
-
-
- Failed requests:
- 0
-
-
- Total transferred:
- 432500000 bytes
-
-
- HTML transferred:
- 395400000 bytes
-
-
- Requests per second:
- 241.92
-
-
- Transfer rate:
- 1021.79 kb/s received
-
-
- Connnection Times (ms)
-
-
-
- avg
-
-
- Connect:
- 0
- 3
- 1009
-
-
- Processing:
- 45
- 4113
- 5439
-
-
- Total:
- 45
- 4116
- 6448
-
-
-
- This is ApacheBench, Version 2.3 <$Revision: 1748469 $>
- Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
- Licensed to The Apache Software Foundation, http://www.apache.org/
-
-
-
- Server Software:
- nginx
-
-
- Server Hostname:
- 192.168.31.31
-
-
- Server Port:
- 80
-
-
- Document Path:
- /api/Get_Poems/testnameredis
-
-
- Document Length:
- 3954 bytes
-
-
- Concurrency Level:
- 1000
-
-
- 445.139 seconds
-
-
- Complete requests:
- 100000
-
-
- Failed requests:
- 0
-
-
- Total transferred:
- 432500000 bytes
-
-
- HTML transferred:
- 395400000 bytes
-
-
- Requests per second:
- 224.65
-
-
- Transfer rate:
- 948.83 kb/s received
-
-
- Connnection Times (ms)
-
-
-
- avg
-
-
- Connect:
- 0
- 4
- 1007
-
-
- Processing:
- 41
- 4429
- 6390
-
-
- Total:
- 41
- 4433
- 7397
-
-
-
- This is ApacheBench, Version 2.3 <$Revision: 1748469 $>
- Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
- Licensed to The Apache Software Foundation, http://www.apache.org/
-
-
-
- Server Software:
- nginx
-
-
- Server Hostname:
- 192.168.31.31
-
-
- Server Port:
- 80
-
-
- Document Path:
- /api/Get_Poems/testnameredis
-
-
- Document Length:
- 3954 bytes
-
-
- Concurrency Level:
- 1000
-
-
- 432.107 seconds
-
-
- Complete requests:
- 100000
-
-
- Failed requests:
- 0
-
-
- Total transferred:
- 432500000 bytes
-
-
- HTML transferred:
- 395400000 bytes
-
-
- Requests per second:
- 231.42
-
-
- Transfer rate:
- 977.45 kb/s received
-
-
- Connnection Times (ms)
-
-
-
- avg
-
-
- Connect:
- 0
- 4
- 1054
-
-
- Processing:
- 41
- 4293
- 5681
-
-
- Total:
- 41
- 4297
- 6735
前台的访问数据丢包率都是0%。棒棒的;
但是差异还是有的,redis数据库是调用的内存中的数据,而没有的时候使用的是MySQL中直接查询,所以会使用过多的CPU和系统资源。所以后台的系统监控数据就十分的美好了;
首先是磁盘IO方面,6此均有一个写入的小波峰,这个是因为开启了think PHP中的log功能,所以有个波峰,可以忽略不记
这个网络参数就有点不同了,上行明显变高了,这个不在这次的问题中提及。下次分析来进行操作
因为MySQL数据库是需要CPU参与的,所以前3次和后3次的差异一下就显现了
内存方面不好看到,但是有个小波动,因为我提前就是用了redis加载了数据,所以内存值不变,但是确实小号掉了保存数据的内存,大内存基数大的情况下不大容易显现,小内存就可以看到了
负载和资源使用表就很容易看出来了,波峰的峰值就是特别明显
所以在服务器优化了之后,如果MySQL数据量比较小的情况下【对于测试服务器配置10w的数据量确实小】;前端访问几乎就没有明显的差异,具体的差异在服务器的资源消耗上,如果是小配置的服务器估计就可以看到点差异了,但是这个一个消耗CPU一个消耗内存,具体就要看具体业务了,
如果是浏览类的业务的话用redis可以在内存和资源允许的情况下使用,但是如果是例如我们是景点票务系统的,一个数据也就用个3~4次然后他的使命就完成了的话还是不要用了。之前测试时连数据量的索引我都没有用,因为索引还要有个添加事件,这样更拖慢了服务器的响应速度,如果票务系统的接口还要等待OTA接口的反馈值的话,那么就更加没有办法使用这个数据了 使用队列MQ 处理业务的话就更舒适了