slicehost 上 Rails 应用程序的交换问题
我有一个在 slicehost (256M) 上托管和运行的 Rails 2.3.8 应用程序。我对后端一点也不熟悉,我基本上是按照slicehost教程中的步骤安装Apache的。内存使用率非常高,然后我更改了 Apache conf 文件以将 MaxClient 数量减少到 10...但我的切片仍在交换。
以下是我在网站上点击几下后得到的内存使用情况:
top - 23:57:12 up 28 min, 2 users, load average: 0.43, 0.54, 0.30
Tasks: 79 total, 1 running, 78 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.1%us, 0.1%sy, 0.0%ni, 97.8%id, 0.1%wa, 0.0%hi, 0.0%si, 2.0%st
Mem: 262364k total, 258656k used, 3708k free, 260k buffers
Swap: 524280k total, 262772k used, 261508k free, 6328k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
4004 web-app 20 0 178m 72m 1888 S 0 28.4 0:04.38 ruby1.8
4001 web-app 20 0 172m 61m 1932 S 0 24.2 0:02.72 ruby1.8
3941 root 20 0 164m 57m 1672 S 0 22.5 0:21.44 ruby
3990 web-app 20 0 209m 21m 1696 S 0 8.4 0:18.00 ruby1.8
3950 web-app 20 0 165m 7464 1548 S 0 2.8 0:20.40 ruby1.8
3684 mysql 20 0 224m 6504 2084 S 0 2.5 0:14.34 mysqld
3938 root 20 0 53632 3048 1036 S 1 1.2 0:01.50 starling
3839 root 20 0 243m 1456 1248 S 0 0.6 0:00.34 apache2
3897 www-data 20 0 243m 1452 1072 S 0 0.6 0:00.04 apache2
3894 www-data 20 0 243m 1368 1008 S 0 0.5 0:00.04 apache2
3895 www-data 20 0 243m 1220 960 S 0 0.5 0:00.02 apache2
3888 root 20 0 46520 1204 1100 S 0 0.5 0:02.29 ruby1.8
3866 root 20 0 17648 1184 896 S 0 0.5 0:00.08 bash
3896 www-data 20 0 243m 1180 952 S 0 0.4 0:00.00 apache2
3964 www-data 20 0 243m 1164 956 S 0 0.4 0:00.02 apache2
3892 www-data 20 0 243m 1132 956 S 0 0.4 0:00.00 apache2
3948 www-data 20 0 243m 1132 956 S 0 0.4 0:00.00 apache2
3962 www-data 20 0 243m 1132 956 S 0 0.4 0:00.02 apache2
3963 www-data 20 0 243m 1132 956 S 0 0.4 0:00.00 apache2
3965 www-data 20 0 243m 1080 888 S 0 0.4 0:00.00 apache2
3887 root 20 0 89008 960 796 S 0 0.4 0:00.00 ApplicationPool
我不知道下一步该做什么...我可以升级到更大的切片,但目前我在这个应用程序上几乎没有流量,所以我认为这更多是我的配置或我的代码的问题?
欢迎任何具体建议! 谢谢
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您的 Rails 应用程序正在使用所有可用内存。我建议三件事:
升级服务器上的内存。对于 Rails 应用程序来说 256MB 并不算多。拨打 512 可能会缓解您的问题。如果这解决了问题,那么您需要考虑额外的成本(18 美元/月)与跟踪性能问题所需的时间。
分析您的应用程序以找出哪些请求消耗最多的内存。您可能会在此处找到大量记录,并且可能还包括一些关联的表。有一些工具可以帮助您缩小可能出现问题的范围。我使用过 oink 但肯定还有其他。一旦找出问题所在,您就可以进行一些调整来尝试减少内存使用量。
假设您将 Passenger 与 Apache 一起使用,您可以减少 Passenger 配置文件中的并发请求数。这对于 https:// serverfault.com/questions/15350/running-ruby-on-rails-app-on-apache-passenger-to-much-memory
It looks like your rails app is using all your available memory. I would recommend three things:
Upgrade the memory on your server. 256MB is not very much for a Rails app. Going to 512 may alleviate your problem. If that solves it, you then need to consider the additional cost ($18/mo) vs how much time it will take to track down performance issues.
Profile your application to figure out which requests are consuming the most memory. This is likely going to be places where you're finding a lot of records and possibly including some associated tables too. There are a couple of tools out there to help you narrow down possible trouble areas. I've used oink but there are definitely others. Once you figure out where the problems are, you can make some tweaks to try and reduce the memory usage.
Assuming you're using Passenger with Apache, you can reduce the number of concurrent requests in the Passenger config file. This might be useful for that https://serverfault.com/questions/15350/running-ruby-on-rails-app-on-apache-passenger-to-much-memory
简而言之,256MB 对于 Rails 应用程序来说是紧张的。您并没有真正给出有关如何运行 Rails 的任何具体信息,但我假设您正在将 Apache 与 Passenger 模块一起使用。可以配置 Passenger 模块保持运行的实例数量。您有 4 个 ruby 实例在 Web 应用程序帐户下运行。我猜那些来自乘客。在配置中,您可以限制 Passenger 启动的实例数量。这将减少内存需求。
另一方面,当仅使用 256MB 且仅托管 1 个 Rails 应用程序时,最好选择其他设置。我自己之前使用的设置是一个 Nginx Web 服务器和一个包含 2 个 mongrel 的 mongrel 集群(大小为 192MB,应用程序仅用于测试目的)。基本上,这意味着在任何时候,您都可以并行处理 2 个(且仅 2 个)rails 请求。设置可能比 Apache+Passenger 难一点,但绝对不难。我认为当您坚持使用 256MB 时,这是一个性能更高的解决方案。
In short, 256MB is tight for a Rails application. You did not really give any specifics on how you are running rails, but I assume you are using Apache with the Passenger module. The Passenger module can be configured on how many instances it keeps running. You have 4 ruby instances running under the web-app account. I guess those come from Passenger. In the configuration, you can limit how many instances Passenger starts. This will reduce the memory requirements.
On the other hand, when working with only 256MB, and when you are only hosting 1 rails application, it might be better to go for another setup. The setup that I used myself before was an Nginx web server, and a mongrel cluster with 2 mongrels (on 192MB, and application was only for testing purposes). Basically that means that at any one time, you can process 2 (and only 2) rails requests in parallel. The setup is maybe a bit harder than Apache+Passenger, but definitely not difficult. I think that is a more performant solution when you stick with the 256MB.