为什么Rails和Passenger会占用我的记忆?

时间:2022-10-05 21:37:08

I'm on a 256 slice of Slicehost and running Apache and Passenger to host my Rails app. I've had to do the Hard-Reboot often. When I looked at this Passenger memory stat.

我正在使用256片Slicehost并运行Apache和Passenger来托管我的Rails应用程序。我不得不经常进行硬重启。当我看着这个Passenger记忆统计。

--------- Passenger processes ---------
 ** [out :: welcometonewnepal.com] PID   Threads  VMSize    Private  Name
 ** [out :: welcometonewnepal.com] ---------------------------------------
 ** [out :: welcometonewnepal.com] 8246  11       <b>84.1 MB   0.1 MB   /usr/lib/ruby/gems/1.8/gems/passenger-2.2.2/ext/apache2/ApplicationPoolServerExecutable</b> 0 /usr/lib/ruby/gems/1.8/gems/passenger-2.2.2/bin/passenger-spawn-server  /usr/bin/ruby1.8  /tmp/passenger.4217
 ** [out :: welcometonewnepal.com] 8247  2        <b>57.1 MB   0.2 MB   Passenger spawn server</b>
 ** [out :: welcometonewnepal.com] 8903  1        <b>185.6 MB  9.6 MB   Passenger ApplicationSpawner:</b> /home/deploy/rails_apps/welcometonewnepal/production/current
 ** [out :: welcometonewnepal.com] 9065  1        <b>195.1 MB  76.6 MB  Rails:</b> /home/deploy/rails_apps/welcometonewnepal/production/current
 ** [out :: welcometonewnepal.com] ### Processes: 4
 ** [out :: welcometonewnepal.com] ### Total private dirty RSS: 86.43 MB

Seeing the sizes in bold, why is it eating up memory so much?

看到粗体大小,为什么它会如此耗费内存?

5 个解决方案

#1


Can't say for sure based on those stats alone.

根据这些统计数据,不能肯定地说。

But to help lower it:

但要帮助降低它:

  • Use Nginx over Apache
  • 使用Nginx而不是Apache

  • Use Ruby Enterprise Edition -- looks like you're just using regular 1.8.6/7... that's wasted memory right there
  • 使用Ruby Enterprise Edition - 看起来你只是使用常规的1.8.6 / 7 ......就是那里浪费的内存

Also, do you have a lot of gems and/or plugins in your app?

此外,你的应用程序中有很多宝石和/或插件吗?

#2


Its not taking up that much memory ... the column you need to pay attention to is the one marked "private".
If you add them all up (and it does at the bottom) you'll see that passenger and its related processes are only taking up 86MB of memory. Most of it is being taken up by the size of your application too (76MB).

它没有占用那么多的记忆......你需要注意的那一栏是标有“私人”的栏目。如果将它们全部添加(并且它在底部),您将看到乘客及其相关进程仅占用86MB内存。其中大部分也被应用程序的大小占用(76MB)。

You might need to let us know what else you're running on the server ... install htop and sort by memory to get an idea.

您可能需要告诉我们您在服务器上运行的其他内容...安装htop并按内存排序以获得想法。

#3


You need to do some memory profiling.

您需要进行一些内存分析。

#4


If you are running in a 64-bit environment, try switching to 32-bit. Rails/Ruby tend to use less memory in a 32-bit environment.

如果您在64位环境中运行,请尝试切换到32位。 Rails / Ruby倾向于在32位环境中使用更少的内存。

#5


Have you tuned Apache or your database settings? I found a Wordpress blog + a small Rails app to be too much for a 256MB slice with the default Ubuntu configurations.

你有没有调整过Apache或你的数据库设置?我发现一个Wordpress博客+一个小的Rails应用程序对于256MB切片使用默认的Ubuntu配置太多了。

Try the following settings in Apache (Prefork MPM):

在Apache(Prefork MPM)中尝试以下设置:

#KeepAlive On
KeepAlive Off
MaxKeepAliveRequests 100
KeepAliveTimeout 4

<IfModule prefork.c>
StartServers       5
MinSpareServers    5
MaxSpareServers    10
MaxClients         40
MaxRequestsPerChild 1
</IfModule>

In my case, I had to further tune down the MaxClients to 25. I used to get 2-3 swap warning emails per week from Slicehost, but I haven't received any in the 2 weeks since I've switched my settings. If you are using the WorkerMPM fork, then your settings will be different.

在我的情况下,我不得不进一步将MaxClients调低到25.我曾经每周从Slicehost获得2-3个交换警告电子邮件,但是自从我切换设置后的2周内我没有收到任何电子邮件。如果您使用的是WorkerMPM分支,则您的设置将有所不同。

If you are using MySQL, disable InnoDB tables if you don't use InnoDB. That can save you quite a bit of memory.

如果您使用的是MySQL,请在不使用InnoDB的情况下禁用InnoDB表。这可以为你节省相当多的内存。

#1


Can't say for sure based on those stats alone.

根据这些统计数据,不能肯定地说。

But to help lower it:

但要帮助降低它:

  • Use Nginx over Apache
  • 使用Nginx而不是Apache

  • Use Ruby Enterprise Edition -- looks like you're just using regular 1.8.6/7... that's wasted memory right there
  • 使用Ruby Enterprise Edition - 看起来你只是使用常规的1.8.6 / 7 ......就是那里浪费的内存

Also, do you have a lot of gems and/or plugins in your app?

此外,你的应用程序中有很多宝石和/或插件吗?

#2


Its not taking up that much memory ... the column you need to pay attention to is the one marked "private".
If you add them all up (and it does at the bottom) you'll see that passenger and its related processes are only taking up 86MB of memory. Most of it is being taken up by the size of your application too (76MB).

它没有占用那么多的记忆......你需要注意的那一栏是标有“私人”的栏目。如果将它们全部添加(并且它在底部),您将看到乘客及其相关进程仅占用86MB内存。其中大部分也被应用程序的大小占用(76MB)。

You might need to let us know what else you're running on the server ... install htop and sort by memory to get an idea.

您可能需要告诉我们您在服务器上运行的其他内容...安装htop并按内存排序以获得想法。

#3


You need to do some memory profiling.

您需要进行一些内存分析。

#4


If you are running in a 64-bit environment, try switching to 32-bit. Rails/Ruby tend to use less memory in a 32-bit environment.

如果您在64位环境中运行,请尝试切换到32位。 Rails / Ruby倾向于在32位环境中使用更少的内存。

#5


Have you tuned Apache or your database settings? I found a Wordpress blog + a small Rails app to be too much for a 256MB slice with the default Ubuntu configurations.

你有没有调整过Apache或你的数据库设置?我发现一个Wordpress博客+一个小的Rails应用程序对于256MB切片使用默认的Ubuntu配置太多了。

Try the following settings in Apache (Prefork MPM):

在Apache(Prefork MPM)中尝试以下设置:

#KeepAlive On
KeepAlive Off
MaxKeepAliveRequests 100
KeepAliveTimeout 4

<IfModule prefork.c>
StartServers       5
MinSpareServers    5
MaxSpareServers    10
MaxClients         40
MaxRequestsPerChild 1
</IfModule>

In my case, I had to further tune down the MaxClients to 25. I used to get 2-3 swap warning emails per week from Slicehost, but I haven't received any in the 2 weeks since I've switched my settings. If you are using the WorkerMPM fork, then your settings will be different.

在我的情况下,我不得不进一步将MaxClients调低到25.我曾经每周从Slicehost获得2-3个交换警告电子邮件,但是自从我切换设置后的2周内我没有收到任何电子邮件。如果您使用的是WorkerMPM分支,则您的设置将有所不同。

If you are using MySQL, disable InnoDB tables if you don't use InnoDB. That can save you quite a bit of memory.

如果您使用的是MySQL,请在不使用InnoDB的情况下禁用InnoDB表。这可以为你节省相当多的内存。