From mboxrd@z Thu Jan 1 00:00:00 1970 Delivered-To: chneukirchen@gmail.com Received: by 10.227.24.3 with SMTP id t3csp96031wbb; Tue, 29 Oct 2013 01:11:15 -0700 (PDT) Return-Path: Received-SPF: pass (google.com: domain of rack-devel+bncBD4NF5ONU4IBBIW3XWJQKGQEXMGN6XI@googlegroups.com designates 10.180.102.10 as permitted sender) client-ip=10.180.102.10 Authentication-Results: mr.google.com; spf=pass (google.com: domain of rack-devel+bncBD4NF5ONU4IBBIW3XWJQKGQEXMGN6XI@googlegroups.com designates 10.180.102.10 as permitted sender) smtp.mail=rack-devel+bncBD4NF5ONU4IBBIW3XWJQKGQEXMGN6XI@googlegroups.com; dkim=pass header.i=@googlegroups.com X-Received: from mr.google.com ([10.180.102.10]) by 10.180.102.10 with SMTP id fk10mr869473wib.21.1383034275166 (num_hops = 1); Tue, 29 Oct 2013 01:11:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=mime-version:in-reply-to:references:from:date:message-id:subject: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=QZQ8zkFji+hyy7IKTgioQ59HV+yJ3o3h3sj1ZygGAa0=; b=aCyfwG3R1SmYOs92pCMssHhhSM6Fo1/WFHOfg+ksksvUS3LogWXCut4wtBNWYf+h1/ EaKVAOR7D1aODT0qhFL6fYYhI5acP+S75ax+OdyJ+twxOdp1BqUG65Md2+CFrlRTIJS+ DjPJwKNVngp6sAOSrWKvJbRUPFZrVY32RpBPG1VWMNZARrKHOQKmJUyg2nyomqMIzFcK MRtOLN9cop2r7DkrnjFPlDd1Z4kpdJMD0EwhK62L331Y7KC9TRrPr6KlYxlsh+8Z8eu+ 6h/jVjLeeGeFogS0rwej82YdYsWbMOg3lBNR2+l10EtGyjW5d8KsEsu6oUyaFxMW9Suc T1Xw== X-Received: by 10.180.102.10 with SMTP id fk10mr92425wib.21.1383034275111; Tue, 29 Oct 2013 01:11:15 -0700 (PDT) X-BeenThere: rack-devel@googlegroups.com Received: by 10.180.95.194 with SMTP id dm2ls650801wib.25.gmail; Tue, 29 Oct 2013 01:11:14 -0700 (PDT) X-Received: by 10.180.210.242 with SMTP id mx18mr5728340wic.6.1383034274056; Tue, 29 Oct 2013 01:11:14 -0700 (PDT) Received: by 10.194.175.103 with SMTP id bz7mswjc; Mon, 28 Oct 2013 17:21:38 -0700 (PDT) X-Received: by 10.112.234.163 with SMTP id uf3mr7225042lbc.14.1383006098682; Mon, 28 Oct 2013 17:21:38 -0700 (PDT) Received: from mail-wg0-x22a.google.com (mail-wg0-x22a.google.com [2a00:1450:400c:c00::22a]) by gmr-mx.google.com with ESMTPS id ep17si68102wid.2.2013.10.28.17.21.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 28 Oct 2013 17:21:38 -0700 (PDT) Received-SPF: pass (google.com: domain of spastorino@gmail.com designates 2a00:1450:400c:c00::22a as permitted sender) client-ip=2a00:1450:400c:c00::22a; Received: by mail-wg0-f42.google.com with SMTP id n12so4171119wgh.5 for ; Mon, 28 Oct 2013 17:21:38 -0700 (PDT) X-Received: by 10.194.122.99 with SMTP id lr3mr20096365wjb.21.1383006098520; Mon, 28 Oct 2013 17:21:38 -0700 (PDT) MIME-Version: 1.0 Received: by 10.180.149.176 with HTTP; Mon, 28 Oct 2013 17:21:18 -0700 (PDT) In-Reply-To: References: <1380755407-40487-1-git-send-email-ruby@tmm1.net> <5F09D3FD-B53A-4166-9F63-438F075E4A7C@finn.de> From: Santiago Pastorino Date: Mon, 28 Oct 2013 22:21:18 -0200 Message-ID: Subject: Re: [RFC/PATCH] Add Rack::Builder#warmup method for app preloading. To: rack-devel@googlegroups.com Cc: Aman Gupta X-Original-Sender: spastorino@gmail.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of spastorino@gmail.com designates 2a00:1450:400c:c00::22a as permitted sender) smtp.mail=spastorino@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=089e011779b53982d504e9d6333f --089e011779b53982d504e9d6333f Content-Type: text/plain; charset=ISO-8859-1 James, I already merged this in master. On Mon, Oct 28, 2013 at 10:02 PM, James Tucker wrote: > 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. > -- --- 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. --089e011779b53982d504e9d6333f Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
James, I already merged this in master.


On Mon, Oct 28, 2013 at 10= :02 PM, James Tucker <jftucker@gmail.com> wrote:
Yeah, Builder#call leads to= mistakes all the time and then people claiming performance sucks. I don= 9;t think the simple use case there ever helped.

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

On Wed, Oct 2, 2013 at 4:55 PM, Konstantin= Haase <k.haase@finn.de> wrote:
"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 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
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 &= 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.

--
=A0
---
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.

--
 
---
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.
--089e011779b53982d504e9d6333f--