国产欧美日韩第一页|日本一二三不卡视频|在线精品小视频,亚洲第一免费播放区,metcn人体亚洲一区,亚洲精品午夜视频

幫助中心 >  技術(shù)知識(shí)庫 >  云服務(wù)器 >  服務(wù)器教程 >  nginx日志request_time 和upstream_response_time區(qū)別

nginx日志request_time 和upstream_response_time區(qū)別

2016-10-14 17:20:55 10245

筆者在根據(jù)nginx的accesslog中$request_time進(jìn)行程序優(yōu)化時(shí),發(fā)現(xiàn)有個(gè)接口,直接返回?cái)?shù)據(jù),平均的$request_time也比較大。原來$request_time包含了用戶數(shù)據(jù)接收時(shí)間,而真正程序的響應(yīng)時(shí)間應(yīng)該用$upstream_response_time。

下面介紹下2者的差別:

1、request_time

官網(wǎng)描述:request processing time in seconds with a milliseconds resolution; time elapsed between the first bytes were read from the client and the log write after the last bytes were sent to the client 。
指的就是從接受用戶請(qǐng)求的第一個(gè)字節(jié)到發(fā)送完響應(yīng)數(shù)據(jù)的時(shí)間,即包括接收請(qǐng)求數(shù)據(jù)時(shí)間、程序響應(yīng)時(shí)間、輸出
響應(yīng)數(shù)據(jù)時(shí)間。

2、upstream_response_time

官網(wǎng)描述:keeps times of responses obtained from upstream servers; times are kept in seconds with a milliseconds resolution. Several response times are separated by commas and colons like addresses in the $upstream_addr variable

是指從Nginx向后端(php-cgi)建立連接開始到接受完數(shù)據(jù)然后關(guān)閉連接為止的時(shí)間。

從上面的描述可以看出,$request_time肯定比$upstream_response_time值大,特別是使用POST方式傳遞參數(shù)時(shí),因?yàn)镹ginx會(huì)把request body緩存住,接受完畢后才會(huì)把數(shù)據(jù)一起發(fā)給后端。所以如果用戶網(wǎng)絡(luò)較差,或者傳遞數(shù)據(jù)較大時(shí),$request_time會(huì)比$upstream_response_time大很多。

所以如果使用nginx的accesslog查看php程序中哪些接口比較慢的話,記得在log_format中加入$upstream_response_time。


提交成功!非常感謝您的反饋,我們會(huì)繼續(xù)努力做到更好!

這條文檔是否有幫助解決問題?

非常抱歉未能幫助到您。為了給您提供更好的服務(wù),我們很需要您進(jìn)一步的反饋信息:

在文檔使用中是否遇到以下問題: