Ubuntu 上的 Phusion 乘客内存消耗从 1.9.3(系统)增加到 2.1.2(RVM) [英] Phusion Passenger memory consumption increase from 1.9.3 (system) to 2.1.2 (RVM) on Ubuntu

查看:56
本文介绍了Ubuntu 上的 Phusion 乘客内存消耗从 1.9.3(系统)增加到 2.1.2(RVM)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有 512MB 物理 RAM 和 512MB 交换空间的 Ubuntu 系统.使用单用户(我的用户)RVM Ruby 2.1.2 在Passenger 4.0.45 服务器(Apache 模块)上运行我的四个Rails 3.2.12 应用程序,它使用的内存比我将Passenger 配置为使用旧系统(根)Ruby 1.9.3.这是乘客配置的唯一区别.

I have an Ubuntu system with 512MB physical RAM and 512MB swap. Running my four Rails 3.2.12 apps on Passenger 4.0.45 server (Apache module) using single-user (my user) RVM Ruby 2.1.2, it uses about 30% more memory than when I configure Passenger to use the older system (root) Ruby 1.9.3. That is the only difference in the Passenger config.

这会导致Passenger在访问时将其他应用程序移动到swap,这意味着每次访问不同的应用程序时,都必须从swap加载,从而导致延迟.这意味着如果同时使用多个应用程序,我几乎会耗尽内存,并且它们对用户的反应很慢.

This causes Passenger to move other applications to swap when one is accessed, which means each time a different application is accessed, it has to be loaded in from swap, resulting in a delay. This means that I almost run out of memory if multiple apps are being used concurrently, and they react slowly to users.

我不明白为什么使用 RVM 会导致乘客使用更多内存.我怀疑是因为 Ruby 2.1.2,除非我需要调整内存参数.

I can't understand why using RVM causes Passenger to use more memory. I doubt it is because of Ruby 2.1.2 unless there are memory parameters I need to tune.

推荐答案

与 2.0.0 相比,ruby 2.1.2 的开箱即用设置确实增加了内存使用(如果您不要考虑 2.0.0 中写入改进的副本)

The out of the box settings for ruby 2.1.2 do increase memory use compared to 2.0.0 (which I believe was on par with 1.9.3 if you don't consider the copy on write improvements in 2.0.0)

原因是 Ruby 2.1 引入了新的垃圾收集算法.简而言之,该算法假定,虽然某些对象存在很长时间(例如代表您的代码的对象),但其他对象的存在时间很短.较旧的 ruby​​ 会花很长时间尝试查看是否所有对象都已准备好进行垃圾回收,而 ruby​​ 2.1 在次要收集(仅尝试收集短寿命对象)和主要收集(尝试收集长寿命对象)之间切换.

The reason is that Ruby 2.1 introduced a new garbage collection algorithm. In a nutshell the algorithm assumes that while some objects live for a long time (eg the objects representing your code) others are very short lived. Older rubies would spend a long time trying to see whether all objects were ready to be garbage collected, whereas ruby 2.1 switches between minor collections (only try to collect the short lived objects) and major collections (try to collect the long lived ones).

这会以一些内存使用为代价提高性能(次要集合要快得多).

This increases performance (minor collections are much faster) at the expense of some memory usage.

您可以使用(除其他外)RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR 环境变量进行调整.默认值为 2,设置为 0.9 会关闭分代垃圾收集器,介于两者之间的数字将牺牲内存以换取性能.

You can tune this, using (among others) the RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR environment variable. The default is 2, a setting of 0.9 turns off the the generational garbage collector and numbers in between will trade off memory for performance.

您还可以使用 jemalloc 库(在任何 ruby​​ 版本上)来获得一点性能并稍微减少内存使用量.

You can also use the jemalloc library (on any ruby version) to gain a little performance and reduce memory usage slightly.

rails 应用程序的最后一部分问题是,许多应用程序都拥有可以持续整个请求的中等生命对象——Ruby 尝试将对象分成两代是不够的.Ruby 2.2 计划对此进行改进.

Lastly part of the problem with rails apps is the many apps have what one might call medium lived objects that last for a whole request - Ruby's attempt to split objects into just 2 generations isn't quite sufficient. Ruby 2.2 is slated to improve on this.

Sam Saffron 有一个很棒的 发布如果你想阅读更多

Sam Saffron has a great post on this if you want to read more

此外,ruby 2.1.3 对 gc 计时进行了一些更改,与 2.1.2 相比,在大多数情况下减少了内存使用

In addition ruby 2.1.3 made some changes to gc timing that reduces memory uses in most cases compared to 2.1.2

这篇关于Ubuntu 上的 Phusion 乘客内存消耗从 1.9.3(系统)增加到 2.1.2(RVM)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆