From owner-freebsd-questions@FreeBSD.ORG Sat May 2 20:52:57 2015 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C389AA9A for ; Sat, 2 May 2015 20:52:57 +0000 (UTC) Received: from smtp2.hushmail.com (smtp2.hushmail.com [65.39.178.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "smtp.hushmail.com", Issuer "smtp.hushmail.com" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id ABD6B1481 for ; Sat, 2 May 2015 20:52:57 +0000 (UTC) Received: from smtp2.hushmail.com (localhost [127.0.0.1]) by smtp2.hushmail.com (Postfix) with SMTP id AAA0DA0624 for ; Sat, 2 May 2015 20:18:13 +0000 (UTC) Received: from smtp.hushmail.com (w9.hushmail.com [65.39.178.29]) by smtp2.hushmail.com (Postfix) with ESMTP for ; Sat, 2 May 2015 20:18:13 +0000 (UTC) Received: by smtp.hushmail.com (Postfix, from userid 99) id 91B9E42420; Sat, 2 May 2015 20:18:13 +0000 (UTC) MIME-Version: 1.0 Date: Sat, 02 May 2015 20:18:13 +0000 To: freebsd-questions@freebsd.org Subject: Rails app slow after PostgreSQL inactivity From: opendaddy@hushmail.com Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="UTF-8" Message-Id: <20150502201813.91B9E42420@smtp.hushmail.com> X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 May 2015 20:52:57 -0000 Hi! 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 Thanks! O.D.