[PATCH] preload_app can take an optional block for warmup

Aman Gupta aman at tmm1.net
Sat Sep 21 23:10:51 UTC 2013


> In particular, what benefit does this have over putting the same
> code in config.ru or config/initializer.rb (or similar?)

With my patch, preload_app yields a rack app object which includes the
middleware stack. AFAIK there's no way to do this in the context of
config.ru, since the app is still being built. My goal is to warm up
the final application that will be serving traffic, including all
middleware.

On Sat, Sep 21, 2013 at 1:49 AM, Eric Wong <normalperson at yhbt.net> wrote:
> Aman Gupta <aman at tmm1.net> wrote:
>
> Thanks for the patch!
>
> I expect a commit message body to describe why it is useful.
>
> In particular, what benefit does this have over putting the same
> code in config.ru or config/initializer.rb (or similar?)
>
> For user-visible config changes like these, it can be similar/identical
> to the added documentation.
>
> Anyways, I agree warming up the app is often necessary, but I'm not
> convinced it's necessary change unicorn for it.  It makes sense
> to warmup apps on servers other than unicorn, too.
>
>> --- a/lib/unicorn/http_server.rb
>> +++ b/lib/unicorn/http_server.rb
>> @@ -721,6 +721,9 @@ class Unicorn::HttpServer
>>          Gem.refresh
>>        end
>>        self.app = app.call
>> +      if preload_app.respond_to?(:call)
>> +        preload_app[app]
>> +      end
>
> Since you're testing for respond_to?(:call), it should be less confusing
> to use "preload_app.call(app)" here instead of "preload_app[app]"


More information about the mongrel-unicorn mailing list