另to shudu: 我之前配置keepalive_timeout 0,$request_time大部分显示 0.0xx -
0.3xx不等,改完60后所有的都是0.000了。
Hello!
2012/6/20 huangfxbupt <huang...@gmail.com>:
> 在keepalive_timeout设置(如60)情况下,access_log的$request_time显示几乎都为0.000,请问这种情况下怎么获取每个请求的真实request_time。多谢~
>
我用下面这个简单的配置不能复现你说的问题(同时在 Linux x86_64 上面尝试过了 nginx 1.0.15 和 1.2.1):
http {
keepalive_timeout 60;
log_format test '[$time_local] "$request" $status $request_time';
server {
listen 1984;
location /t {
access_log logs/access2.log test;
content_by_lua '
ngx.sleep(0.002)
';
}
}
}
使用 ab 的 HTTP 1.0 keepalive 功能连续请求 10 次 /t 得到的访问日志如下:
[20/Jun/2012:13:53:14 +0800] "GET /t HTTP/1.0" 200 0.002
[20/Jun/2012:13:53:14 +0800] "GET /t HTTP/1.0" 200 0.002
[20/Jun/2012:13:53:14 +0800] "GET /t HTTP/1.0" 200 0.002
[20/Jun/2012:13:53:14 +0800] "GET /t HTTP/1.0" 200 0.002
[20/Jun/2012:13:53:14 +0800] "GET /t HTTP/1.0" 200 0.002
[20/Jun/2012:13:53:14 +0800] "GET /t HTTP/1.0" 200 0.003
[20/Jun/2012:13:53:14 +0800] "GET /t HTTP/1.0" 200 0.002
[20/Jun/2012:13:53:14 +0800] "GET /t HTTP/1.0" 200 0.002
[20/Jun/2012:13:53:14 +0800] "GET /t HTTP/1.0" 200 0.002
[20/Jun/2012:13:53:14 +0800] "GET /t HTTP/1.0" 200 0.002
[20/Jun/2012:13:53:14 +0800] "GET /t HTTP/1.0" 200 0.002
可以看到最后一列记录的时间符合预期。
我使用的 ab 命令行是
ab -c1 -n10 -k localhost:1984/t
ab 生成的报告中显示 HTTP 1.0 keepalive 确实生效了:
Keep-Alive requests: 10
使用 weighttp 工具发起 HTTP 1.1 keepalive 请求或者手工 telnet 处理之,也可以得到类似的结果:
[20/Jun/2012:13:53:59 +0800] "GET /t HTTP/1.1" 200 0.002
[20/Jun/2012:13:53:59 +0800] "GET /t HTTP/1.1" 200 0.002
[20/Jun/2012:13:53:59 +0800] "GET /t HTTP/1.1" 200 0.002
[20/Jun/2012:13:53:59 +0800] "GET /t HTTP/1.1" 200 0.002
[20/Jun/2012:13:53:59 +0800] "GET /t HTTP/1.1" 200 0.002
[20/Jun/2012:13:53:59 +0800] "GET /t HTTP/1.1" 200 0.002
[20/Jun/2012:13:53:59 +0800] "GET /t HTTP/1.1" 200 0.002
[20/Jun/2012:13:53:59 +0800] "GET /t HTTP/1.1" 200 0.002
[20/Jun/2012:13:53:59 +0800] "GET /t HTTP/1.1" 200 0.002
[20/Jun/2012:13:53:59 +0800] "GET /t HTTP/1.1" 200 0.002
所以需要你提供关于此问题的更多信息,包括 nginx 的版本号、主要的 nginx 配置等等。
Regards,
-agentzh
--
邮件自: 列表“openresty”,专用于技术讨论!
发言: 请发邮件到 openresty@googlegroups.com
退订: 请发邮件至 openresty+unsubscribe@googlegroups.com
详情: http://groups.google.com/group/openresty
官网: http://openresty.org/
仓库: https://github.com/agentzh/ngx_openresty
建议: 提问的智慧 http://wiki.woodpecker.org.cn/moin/AskForHelp
教程: http://agentzh.org/misc/nginx/agentzh-nginx-tutorials-zhcn.html