Rails app slow after PostgreSQL inactivity

opendaddy at hushmail.com opendaddy at hushmail.com
Sat May 2 20:52:57 UTC 2015


I'm using Rails with PostgreSQL and I often get these 504 gateway timeouts (30+ secs) seemingly out of nowhere. I just noticed that this usually happens after my database has been inactive (say for half a day). After feeding my app some new content via its JSON API, speeds immediately return to normal (2-3 secs). How can this be?

Could this be related to FreeBSD (DigitalOcean)? Are my PostgreSQL workers are going dormant? Do I need a cron script to act as a little ping pong ball bouncing back and forth making sure everybody's awake?

Prior to all of this I've: 

- made sure I'm not querying any 3rd party services
- confirmed it's not Nginx, Puma, or my network in general
- looked for clues with rack-mini-profiler
- confirmed it's not the "initial request" problem: http://stackoverflow.com/a/12903611



More information about the freebsd-questions mailing list