php程序执行返回时间过长的原因

作者: dreamfly 分类: php,redis 发布时间: 2020-07-13 10:39

关闭xdebug

开发环境我们经常需要调试,因此xdebug我们经常开启,但是线上的环境,我们一定要关闭xdebug。在打开xdebug的时候,我们的程序返回时间平均在200ms以上,可以说非常的慢,但是当我们关掉xdebug的时候,你会发现,平均响应时间会缩短到10ms左右,可以说进20倍的提升,因此线上环境,一定要关闭xdebug,一定要关闭xdebug,一定要关闭xdebug。

mysql的读效率不低

使用redis

 ab -n 10000 -c 10000 http://testredis.com/

 Concurrency Level:      10000
Time taken for tests:   23.533 seconds
Complete requests:      10000
Failed requests:        5941
   (Connect: 0, Receive: 0, Length: 5941, Exceptions: 0)
Total transferred:      2274395 bytes
HTML transferred:       644395 bytes
Requests per second:    424.94 [#/sec] (mean)
Time per request:       23532.568 [ms] (mean)
Time per request:       2.353 [ms] (mean, across all concurrent requests)
Transfer rate:          94.38 [Kbytes/sec] received

使用mysql

 ab -n 10000 -c 10000 http://testredis.com/

 Concurrency Level:      10000
Time taken for tests:   19.323 seconds
Complete requests:      10000
Failed requests:        122
   (Connect: 0, Receive: 0, Length: 122, Exceptions: 0)
Total transferred:      2006710 bytes
HTML transferred:       376710 bytes
Requests per second:    517.52 [#/sec] (mean)
Time per request:       19322.764 [ms] (mean)
Time per request:       1.932 [ms] (mean, across all concurrent requests)
Transfer rate:          101.42 [Kbytes/sec] received

从上面可以看出,mysql的读请求RPS并不弱于redis

写请求更适合redis

ab -n 10000 -c 10000 http://testredis.com/

redis写请求

Concurrency Level:      10000
Time taken for tests:   18.337 seconds
Complete requests:      10000
Failed requests:        1910
   (Connect: 0, Receive: 0, Length: 1910, Exceptions: 0)
Total transferred:      1834820 bytes
HTML transferred:       204820 bytes
Requests per second:    545.34 [#/sec] (mean)
Time per request:       18337.051 [ms] (mean)
Time per request:       1.834 [ms] (mean, across all concurrent requests)
Transfer rate:          97.72 [Kbytes/sec] received

mysql写请求

Concurrency Level:      10000
Time taken for tests:   19.141 seconds
Complete requests:      10000
Failed requests:        18
   (Connect: 0, Receive: 0, Length: 18, Exceptions: 0)
Total transferred:      1641638 bytes
HTML transferred:       11638 bytes
Requests per second:    522.45 [#/sec] (mean)
Time per request:       19140.566 [ms] (mean)
Time per request:       1.914 [ms] (mean, across all concurrent requests)
Transfer rate:          83.76 [Kbytes/sec] received

使用常驻内存

如果每次请求之后资源都销毁,自然会降低响应速度,因此,可以使用swoole 扩展来进行常驻内存,这样的话,将大大提升rps。

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!