本文介绍了对于Ruby on Rails,使用Webrick时,它支持并发请求和Keep-Alive吗?为什么加载.js和.png文件这么慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行Rails 3.0.5,并且在控制台上报告一个页面需要60毫秒,但是如果我查看Firefox Net加载时间图表,则需要2.9秒.如果我在Bash上运行ab命令,则说需要300毫秒.

I am running Rails 3.0.5, and a page is reported on the console that it take 60ms, but if I check the Firefox Net load time chart, it takes 2.9 seconds. If I run the ab command on Bash, it says it take 300ms.

因此,如果删除标准javascript(其中6个),则需要1.9秒...但是我想知道为什么这么慢吗?保持生命不是很荣幸吗?

So if remove the stand javascripts (6 of them), then it takes 1.9 seconds... but I wonder why so slow? Isn't keep-alive honored?

奇怪的是Firefox显示并发下载了4个文件-我认为Webrick一次仅支持1个连接吗?

Also strange is Firefox shows that 4 files are downloading concurrently -- I thought Webrick supports only 1 connection as a time?

(更改为使用杂种或瘦"东西会使事情变得不同或变得更好吗?)

(Will changing to using mongrel or "thin" make things any different or better?)

另一个奇怪的是,如果我

also strange is that if I

ab -n 10 -c 5 http://www.somesite.com:8080

需要3秒钟,并且要测试如何支持keep-alive,我使用了-k选项:

it takes 3 seconds, and to test how keep-alive is supported, I used the -k option:

ab -n 10 -c 5 -k http://www.somesite.com:8080

,但是现在总时间从3秒更改为4.5秒. keep-alive是否应该使其速度更快,并且Webrick是否支持keep-alive?

but now the total time changes from 3 seconds to 4.5 seconds. Isn't keep-alive supposed to make it faster, and is keep-alive supported by Webrick?

此外,如果它支持并发连接,那么如果某些代码使用类变量来处理事情,那么就不会发生竞争状况吗? (因为类变量的内容会保留在请求中)

Also, if it supports concurrent connection, then if some code uses a class variable to handle things, then can't there be race condition happening? (since class variable content stays across requests)

推荐答案

这不能完全回答您的问题,但是我将向您提供可能使您的问题不相关的建议.

This doesn't exactly answer your question, but I'm going to give you advice that probably makes your question irrelevant.

Webrick不应在生产中使用.它是用纯红宝石编写的,一次只能处理一个请求.请勿将其用于开发模式以外的任何地方.

Webrick should not be used in production. It is written in pure ruby and can only process one request at a time. It is not made to be used in anything outside of development mode.

对于生产而言,您想要在反向代理(如nginx)后面使用多个Thin实例,或者可以使用为您做到这一点的乘客(这是当今大多数人所使用的).

For production, you want to use multiple instances of thin behind a reverse proxy like nginx, or you can use passenger which does this for you (and is what most people use in the modern day).

部分回答您的问题:

ab的运行速度比firefox快的原因是,请求CSS和javascript文件是浏览器的功能. ab只是基准化服务器的响应时间,不包括发送任何图像,css或js.

The reason ab is running faster than firefox is because requesting css and javascript files are a function of the browser. ab is only benchmarking the response time from the server, which doesn't include sending down any images, css, or js.

rails基准仅为60ms的原因是,它仅测量它在rails堆栈中的时间.它不计算将请求发送回用户所花费的时间.

The reason the rails benchmark is only 60ms is because it only measures the time it was in the rails stack. It does not count the time it takes to send the request back to the user.

因为webrick不是用于生产的,所以如果不支持keep-alive,也不会令我感到惊讶.

Because webrick isn't made for production, it wouldn't surprise me if keep-alive is not supported.

这篇关于对于Ruby on Rails,使用Webrick时,它支持并发请求和Keep-Alive吗?为什么加载.js和.png文件这么慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 17:45