From mboxrd@z Thu Jan 1 00:00:00 1970 Delivered-To: chneukirchen@gmail.com Received: by 10.227.24.3 with SMTP id t3csp82078wbb; Mon, 28 Oct 2013 17:02:48 -0700 (PDT) Return-Path: Received-SPF: pass (google.com: domain of rack-devel+bncBD75LW742ECRBJ7WXOJQKGQE67LDKMA@googlegroups.com designates 10.49.99.37 as permitted sender) client-ip=10.49.99.37 Authentication-Results: mr.google.com; spf=pass (google.com: domain of rack-devel+bncBD75LW742ECRBJ7WXOJQKGQE67LDKMA@googlegroups.com designates 10.49.99.37 as permitted sender) smtp.mail=rack-devel+bncBD75LW742ECRBJ7WXOJQKGQE67LDKMA@googlegroups.com; dkim=pass header.i=@googlegroups.com X-Received: from mr.google.com ([10.49.99.37]) by 10.49.99.37 with SMTP id en5mr5219849qeb.8.1383004968711 (num_hops = 1); Mon, 28 Oct 2013 17:02:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:x-original-sender:x-original-authentication-results:reply-to :precedence:mailing-list:list-id:list-post:list-help:list-archive :sender:list-subscribe:list-unsubscribe:content-type; bh=dAXRYMb36JyPoOQ650efhqVMQzCbHNe82IQwmZijLNw=; b=YvTTeHitqovhpXzQfyYKEHd9o6KSWsZm1MbIEXvWKO+tZpn/k9zQCy9lzAnmkC1HQK 1gwq6ghF6ZF0PlxhKY9X21o1hxqbZgu5OvYL9gpR0xH8Z9TsnEgS41MkDUbNZS0gVQTz k7kDfffJ4Ov/x8ijXILQn6zEoSs7oKso8VlA75SX0kUMd2Ep2sckQArLu11jvf61++6r ESOVDH4ar4TS/Lxf+FQszWBRmhkAkM1IISB0LdpOwn5fH9rMVXxF/gyGZeLT60lhFqiO oDtOJ7dQkQoi85x7Z6zt83bUdj9nmeLx2KLQUosOVspbjg5Os3lBDMMyAnIp1yRrJ4QN 18/g== X-Received: by 10.49.99.37 with SMTP id en5mr606287qeb.8.1383004968326; Mon, 28 Oct 2013 17:02:48 -0700 (PDT) X-BeenThere: rack-devel@googlegroups.com Received: by 10.49.2.102 with SMTP id 6ls1756568qet.69.gmail; Mon, 28 Oct 2013 17:02:47 -0700 (PDT) X-Received: by 10.236.43.229 with SMTP id l65mr6483744yhb.30.1383004967654; Mon, 28 Oct 2013 17:02:47 -0700 (PDT) Received: from mail-vc0-x22d.google.com (mail-vc0-x22d.google.com [2607:f8b0:400c:c03::22d]) by gmr-mx.google.com with ESMTPS id ee5si2331761vdb.1.2013.10.28.17.02.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 28 Oct 2013 17:02:47 -0700 (PDT) Received-SPF: pass (google.com: domain of jftucker@gmail.com designates 2607:f8b0:400c:c03::22d as permitted sender) client-ip=2607:f8b0:400c:c03::22d; Received: by mail-vc0-f173.google.com with SMTP id lh4so1001094vcb.18 for ; Mon, 28 Oct 2013 17:02:47 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.220.183.199 with SMTP id ch7mr90762vcb.27.1383004967483; Mon, 28 Oct 2013 17:02:47 -0700 (PDT) Received: by 10.220.192.71 with HTTP; Mon, 28 Oct 2013 17:02:47 -0700 (PDT) In-Reply-To: <5F09D3FD-B53A-4166-9F63-438F075E4A7C@finn.de> References: <1380755407-40487-1-git-send-email-ruby@tmm1.net> <5F09D3FD-B53A-4166-9F63-438F075E4A7C@finn.de> Date: Mon, 28 Oct 2013 17:02:47 -0700 Message-ID: Subject: Re: [RFC/PATCH] Add Rack::Builder#warmup method for app preloading. From: James Tucker To: rack-devel@googlegroups.com Cc: Aman Gupta X-Original-Sender: jftucker@gmail.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of jftucker@gmail.com designates 2607:f8b0:400c:c03::22d as permitted sender) smtp.mail=jftucker@gmail.com; dkim=pass header.i=@gmail.com; dmarc=pass (p=NONE dis=NONE) header.from=gmail.com Reply-To: rack-devel@googlegroups.com Precedence: list Mailing-list: list rack-devel@googlegroups.com; contact rack-devel+owners@googlegroups.com List-ID: X-Google-Group-Id: 486215384060 List-Post: , List-Help: , List-Archive: Sender: rack-devel@googlegroups.com List-Subscribe: , List-Unsubscribe: , Content-Type: multipart/alternative; boundary=001a11c1bce0cf448e04e9d5efb4 --001a11c1bce0cf448e04e9d5efb4 Content-Type: text/plain; charset=ISO-8859-1 Yeah, Builder#call leads to mistakes all the time and then people claiming performance sucks. I don't think the simple use case there ever helped. I'll keep this starred for my next round of merges. Probably not before 1.6. On Wed, Oct 2, 2013 at 4:55 PM, Konstantin Haase wrote: > "Could you rebase and add some tests." /trololo > > I generally like the idea. I think we might have to remove Builder#call, > though, just to avoid concurrency issues and double firing warmup blocks. > > Konstantin > > On Oct 3, 2013, at 1:10 AM, ruby@tmm1.net wrote: > > > From: Aman Gupta > > > > This new `warmup` method takes a block which is invoked after the app > > is built. The block can be used to make mock requests that ensure > > all application dependencies are loaded before the app starts > > serving traffic. > > > > With complex frameworks like Rails, many dependencies are auto-loaded > > and data like mime-type and i18n is not loaded into memory by default. > This > > often means the first few requests handled by an application are quite > > slow. > > > > With this patch, config.ru can simply make requests via warmup to > > exercise the app before it is used: > > > > $ tail -4 config.ru > > warmup do |app| > > client = Rack::MockRequest.new(app) > > client.get('/') > > end > > --- > > lib/rack/builder.rb | 19 +++++++++++++++++-- > > test/spec_builder.rb | 11 +++++++++++ > > 2 files changed, 28 insertions(+), 2 deletions(-) > > > > diff --git a/lib/rack/builder.rb b/lib/rack/builder.rb > > index 66dc7bd..fa3a1ea 100644 > > --- a/lib/rack/builder.rb > > +++ b/lib/rack/builder.rb > > @@ -51,7 +51,7 @@ module Rack > > end > > > > def initialize(default_app = nil,&block) > > - @use, @map, @run = [], nil, default_app > > + @use, @map, @run, @warmup = [], nil, default_app, nil > > instance_eval(&block) if block_given? > > end > > > > @@ -104,6 +104,19 @@ module Rack > > @run = app > > end > > > > + # Takes a lambda or block that is used to warm-up the application. > > + # > > + # warmup do |app| > > + # client = Rack::MockRequest.new(app) > > + # client.get('/') > > + # end > > + # > > + # use SomeMiddleware > > + # run MyApp > > + def warmup(prc=nil, &block) > > + @warmup = prc || block > > + end > > + > > # Creates a route within the application. > > # > > # Rack::Builder.app do > > @@ -131,7 +144,9 @@ module Rack > > def to_app > > app = @map ? generate_map(@run, @map) : @run > > fail "missing run or map statement" unless app > > - @use.reverse.inject(app) { |a,e| e[a] } > > + app = @use.reverse.inject(app) { |a,e| e[a] } > > + @warmup.call(app) if @warmup > > + app > > end > > > > def call(env) > > diff --git a/test/spec_builder.rb b/test/spec_builder.rb > > index 0774f59..20ea668 100644 > > --- a/test/spec_builder.rb > > +++ b/test/spec_builder.rb > > @@ -130,6 +130,17 @@ describe Rack::Builder do > > Rack::MockRequest.new(app).get("/foo").should.be.server_error > > end > > > > + it "yields the generated app to a block for warmup" do > > + warmed_up_app = nil > > + > > + app = Rack::Builder.new do > > + warmup { |a| warmed_up_app = a } > > + run lambda { |env| [200, {}, []] } > > + end.to_app > > + > > + warmed_up_app.should.equal app > > + end > > + > > should "initialize apps once" do > > app = builder do > > class AppClass > > -- > > 1.8.3.4 > > > > -- > > > > --- > > You received this message because you are subscribed to the Google > Groups "Rack Development" group. > > To unsubscribe from this group and stop receiving emails from it, send > an email to rack-devel+unsubscribe@googlegroups.com. > > For more options, visit https://groups.google.com/groups/opt_out. > > -- > > --- > You received this message because you are subscribed to the Google Groups > "Rack Development" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rack-devel+unsubscribe@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > -- --- You received this message because you are subscribed to the Google Groups "Rack Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to rack-devel+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. --001a11c1bce0cf448e04e9d5efb4 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Yeah, Builder#call leads to mistakes all the time and then= people claiming performance sucks. I don't think the simple use case t= here ever helped.

I'll keep this starred for my next= round of merges. Probably not before 1.6.


On Wed,= Oct 2, 2013 at 4:55 PM, Konstantin Haase <k.haase@finn.de> wr= ote:
"Could you rebase and add some tests.&q= uot; /trololo

I generally like the idea. I think we might have to remove Builder#call, th= ough, just to avoid concurrency issues and double firing warmup blocks.

Konstantin

On Oct 3, 2013, at 1:10 AM, ruby@tmm1.net<= /a> wrote:

> From: Aman Gupta <
aman@tmm1.net>
>
> This new `warmup` method takes a block which is invoked after the app<= br> > is built. The block can be used to make mock requests that ensure
> all application dependencies are loaded before the app starts
> serving traffic.
>
> With complex frameworks like Rails, many dependencies are auto-loaded<= br> > and data like mime-type and i18n is not loaded into memory by default.= This
> often means the first few requests handled by an application are quite=
> slow.
>
> With this patch,
config= .ru can simply make requests via warmup to
> exercise the app before it is used:
>
> =A0$ tail -4 config.ru<= /a>
> =A0warmup do |app|
> =A0 =A0client =3D Rack::MockRequest.new(app)
> =A0 =A0client.get('/')
> =A0end
> ---
> lib/rack/builder.rb =A0| 19 +++++++++++++++++--
> test/spec_builder.rb | 11 +++++++++++
> 2 files changed, 28 insertions(+), 2 deletions(-)
>
> diff --git a/lib/rack/builder.rb b/lib/rack/builder.rb
> index 66dc7bd..fa3a1ea 100644
> --- a/lib/rack/builder.rb
> +++ b/lib/rack/builder.rb
> @@ -51,7 +51,7 @@ module Rack
> =A0 =A0 end
>
> =A0 =A0 def initialize(default_app =3D nil,&block)
> - =A0 =A0 =A0@use, @map, @run =3D [], nil, default_app
> + =A0 =A0 =A0@use, @map, @run, @warmup =3D [], nil, default_app, nil > =A0 =A0 =A0 instance_eval(&block) if block_given?
> =A0 =A0 end
>
> @@ -104,6 +104,19 @@ module Rack
> =A0 =A0 =A0 @run =3D app
> =A0 =A0 end
>
> + =A0 =A0# Takes a lambda or block that is used to warm-up the applica= tion.
> + =A0 =A0#
> + =A0 =A0# =A0 warmup do |app|
> + =A0 =A0# =A0 =A0 client =3D Rack::MockRequest.new(app)
> + =A0 =A0# =A0 =A0 client.get('/')
> + =A0 =A0# =A0 end
> + =A0 =A0#
> + =A0 =A0# =A0 use SomeMiddleware
> + =A0 =A0# =A0 run MyApp
> + =A0 =A0def warmup(prc=3Dnil, &block)
> + =A0 =A0 =A0@warmup =3D prc || block
> + =A0 =A0end
> +
> =A0 =A0 # Creates a route within the application.
> =A0 =A0 #
> =A0 =A0 # =A0 Rack::Builder.app do
> @@ -131,7 +144,9 @@ module Rack
> =A0 =A0 def to_app
> =A0 =A0 =A0 app =3D @map ? generate_map(@run, @map) : @run
> =A0 =A0 =A0 fail "missing run or map statement" unless app > - =A0 =A0 =A0@use.reverse.inject(app) { |a,e| e[a] }
> + =A0 =A0 =A0app =3D @use.reverse.inject(app) { |a,e| e[a] }
> + =A0 =A0 =A0@warmup.call(app) if @warmup
> + =A0 =A0 =A0app
> =A0 =A0 end
>
> =A0 =A0 def call(env)
> diff --git a/test/spec_builder.rb b/test/spec_builder.rb
> index 0774f59..20ea668 100644
> --- a/test/spec_builder.rb
> +++ b/test/spec_builder.rb
> @@ -130,6 +130,17 @@ describe Rack::Builder do
> =A0 =A0 Rack::MockRequest.new(app).get("/foo").should.be.ser= ver_error
> =A0 end
>
> + =A0it "yields the generated app to a block for warmup" do<= br> > + =A0 =A0warmed_up_app =3D nil
> +
> + =A0 =A0app =3D Rack::Builder.new do
> + =A0 =A0 =A0warmup { |a| warmed_up_app =3D a }
> + =A0 =A0 =A0run lambda { |env| [200, {}, []] }
> + =A0 =A0end.to_app
> +
> + =A0 =A0warmed_up_app.should.equal app
> + =A0end
> +
> =A0 should "initialize apps once" do
> =A0 =A0 app =3D builder do
> =A0 =A0 =A0 class AppClass
> --
> 1.8.3.4
>
> --
>
> ---
> You received this message because you are subscribed to the Google Gro= ups "Rack Development" group.
> To unsubscribe from this group and stop receiving emails from it, send= an email to
r= ack-devel+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

--

---
You received this message because you are subscribed to the Google Groups &= quot;Rack Development" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to rack-d= evel+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
 
---
You received this message because you are subscribed to the Google Groups &= quot;Rack Development" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to rack-devel+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--001a11c1bce0cf448e04e9d5efb4--