{"id":3011,"date":"2010-06-26T18:12:41","date_gmt":"2010-06-26T22:12:41","guid":{"rendered":"http:\/\/blogs.n1zyy.com\/n1zyy\/?p=3011"},"modified":"2010-06-26T18:12:41","modified_gmt":"2010-06-26T22:12:41","slug":"fix-slow-first-request-with-passenger-mod_rails","status":"publish","type":"post","link":"https:\/\/blogs.n1zyy.com\/n1zyy\/2010\/06\/26\/fix-slow-first-request-with-passenger-mod_rails\/","title":{"rendered":"Fix slow first request with Passenger \/ mod_rails?"},"content":{"rendered":"<p>The main page of this site is now a Rails app, and I plan to use Rails more extensively as time goes on. I run <a href=\"http:\/\/www.modrails.com\/\">Passenger<\/a> with Apache, which is a pretty nice solution. (I&#8217;m thinking of dropping in <a href=\"http:\/\/www.rubyenterpriseedition.com\/\">REE<\/a> in lieu of standard Ruby, too?)<\/p>\n<p>But it had one crippling bug: if you were the first to hit the page in a while, it was unbearably slow. It turns out that my guess about what was happening was correct: after a period of inactivity, your app will spin down to free up memory for other threads. The benefit is that it&#8217;s proper and efficient. The downside is that if someone hits the application (here, &#8220;the application&#8221; is the main page) for the first time in a while, Passenger has to load the application into memory again. And as someone who works with Rails on a daily basis, I have to say that it&#8217;s excruciatingly slow to start. 10-30 seconds is the norm for me.<\/p>\n<p>The fix is apparently pretty easy: set <a href=\"http:\/\/www.modrails.com\/documentation\/Users%20guide.html#PassengerPoolIdleTime\">PassengerPoolIdleTime<\/a> much higher to leave idle threads running longer, or set it to 0 to leave them running forever &#8220;unless it&#8217;s really necessary&#8221; to make room for something else. The documentation also notes, &#8220;Setting the value to 0 is recommended if you\u2019re on a non-shared host that\u2019s only running a few applications, each which must be available at all times.&#8221;<\/p>\n<p>You&#8217;ll probably also want to set <a href=\"http:\/\/www.modrails.com\/documentation\/Users%20guide.html#_railsframeworkspawneridletime_lt_integer_gt\">RailsFrameworkSpawnerIdleTime and RailsAppSpawnerIdleTime<\/a> to 0 if you go that route.<\/p>\n<p>Drop the settings right into httpd.conf, restart Apache, and viola.<\/p>","protected":false},"excerpt":{"rendered":"<p>The main page of this site is now a Rails app, and I plan to use Rails more extensively as time goes on. I run Passenger with Apache, which is a pretty nice solution. (I&#8217;m thinking of dropping in REE &hellip; <a href=\"https:\/\/blogs.n1zyy.com\/n1zyy\/2010\/06\/26\/fix-slow-first-request-with-passenger-mod_rails\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3011","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts\/3011","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/comments?post=3011"}],"version-history":[{"count":0,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts\/3011\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/media?parent=3011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/categories?post=3011"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/tags?post=3011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}