简体   繁体   English

什么是nginx的$ request_time?为什么它比php-fpm执行时间多得多?

[英]What is nginx's $request_time and why is it a lot more than php-fpm execution time?

Background : It is the objective of my project is to create a very fast responding website. 背景 :我项目的目的是创建一个响应速度非常快的网站。 There are only very few pages, many of them are simply 302 redirects. 页面只有极少数,其中许多只是302重定向。

In Nginx , I'm logging here $request_time . Nginx中 ,我在这里记录$request_time

In PHP , I'm logging the microtime of the start of the request and just before it exits. PHP中,我记录了microtime只是在退出前请求的开始和。

php-fpm (php 5.3.27) and nginx (1.4.4) run on the same machine, there is no database (just writing to a Beanstalkd queue), there are no complicated nginx configurations. php-fpm (php 5.3.27)和nginx (1.4.4)在同一台机器上运行,没有数据库(仅写入Beanstalkd队列),没有复杂的nginx配置。

Problem : There is a massive discrepancy between the PHP execution time and Nginx's $request_time. 问题 :PHP执行时间与Nginx的$ request_time之间存在巨大差异。 The $request_time is generally 0.5 seconds but during some hours it's more like 3 seconds on average. $ request_time通常为0.5秒,但在某些小时 ,平均约为3秒 PHP's execution time is always between 0.008 seconds and 0.02 seconds (using PhalconPHP ). PHP的执行时间始终在0.008秒和0.02秒之间(使用PhalconPHP )。

Question : Why could there be such a big discrepancy? 问题 :为什么会有如此大的差异? Perhaps I don't fully understand what $request_time is, or maybe my webservers have some problematic configuration? 也许我不完全了解$request_time是什么,或者我的Web服务器的配置有问题吗? I'd be happy to provide more information about the environment. 我很乐意提供有关环境的更多信息。

$request_time is the time from the first byte sent, to the time everything is closed up and logging has been completed. $request_time是从发送第一个字节到关闭所有内容并完成日志记录的时间。 If you look at your nginx logs and the microtime you are logging, how close are they in terms of starting times? 如果查看您的nginx日志和所记录的时间,它们在开始时间上有多接近? For the ones where the request_time was closer to 3 seconds, and the php execution time was say 0.02 seconds, if you extrapolate the request start time and compare that to the microtime inside php, are they close, or did nginx need to wait a second or 2 (perhaps for a php process to free up, etc..). 对于request_time接近3秒且php执行时间为0.02秒的那些,如果您推断请求开始时间并将其与php中的microtime比较,它们是否关闭,或者nginx是否需要等待一秒钟或2(可能是php进程释放了,等等。)。 It would probably be interesting to also log the $upstream_response_time to see how that compares. 还要记录$upstream_response_time以查看两者之间的比较可能会很有趣。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM