简体   繁体   English

当nginx用作代理时,为什么Rails中间件开销如此之高?

[英]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:

  • X-Runtime: 25ms X-Runtime:25ms
  • Chrome "Waiting" time: 27ms Chrome“等待”时间:27ms
  • Reported time in the Rails log format: Completed 200 OK in 7ms (Views: 0.9ms | Sequel: 3.0ms) Rails日志格式的报告时间:7ms完成200 OK(浏览次数:0.9ms |续集:3.0ms)

2 - Access the same URL but using nginx with proxy_pass, also in Chrome: 2 - 访问相同的网址,但在Chrome中也使用带有proxy_pass的nginx:

  • X-Runtime: 84ms X-Runtime:84ms
  • Chrome "Waiting" time: 88ms Chrome“等待”时间:88毫秒
  • Completed 200 OK in 7ms (Views: 0.8ms | Sequel: 2.9ms) 在7ms完成200 OK(浏览次数:0.8ms |续集:2.9ms)

3 - Copying the Curl address from Chrome's developer tool and running it with curl -I: 3 - 从Chrome的开发人员工具中复制Curl地址并使用curl -I运行它:

  • X-Runtime: 105ms (sometimes it goes up to 400ms) X-Runtime:105ms(有时高达400ms)
  • Completed 200 OK in 88ms (Views: 2.0ms | Sequel: 5.5ms) 在88ms完成200 OK(浏览次数:2.0ms |续集:5.5ms)

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.

相关问题 如何配置nginx代理到rails应用程序?所以我不必说domain.com:port - How to config nginx to proxy to rails app? so that i dont have to say domain.com:port 在Rails代理中间件中添加身份验证信息 - Adding authentication info in Rails proxy middleware 如何在Rails Box上使用Nginx代理Angle App? - How to proxy angular app with nginx on a rails box? NGINX上的多个Rails应用程序(反向代理) - Multiple Rails apps over NGINX (reverse proxy) 配置nginx代理瘦和Rails ActionCable - Configuring nginx to proxy thin and Rails ActionCable 使用POW时,为什么Chrome渲染Rails页面如此缓慢? - Why is Chrome Rendering Rails Pages So Slowly When Using POW? (Nginx+Passenger) 运行线程的 Rails 与passenger_max_requests 设置一起使用时会被杀死 - (Nginx+Passenger) Rails running Threads get killed when used along with passenger_max_requests setting 为什么在Ruby on Rails中使用“ awk”命令不将任何内容返回变量? - Why 'awk' command is not returning anything to variable when used in Ruby on rails? 如何获取在Rails应用中运行的二手Rack中间件的对象 - How to get objects of used Rack middleware running in a Rails app 什么是中间件在Ruby on Rails的上下文中引用? - What is middleware when referenced in the context of Ruby on Rails?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM