Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 02 May 2015 20:18:13 +0000
Subject:   Rails app slow after PostgreSQL inactivity
Message-ID:  <>

Next in thread | Raw E-Mail | Index | Archive | Help

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:



Want to link to this message? Use this URL: <>