# First hit on app takes a long time

**URL:** <https://www.ruby-forum.com/t/first-hit-on-app-takes-a-long-time/173668>\
**Category:** Rails\
**Created:** [August 13, 2009, 2:23am UTC](https://www.ruby-forum.com/t/first-hit-on-app-takes-a-long-time/173668 "2009-08-13T02:23:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![davetron5000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a3d4f5/32.png) [@davetron5000](https://www.ruby-forum.com/u/davetron5000)\
**Post date:** [August 13, 2009, 2:23am UTC](https://www.ruby-forum.com/t/first-hit-on-app-takes-a-long-time/173668/1 "2009-08-13T02:23:32Z")

</div>

So, I’ve deployed my first rails app, however I’m the only one hitting  
it for now.

I’ve noticed that the first time I hit the app after some long period,  
it takes a really long time to respond (2-3 seconds). After that,  
it’s very fast.

At first, I thought it might be my VPS “waking up” from some sleep  
state, but Rails does log the long load time (log below).

My app just uses the database for login/user auth. Otherwise, it  
serves up pages on the filesystem in textile and renders them as  
HTML. There is no explicit caching done by me, and the filesystem/  
textile/rendering is all hand-rolled (so there’s no caching done  
implicitly).

What are some things I should look for to understand why this happens?

log of two sequential requests for the same page:

Processing WikiPagesController#show (for 98.218.223.189 at 2009-08-12  
20:16:41) [GET]  
Parameters: {“id”=\>“MainPage”}  
Rendering template within layouts/application  
Rendering wiki\_pages/show  
User Columns (1.3ms) SHOW FIELDS FROM `users`  
User Load (0.4ms) SELECT \* FROM `users` WHERE (`users`.`id` = 4)  
LIMIT 1  
Repopulating the stop words  
Rendered common/\_header (16.7ms)  
Rendered common/\_nav (4.4ms)  
Rendered common/\_search (2.4ms)  
Rendered common/\_footer (0.6ms)  
Completed in 2422ms (View: 134, DB: 2) | 200 OK [[http://myserver.com/](http://myserver.com/)  
wiki\_pages/MainPage]

Processing WikiPagesController#show (for 98.218.223.189 at 2009-08-12  
20:17:04) [GET]  
Parameters: {“id”=\>“MainPage”}  
Rendering template within layouts/application  
Rendering wiki\_pages/show  
User Load (0.4ms) SELECT \* FROM `users` WHERE (`users`.`id` = 4)  
LIMIT 1  
Rendered common/\_header (10.9ms)  
Rendered common/\_nav (1.6ms)  
Rendered common/\_search (1.7ms)  
Rendered common/\_footer (0.2ms)  
Completed in 138ms (View: 53, DB: 0) | 200 OK [[http://myserver.com.com/](http://myserver.com.com/)  
wiki\_pages/MainPage]

---

<div class="post-metadata">

**Author:** ![davetron5000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a3d4f5/32.png) [@davetron5000](https://www.ruby-forum.com/u/davetron5000)\
**Post date:** [August 13, 2009, 2:38am UTC](https://www.ruby-forum.com/t/first-hit-on-app-takes-a-long-time/173668/2 "2009-08-13T02:38:45Z")

</div>

Are you using Passenger?

Jamey

---

<div class="post-metadata">

**Author:** ![davetron5000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a3d4f5/32.png) [@davetron5000](https://www.ruby-forum.com/u/davetron5000)\
**Post date:** [August 13, 2009, 3:51am UTC](https://www.ruby-forum.com/t/first-hit-on-app-takes-a-long-time/173668/3 "2009-08-13T03:51:55Z")

</div>

Yes, I’m using passenger with a config like so:

passenger.conf

LoadModule passenger\_module /usr/share/passenger/ext/apache2/  
mod\_passenger.so  
PassengerRoot /usr/share/passenger  
PassengerRuby /usr/bin/ruby  
PassengerLogLevel 2

httpd.conf

RailsBaseURI /my\_app

The passenger.conf was configured by my hosting provider and the (one  
line of) configuration for Apache was via me reading the passenger  
configuration

Dave

---

<div class="post-metadata">

**Author:** ![davetron5000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a3d4f5/32.png) [@davetron5000](https://www.ruby-forum.com/u/davetron5000)\
**Post date:** [August 13, 2009, 4:10am UTC](https://www.ruby-forum.com/t/first-hit-on-app-takes-a-long-time/173668/4 "2009-08-13T04:10:03Z")

</div>

Passenger will shut down it’s rails instances after a certain amount  
of inactivity. So when you hit the site after a long absence it takes  
a second or two load up the rails instance (just like ./script/console  
takes a second or two). After that it’s up and you don’t have that lag.

You’re hosting provider is probably doing this intentionally so it  
doesn’t have a lot of rails processes sitting around doing nothing.

---

<div class="post-metadata">

**Author:** ![davetron5000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a3d4f5/32.png) [@davetron5000](https://www.ruby-forum.com/u/davetron5000)\
**Post date:** [August 13, 2009, 11:39am UTC](https://www.ruby-forum.com/t/first-hit-on-app-takes-a-long-time/173668/5 "2009-08-13T11:39:00Z")

</div>

Looks like this will solve the problem:  
[http://www.modrails.com/documentation/Users%20guide.html#PassengerPoolIdleTime](http://www.modrails.com/documentation/Users%20guide.html#PassengerPoolIdleTime)

Just ran into this issue on my VPS.

- JK.

---

<div class="post-metadata">

**Author:** ![davetron5000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a3d4f5/32.png) [@davetron5000](https://www.ruby-forum.com/u/davetron5000)\
**Post date:** [August 13, 2009, 4:10am UTC](https://www.ruby-forum.com/t/first-hit-on-app-takes-a-long-time/173668/6 "2009-08-13T04:10:03Z")

</div>

Things may have changed, but AFAIK, passenger does go to sleep after a  
period of no http activity on your site. What I ususally do is create  
a cron job that runs every 5 minutes and just hits the web server,  
something like:

wget [http://localhost](http://localhost)

or whatever. This ensures that passenger keeps ruby loaded in memory  
and the app is no longer sluggish on that first hit.

HTH,

Jamey
