开发者

Kill a Rails Process After Its Usefulness is Over

开发者 https://www.devze.com 2023-02-28 14:39 出处:网络
I\'m runni开发者_开发百科ng a Rails app (Tracks, to be exact) with nginx.The Rails process that starts seems to persist indefinitely?Is it suppose to stop?

I'm runni开发者_开发百科ng a Rails app (Tracks, to be exact) with nginx. The Rails process that starts seems to persist indefinitely? Is it suppose to stop?

I have a low RAM allotment on my Shared Hosting and want to be able to kill the Rails process after, say, 10 minutes. Is there a way to do this in nginx or Passenger?

In the meantime, I'm running this bash script with cron every 10 minutes:

PID=$(ps ax|grep [R]ails.*lytracks | cut -f2 -d" " | head -n1)

if [ $PID ]; then
    kill -SIGUSR1 $PID
else
    echo Not running
fi


You can do that, but you shouldn't.

Rails(in production mode) does not normally leak memory, so restarting the process should have no effect.
A healthy rails app with reasonable load should stabilize at about 30-70MB RAM and stay there forever.

Restarting it every 10 minutes means that every 10 minutes some of your users will see a page that takes 20 seconds to load. Or fail to load at all.
You're trying to use Rails like you would use a CGI PHP script. It's not meant to do that.

If you have memory leaks, you should try and find out what's causing them, then fix it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号