设置log_format,添加request_time,$upstream_response_time,位置随意
og_format main '"$request_time" "$upstream_response_time" $remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
日志输出效果:
"0.015" "0.015" 10.1.2.3 - - [20/Mar/2017:04:05:49 +0800] "GET /myApp/servlet/TestServlet HTTP/1.1" 200 52 "-" "Mozilla/4.0 (compatible; MSIE 4.0; Windows NT)" "-"
-------------------------------------------------------------------------------
笔者在根据nginx的accesslog中$request_time进行程序优化时,发现有个接口,直接返回数据,平均的$request_time也比较大。原来$request_time包含了用户数据接收时间,而真正程序的响应时间应该用$upstream_response_time。
下面介绍下2者的差别:
1、request_time
官网描述: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 。
指的就是从接受用户请求的第一个字节到发送完响应数据的时间,即包括接收请求数据时间、程序响应时间、输出
响应数据时间。
2、upstream_response_time
官网描述: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)建立连接开始到接受完数据然后关闭连接为止的时间。
从上面的描述可以看出,$request_time肯定比$upstream_response_time值大,特别是使用POST方式传递参数时,因为Nginx会把request body缓存住,接受完毕后才会把数据一起发给后端。所以如果用户网络较差,或者传递数据较大时,$request_time会比$upstream_response_time大很多。
所以如果使用nginx的accesslog查看php程序中哪些接口比较慢的话,记得在log_format中加入$upstream_response_time。
参考:
nginx优化之request_time 和upstream_response_time差别
http://wuzhangshu927.blog.163.com/blog/static/114224687201310674652147/
相关推荐
nginx优化之request_time 和upstream_response_time差别笔者在根据nginx的accesslog中$request_time
官方nginx 镜像不带主动健康,本镜像将 nginx_upstream_check健康检查 打包到了镜像中。
包含yamdi-1.9.tar.gz nginx_mod_h264_streaming-2.2.7.tar.gz nginx-1.8.1
linux nginx nginx_upstream_jvm_route
lua-upstream-nginx-module, Nginx C 模块将Lua向ngx_lua公开,用于 Nginx upstreams 电子邮件名称ngx_http_lua_upstream - Nginx MODULE,用于向 Nginx upstreams公开Lua到 ngx_lua目录NAME状态概要说明函数get_...
该指令在nginx-1.9.0-plus中可用。地位生产准备就绪。指令dynamic_upstream 句法dynamic_upstream 默认-- 语境地点现在, ngx_dynamic_upstream仅在http上下文下支持动态上游。快速开始upstream backends { zone ...
Nginx所需环境的安装,及nginx安装,nginx相关功能开启,后端节点健康检查插件安装,静态资源缓存插件,缩略图插件安装等。
nginx_upstream_check_module健康检查的时间间隔是毫秒级,而且可以自定义监控url,定制监控页,响应速度快,比原生的敏感度要高。 Syntax: check interval=milliseconds [fall=count] [rise=count] [timeout=...
此资源有两个文件,含 nginx-upstream-jvm-route 和 nginx 对应版本,都是tar.gz文件。 安装方法网上很多就不写了,亲测可用。 不用担心版本不匹配造成安装失败,再浪费积分去到处下载尝试的烦恼。 此资源有两个文件...
NGINX第三方模块:nginx_upstream_hash-0.3.1.tar.gz。
nginx_upstream_check_module模块,2019年11月6日18:11:19下载的
nginx_upstream_check_module-master,淘宝技术团队开发的,适用1.11
nginx后端节点健康检查模块插件,非常好用,淘宝开发。
nginx upstream 连接池 ngx_http_upstream_keepalive-d9ac9ad67f45.tar.gz
在此记录下Nginx服务器nginx.conf的配置文件说明, 部分注释收集与网络. #运行用户 user www-data; #启动进程,通常设置成和cpu的数量相等 worker_processes 1; #全局错误日志及PID文件 error_log /var/log/...
nginx_tcp_proxy_module-master.zip
nginx_mod_h264_streaming-2.2.7,MP4流媒体支持模块
NGINX第三方模块:nginx_upstream_hash-0.3.2版本。。。
Nginx日志描述 通过访问日志,你可以得到用户地域来源、跳转来源、使用终端、某个URL访问量等相关信息;通过错误日志,你可以得到系统某个服务或server的性能瓶颈等。因此,将日志好好利用,你可以得到很多有价值的...