Following up on my previous post , I’ve been experience slow load times (10-15 secs) on the initial request after application restarts. This has to do with the way mod_rails manages application instances (Although, I experienced this when using mongrel_cluster and proxy balancers). It will spin up instances on page request and each instance has an idle timeout. This just means after the timeout expires, mod_rails will shutdown that instance to conserve memory allocation. While you can change timeout value (see PassengerPoolIdleTime), this will only cause all instances that get spin up to live longer. After high load times, these instances will stick around longer than neccessary.
For low traffic sites (like mine), this idle timeout may be reached causing the next visitor to our website to experience a really long delay before page load. What we really want is an option to set a minimum number of instances. This would allow us to automatically spin up an instance during start up and keep it around. Unfortunately at this time, it doesn’t look like there is a way to set this.
As a workaround, I’ve setup a crontab that makes a request to my application every 5 minutes to prevent mod_rails from killing off all application instances.
You can verify this is working correctly but just tailing your application logs and verify every 5 minutes you get a request.
You can also run
You should see at least the count variable to be at least 1 instance.
Note, this workaround will not immediate start up an instance upon restart. You can add an initial request as part of your post deploy capistrano task though. You probably should be making sure your application is up after deploying or restarting the application anyways.
I was looking for where mysql.sock was since running rake db:bootstrap was complaining with “No such file or directory – /tmp/mysql.sock”. Rails looks for the mysql.sock file under /tmp/mysql.sock by default. Ubuntu using an apt-get install of mysql puts the mysql.sock file at /var/run/mysqld/mysqld.sock.
I always forget where it is. So, I’m writing it down.
You can also grep for it from mysql like so
>> mysql -? | grep mysqld.sock
As a developer, there are certain UNIX commands you find yourself typing repeatedly. Whether it’s to debug a production issue or just modifying some files, these commands have helped me do my job time and time again. Here’s my top 8:
grep – Prints the lines that match the pattern provided in the files specified
Usage: grep <options> <pattern> <files>
Example: grep -n Exception production.log
Prints all the line (showing line numbers) in the file production.log that contain the string ‘Exception’
tail – Only interested in a the last couple of lines in a file? tail allows you to quickly view the end of the file
Usage: tail <options> <file>
Example: tail -fn100 production.log
Shows the last 100 lines of the log and waits to display any new text appended to the file
ssh – Log into remote servers
Usage: ssh -p<port> <username>@<hostname>
Example: ssh -p1234 theo@production
Logs into the server named production on port 1234