为什么在 Rails 应用程序中使用生产而不是开发

发布于 2024-10-01 06:18:23 字数 45 浏览 3 评论 0原文

两者之间有什么重大区别吗?我还没有看到一个文档来解释主要区别是什么?表现??

Are there any major differences between the two? I have yet to see a doc that explains what the major difference is? Performance??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

以酷 2024-10-08 06:18:24

“开发”和“生产”的运作模式之间存在显着差异,即使两者表面上看起来相似。

在开发模式下,app/config/routes.rb 中的任何文件都会随每个请求重新加载。这可能需要花费相当多的时间来处理,但其优点是可以根据代码库的任何更改生成最新的响应,这可能是在开发环境中正在进行的。由于生产环境不应在部署之间发生变化,Rails 将缓存您的控制器、视图、路由、帮助程序和模型,以获得最佳性能。对源的任何更改都需要重新启动应用程序。

开发的另一个特点是 Rails 日志记录级别设置为尽可能详细的调试。您不仅可以获得每个 SQL 调用的详细分类,还可以获得小警告和其他信息性消息,否则这些消息将在生产中被忽略。此日志记录会对性能造成相当大的拖累,除非您尝试诊断问题,否则不应在生产环境中使用。这些日志文件很快就会变得非常大,并且在不重新启动 Web 服务器进程的情况下很难轮换它们。

开发环境中还有一种方法可以挽救异常并将其呈现为人类可读的错误报告。这对于调试很有用,但在生产环境中可能会暴露有关应用程序的敏感详细信息,因为它通常包含有关文件系统、关键参数等的大量信息。永远不应该在生产站点上启用此功能。

这些差异可能并不明显,但您只需比较 config/environments/development.rb 和 config/environments/development.rb 中的配置设置即可。不幸的是,一些默认值是什么并不明显,因为有时它们在这些文件中没有清楚地表达,但基本知识通常都在那里。

There are significant differences between "development" and "production" modes of operation even if the two seem superficially similar.

In development mode any file in app/ and config/routes.rb is reloaded with each request. This can take a considerable amount of time to process, but has the advantage of producing an up-to-date response based on any changes to your code-base, something that is presumably on-going in a development environment. Since the production environment should not change between deployments, Rails will cache your controllers, views, routes, helpers and models for maximum performance. Any changes to the source will require an application restart.

Another feature of development is that the Rails logging level is set to debug which is as verbose as possible. Not only do you get a detailed breakdown of every SQL call made, but you also get minor warnings and other informative messages that would otherwise be omitted in production. This logging is a considerable drag on performance and should not be used in a production environment unless you're trying to diagnose a problem. These log files get very big very quickly and it can be difficult to rotate them without restarting your web server processes.

There is also a method in the development environment to rescue from exceptions and render them as a human-readable error report. This is useful for debugging, but in a production environment may expose sensitive details about your application as it often includes a lot of information about the filesystem, key parameters, and so on. This should never be enabled on a production site.

These differences may not be obvious, but you simply need to compare the configuration settings in config/environments/development.rb and config/environments/production.rb. Unfortunately it is not obvious what some of the defaults are, as they are not expressed clearly in these files sometimes, but the basics are usually there.

森林很绿却致人迷途 2024-10-08 06:18:24

在 Rails 生产环境中,您的应用程序代码会被缓存,因此解释器不必在每次调用方法时重新加载您的类。您的应用程序基本上存储在内存中。这带来了明显的速度提升。

此外,它默认执行的日志记录要少得多;例如,生产日志不像开发日志那样包含每个 SQL 调用。

In Rails production environment, your app code is cached, so the interpreter doesn't have to reload your classes every time it calls a method. Your app is basically stored in memory. This gives definite speed improvements.

Also, it does a lot less logging by default; for example, production logs don't contain every single sql call like your development logs do.

鼻尖触碰 2024-10-08 06:18:24

缓存和错误处理。

Caching & error handling.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文