logo
当前位置:首 页 > 编程技术 >后端开发 >PHP语言 > 查看文章

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次的数据都列出来,横向对比后发现数据几乎没有变化 优化前后没有多大差别。

 

  1. This is ApacheBench, Version 2.<$Revision: 1748469 $>
  2. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  3. Licensed to The Apache Software Foundation, http://www.apache.org/
  4.  
  5.  
  6.  
  7. Server Software:
  8. nginx
  9.  
  10.  
  11. Server Hostname:
  12. 192.168.31.31
  13.  
  14.  
  15. Server Port:
  16. 80
  17.  
  18.  
  19. Document Path:
  20. /api/Get_Poems/testname
  21.  
  22.  
  23. Document Length:
  24. 3954 bytes
  25.  
  26.  
  27. Concurrency Level:
  28. 1000
  29.  
  30.  
  31. Time taken for tests:
  32. 416.989 seconds
  33.  
  34.  
  35. Complete requests:
  36. 100000
  37.  
  38.  
  39. Failed requests:
  40. 0
  41.  
  42.  
  43. Total transferred:
  44. 432500000 bytes
  45.  
  46.  
  47. HTML transferred:
  48. 395400000 bytes
  49.  
  50.  
  51. Requests per second:
  52. 239.81
  53.  
  54.  
  55. Transfer rate:
  56. 1012.89 kb/s received
  57.  
  58.  
  59. Connnection Times (ms)
  60.  
  61.  
  62.  
  63. avg
  64.  
  65.  
  66. Connect:
  67. 0
  68. 3
  69. 1036
  70.  
  71.  
  72. Processing:
  73. 44
  74. 4147
  75. 7303
  76.  
  77.  
  78. Total:
  79. 44
  80. 4150
  81. 8339
  82.  
  83.  
  84.  
  85. This is ApacheBench, Version 2.<$Revision: 1748469 $>
  86. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  87. Licensed to The Apache Software Foundation, http://www.apache.org/
  88.  
  89.  
  90.  
  91. Server Software:
  92. nginx
  93.  
  94.  
  95. Server Hostname:
  96. 192.168.31.31
  97.  
  98.  
  99. Server Port:
  100. 80
  101.  
  102.  
  103. Document Path:
  104. /api/Get_Poems/testname
  105.  
  106.  
  107. Document Length:
  108. 3954 bytes
  109.  
  110.  
  111. Concurrency Level:
  112. 1000
  113.  
  114.  
  115. Time taken for tests:
  116. 403.656 seconds
  117.  
  118.  
  119. Complete requests:
  120. 100000
  121.  
  122.  
  123. Failed requests:
  124. 0
  125.  
  126.  
  127. Total transferred:
  128. 432500000 bytes
  129.  
  130.  
  131. HTML transferred:
  132. 395400000 bytes
  133.  
  134.  
  135. Requests per second:
  136. 247.74
  137.  
  138.  
  139. Transfer rate:
  140. 1046.34 kb/s received
  141.  
  142.  
  143. Connnection Times (ms)
  144.  
  145.  
  146.  
  147. avg
  148.  
  149.  
  150. Connect:
  151. 0
  152. 3
  153. 1003
  154.  
  155.  
  156. Processing:
  157. 41
  158. 4015
  159. 11450
  160.  
  161.  
  162. Total:
  163. 41
  164. 4018
  165. 12453
  166.  
  167.  
  168.  
  169. This is ApacheBench, Version 2.<$Revision: 1748469 $>
  170. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  171. Licensed to The Apache Software Foundation, http://www.apache.org/
  172.  
  173.  
  174.  
  175. Server Software:
  176. nginx
  177.  
  178.  
  179. Server Hostname:
  180. 192.168.31.31
  181.  
  182.  
  183. Server Port:
  184. 80
  185.  
  186.  
  187. Document Path:
  188. /api/Get_Poems/testname
  189.  
  190.  
  191. Document Length:
  192. 3954 bytes
  193.  
  194.  
  195. Concurrency Level:
  196. 1000
  197.  
  198.  
  199. Time taken for tests:
  200. 439.615 seconds
  201.  
  202.  
  203. Complete requests:
  204. 100000
  205.  
  206.  
  207. Failed requests:
  208. 0
  209.  
  210.  
  211. Total transferred:
  212. 432500000 bytes
  213.  
  214.  
  215. HTML transferred:
  216. 395400000 bytes
  217.  
  218.  
  219. Requests per second:
  220. 227.47
  221.  
  222.  
  223. Transfer rate:
  224. 960.76 kb/s received
  225.  
  226.  
  227. Connnection Times (ms)
  228.  
  229.  
  230.  
  231. avg
  232.  
  233.  
  234. Connect:
  235. 0
  236. 4
  237. 1018
  238.  
  239.  
  240. Processing:
  241. 54
  242. 4369
  243. 8899
  244.  
  245.  
  246. Total:
  247. 54
  248. 4373
  249. 9917
  250.  
  251.  
  252.  
  253. This is ApacheBench, Version 2.<$Revision: 1748469 $>
  254. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  255. Licensed to The Apache Software Foundation, http://www.apache.org/
  256.  
  257.  
  258.  
  259. Server Software:
  260. nginx
  261.  
  262.  
  263. Server Hostname:
  264. 192.168.31.31
  265.  
  266.  
  267. Server Port:
  268. 80
  269.  
  270.  
  271. Document Path:
  272. /api/Get_Poems/testnameredis
  273.  
  274.  
  275. Document Length:
  276. 3954 bytes
  277.  
  278.  
  279. Concurrency Level:
  280. 1000
  281.  
  282.  
  283. Time taken for tests:
  284. 413.356 seconds
  285.  
  286.  
  287. Complete requests:
  288. 100000
  289.  
  290.  
  291. Failed requests:
  292. 0
  293.  
  294.  
  295. Total transferred:
  296. 432500000 bytes
  297.  
  298.  
  299. HTML transferred:
  300. 395400000 bytes
  301.  
  302.  
  303. Requests per second:
  304. 241.92
  305.  
  306.  
  307. Transfer rate:
  308. 1021.79 kb/s received
  309.  
  310.  
  311. Connnection Times (ms)
  312.  
  313.  
  314.  
  315. avg
  316.  
  317.  
  318. Connect:
  319. 0
  320. 3
  321. 1009
  322.  
  323.  
  324. Processing:
  325. 45
  326. 4113
  327. 5439
  328.  
  329.  
  330. Total:
  331. 45
  332. 4116
  333. 6448
  334.  
  335.  
  336.  
  337. This is ApacheBench, Version 2.<$Revision: 1748469 $>
  338. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  339. Licensed to The Apache Software Foundation, http://www.apache.org/
  340.  
  341.  
  342.  
  343. Server Software:
  344. nginx
  345.  
  346.  
  347. Server Hostname:
  348. 192.168.31.31
  349.  
  350.  
  351. Server Port:
  352. 80
  353.  
  354.  
  355. Document Path:
  356. /api/Get_Poems/testnameredis
  357.  
  358.  
  359. Document Length:
  360. 3954 bytes
  361.  
  362.  
  363. Concurrency Level:
  364. 1000
  365.  
  366.  
  367. Time taken for tests:
  368. 445.139 seconds
  369.  
  370.  
  371. Complete requests:
  372. 100000
  373.  
  374.  
  375. Failed requests:
  376. 0
  377.  
  378.  
  379. Total transferred:
  380. 432500000 bytes
  381.  
  382.  
  383. HTML transferred:
  384. 395400000 bytes
  385.  
  386.  
  387. Requests per second:
  388. 224.65
  389.  
  390.  
  391. Transfer rate:
  392. 948.83 kb/s received
  393.  
  394.  
  395. Connnection Times (ms)
  396.  
  397.  
  398.  
  399. avg
  400.  
  401.  
  402. Connect:
  403. 0
  404. 4
  405. 1007
  406.  
  407.  
  408. Processing:
  409. 41
  410. 4429
  411. 6390
  412.  
  413.  
  414. Total:
  415. 41
  416. 4433
  417. 7397
  418.  
  419.  
  420.  
  421. This is ApacheBench, Version 2.<$Revision: 1748469 $>
  422. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  423. Licensed to The Apache Software Foundation, http://www.apache.org/
  424.  
  425.  
  426.  
  427. Server Software:
  428. nginx
  429.  
  430.  
  431. Server Hostname:
  432. 192.168.31.31
  433.  
  434.  
  435. Server Port:
  436. 80
  437.  
  438.  
  439. Document Path:
  440. /api/Get_Poems/testnameredis
  441.  
  442.  
  443. Document Length:
  444. 3954 bytes
  445.  
  446.  
  447. Concurrency Level:
  448. 1000
  449.  
  450.  
  451. Time taken for tests:
  452. 432.107 seconds
  453.  
  454.  
  455. Complete requests:
  456. 100000
  457.  
  458.  
  459. Failed requests:
  460. 0
  461.  
  462.  
  463. Total transferred:
  464. 432500000 bytes
  465.  
  466.  
  467. HTML transferred:
  468. 395400000 bytes
  469.  
  470.  
  471. Requests per second:
  472. 231.42
  473.  
  474.  
  475. Transfer rate:
  476. 977.45 kb/s received
  477.  
  478.  
  479. Connnection Times (ms)
  480.  
  481.  
  482.  
  483. avg
  484.  
  485.  
  486. Connect:
  487. 0
  488. 4
  489. 1054
  490.  
  491.  
  492. Processing:
  493. 41
  494. 4293
  495. 5681
  496.  
  497.  
  498. Total:
  499. 41
  500. 4297
  501. 6735

 

前台的访问数据丢包率都是0%。棒棒的;

 

但是差异还是有的,redis数据库是调用的内存中的数据,而没有的时候使用的是MySQL中直接查询,所以会使用过多的CPU和系统资源。所以后台的系统监控数据就十分的美好了;

 

首先是磁盘IO方面,6此均有一个写入的小波峰,这个是因为开启了think PHP中的log功能,所以有个波峰,可以忽略不记

 

这个网络参数就有点不同了,上行明显变高了,这个不在这次的问题中提及。下次分析来进行操作

因为MySQL数据库是需要CPU参与的,所以前3次和后3次的差异一下就显现了

 

内存方面不好看到,但是有个小波动,因为我提前就是用了redis加载了数据,所以内存值不变,但是确实小号掉了保存数据的内存,大内存基数大的情况下不大容易显现,小内存就可以看到了

负载和资源使用表就很容易看出来了,波峰的峰值就是特别明显

 

 

所以在服务器优化了之后,如果MySQL数据量比较小的情况下【对于测试服务器配置10w的数据量确实小】;前端访问几乎就没有明显的差异,具体的差异在服务器的资源消耗上,如果是小配置的服务器估计就可以看到点差异了,但是这个一个消耗CPU一个消耗内存,具体就要看具体业务了,

 

如果是浏览类的业务的话用redis可以在内存和资源允许的情况下使用,但是如果是例如我们是景点票务系统的,一个数据也就用个3~4次然后他的使命就完成了的话还是不要用了。之前测试时连数据量的索引我都没有用,因为索引还要有个添加事件,这样更拖慢了服务器的响应速度,如果票务系统的接口还要等待OTA接口的反馈值的话,那么就更加没有办法使用这个数据了 使用队列MQ 处理业务的话就更舒适了

 

 

 

 

 

 

 

 

 

 

说说梦想,谈谈感悟 ,聊聊技术,有啥要说的来github留言吧 https://github.com/cjx2328

—— 陈 建鑫

陈建鑫
你可能也喜欢Related Posts
footer logo
未经许可请勿自行使用、转载、修改、复制、发行、出售、发表或以其它方式利用本网站之内容。站长联系:cjx2328#126.com(修改#为@)
Copyright ©ziao Studio All Rights Reserved. E-mail:cjx2328#126.com(#号改成@) 沪ICP备14052271号-3