简体   繁体   English

为什么WEBrick服务器在生产模式下比在开发模式下更快? +滑轨

[英]Why WEBrick server is faster in production mode rather in development mode? + Rails

I have been developing ruby on rails application since some couple of months. 自几个月以来,我一直在开发ruby on rails应用程序ruby on rails I use the default WEBrick server to run the applications. 我使用默认的WEBrick服务器来运行应用程序。 And I found that when I start the WEBrick server in the development and production modes, the server works more speed for production mode than for the development mode . 我发现当我在developmentproduction模式下启动WEBrick服务器时,服务器的production mode速度比development mode更快。

Is there any specific reason behind that? 这背后有什么具体原因吗? Can anybody explain me? 有人可以解释一下吗?

In dev mode classes are not cached, so Rails reloads all the classes each time you refresh. 在开发人员模式下,类不会被缓存,因此Rails每次刷新时都会重新加载所有类。 Also, asset compilation is not done in development (by default), so Rails reloads all the assets (CSS, Javascript etc) each time you refresh. 此外,资产编译不是在开发中完成的(默认情况下),因此每次刷新时Rails都会重新加载所有资产(CSS,Javascript等)。

In production mode, a server loads code into the cache, which makes things quick. 在生产模式下,服务器将代码加载到缓存中,这使事情变得很快。 However, that's not the case in development mode (since you don't want to restart your webrick every time you made a change). 但是,在开发模式中并非如此(因为每次进行更改时都不想重新启动webrick)。 Every request loads the according code again, which takes a bit of time. 每个请求都会再次加载相应的代码,这需要一些时间。

And the most of all time-eaters is the asset pipeline. 而且大多数时间都是资产管道。 In production, you get a compiled version of your assets (javascripts and css) in maybe one or two requests. 在生产中,您可能会在一两个请求中获得资产(javascript和css)的编译版本。 In development, you get them split, for debugging purpose (based on your environment settings, of course). 在开发中,出于调试目的(当然取决于您的环境设置),您将它们拆分了。 And because a browser does not handle all requests simultaneously, some assets are loaded after other ones are finished loading. 而且由于浏览器不能同时处理所有请求,因此某些资产在其他资产完成加载后才被加载。 You can watch this behaviour with eg firebug's network console. 您可以使用例如firebug的网络控制台来观察此行为。 That means: the more assets you have, the longer your page takes to load in development mode. 这意味着:您拥有的资产越多,页面在开发模式下加载所需的时间就越长。

The difference is between 2 environments. 区别在于两种环境。 In Rails, there are several environment. 在Rails中,有几种环境。 Each has his own database configuration and Rails options. 每个都有自己的数据库配置和Rails选项。

You can use the Rails.env variable to made some different change with particular environment. 您可以使用Rails.env变量对特定环境进行一些不同的更改。

By default, the development environment is without all cache and activate the auto-reloading. 默认情况下,开发环境没有所有缓存并激活自动重新加载。 The production environment is with all cache. 生产环境包含所有缓存。

But if you want you can make a production environment like development or development environment like production. 但是如果你想要你可以创建像生产这样的开发或开发环境的生产环境。

You can add some new specific environment too. 您也可以添加一些新的特定环境。

Creating new Environment: 创造新环境:

Assuming you want create the hudson environment. 假设您要创建哈德逊环境。

Create a new environment file in config/environments/hudson.rb. 

You can start by cloning an existing one, for instance config/environments/test.rb. 您可以从克隆现有的文件(例如config / environments / test.rb)开始。 Add a new configuration block in config/database.yml for your environment. 在config / database.yml中为您的环境添加新配置块。 That's all. 就这样。

Now you can start the server 现在您可以启动服务器了

ruby script/server -e hudson 红宝石脚本/服务器-e hudson

Run the console 运行控制台

ruby script/server hudson ruby脚本/服务器哈德森

And so on. 等等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在webrick服务器上的生产模式下运行rails - Running rails on a Production mode in webrick server 在Rails的开发模式中使用WEBrick有什么好处吗? - Is there any advantage to using WEBrick in development mode for Rails? Rails 4-服务器在开发模式下工作,但不在生产模式下工作 - Rails 4 - server works in development mode, but not in production Rails 3 - 生产模式中的开发错误 - Rails 3 - development errors in production mode Rails在生产模式下抛出NoMethodError,但是在开发模式下却没有 - Rails throw NoMethodError in production mode but not in development mode Rails 4 App-JS在开发模式下可与Webrick一起使用,但不适用于Passenger / Apache2 - Rails 4 App - JS works with Webrick but not Passenger/Apache2 in Development Mode 如何在开发模式下控制Rails / Webrick调试日志记录? - How can I control rails/webrick debug logging in development mode? 在开发模式下,Rails不会在Webrick上提供静态内容 - Rails won't serve static content on Webrick in development mode Rails 服务器在开发模式下工作,但不在生产模式下 - Rails server works in dev mode but not in production mode Rails 5.2.3 / Heroku-为什么在开发模式下使用squlite3无法在生产模式下运行postgres? - Rails 5.2.3 / Heroku - Why is it not possible to run postgres in production mode with squlite3 in development mode?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM