Thin Webserver keeps going down

Hey all,

Have just released my first RoR application into a production setting on
a VPS and am having some stability troubles with Thin. After roughly 1
hour of running the webserver it will fail and I will have to login to
the VPS and restart it. Not exactly sure what the deal is but the most
recent entry in my thin.log presents the following:

Writing PID to tmp/pid/thin.12001.pid
Changing process privilege to root:root
Using rails adapter
Thin web server (v1.0.0 codename That’s What She Said)
Maximum connections set to 1024
Listening on 0.0.0.0:12001, CTRL+C to stop
1714793619361936120889361936112791112791472676>> Stopping …
[FATAL] failed to allocate memory

I’ve checked on memory usage when Thin is operating, according to top it
is on a round 58m res and 67 virt (22.7% mem). Is this high? Could a
runaway memory leak be causing the Thin process to eventually abort? If
this is likely to be my problem is there any way I can debug/resolve
this?

FWIW, I have setup thin according to the guide over at
http://railsforum.com/viewtopic.php?id=17284 - thin can be started,
restarted and stopped through /etc/init.d/thin. The two things I
changed was I only had a single server running (didn’t see the point in
running 5 instances) and I am running the server as root.

Ideally I’d like to get to the bottom of why Thin is aborting and try
and resolve that, but if I can’t I would like to know if there’s any way
to get my server to automatically start thin when it fails?

Any assistance would be appreciated. Thanks in advance.

Re Miara wrote:

Ideally I’d like to get to the bottom of why Thin is aborting and try
and resolve that, but if I can’t I would like to know if there’s any way
to get my server to automatically start thin when it fails?

Hm, could be also your rails application not freeing the memory. Have
you turned your Garbage Collector off maybe? Have you tried using a
Webrick instead to test this behaviour?

For the automatically restart thing, I personally use god:
http://rubyforge.org/projects/god/

Configure it like this:
http://glauche.de/2008/02/15/a-thin-god/

This will periodically check your thin processes for excessive memory or
cpu usage and will check if they are alive. On any problem god will
automatically restart them.

and I am running the server as root
Don’t do that. In case of any exploit through the framework or your
application an attacker could get full root access to your machine.