[英]Why is Rails middleware overhead so high when nginx is used as a proxy?
Thanks to Godfrey Chan for the helpful insights I got from him so far. 感谢Godfrey Chan对我迄今为止所获得的有益见解。 He pointed me to the fact that there's a Rack middleware that will provide me more accurate timing about the whole Rails request in the X-Runtime HTTP header in the response, when compared to the reported time in the logs (Completed in XXXms...). 他向我指出,与报告的日志时间相比,有一个Rack中间件可以为我提供关于响应中X-Runtime HTTP头中整个Rails请求的更准确的时间安排(在XXXms完成... )。
Here's what I get from my tests: 这是我从测试中得到的:
1 - Access the direct URL to the Rails action in Chrome: 1 - 访问Chrome中Rails操作的直接URL:
2 - Access the same URL but using nginx with proxy_pass, also in Chrome: 2 - 访问相同的网址,但在Chrome中也使用带有proxy_pass的nginx:
3 - Copying the Curl address from Chrome's developer tool and running it with curl -I: 3 - 从Chrome的开发人员工具中复制Curl地址并使用curl -I运行它:
Those timings are pretty much consistent when I try them a lot of times. 当我尝试很多次时,这些时间非常一致。
Any ideas why Rails will take longer to serve the same request if it goes through nginx proxy_pass? 任何想法为什么Rails需要更长的时间才能通过nginx proxy_pass提供相同的请求? I understand that Curl can't take advantage of features like keep-alive, but I believe nginx is able to get advantage of it. 据我所知,Curl无法利用keep-alive等功能,但我相信nginx能够充分利用它。 But anyway, the time to open a connection shouldn't be taken into account by X-Runtime header, right? 但无论如何,X-Runtime标头不应该考虑打开连接的时间,对吧?
我不能再重现这个问题了,所以不要介意研究它,除非你自己重现它并提供更多细节来调查它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.