rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / code / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: rack-devel@googlegroups.com
Cc: Aman Gupta <aman@tmm1.net>
Subject: [PATCH] builder: avoid to_app on every request when using map
Date: Wed, 6 Nov 2013 03:12:07 +0000	[thread overview]
Message-ID: <20131106031207.GA4213@dcvr.yhbt.net> (raw)
In-Reply-To: <20131106025752.GA1712@dcvr.yhbt.net>

Eric Wong <normalperson@yhbt.net> wrote:
> Eric Wong <normalperson@yhbt.net> wrote:
> > James Tucker <jftucker@gmail.com> 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.
> > 
> > Just curious, is this in test suites or code running on live servers?
> > I can't imagine there are many one-off webservers existing and using
> > that directly...
> Answering my own question, the "map" directive in Builder seems to
> trigger Builder#to_app in every single request.
> It looks like map completely defeats warmup and preloading...

OK, I can't tell if my this has any bad side effects (specs pass!),
but I'm already running this on yhbt.net:

From: Eric Wong <normalperson@yhbt.net>
Date: Wed, 6 Nov 2013 03:02:48 +0000
Subject: [PATCH] builder: avoid to_app on every request when using map

By calling to_app immediately after initializing the per-map
Rack::Builder instances.  Otherwise, benefits of warmup and web
servers taking advantage of CoW are lost.

This passes tests, and is lightly tested and I have not verified
this for any negative consequences or incompatibilities.
 lib/rack/builder.rb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/rack/builder.rb b/lib/rack/builder.rb
index fa3a1ea..2aa37b6 100644
--- a/lib/rack/builder.rb
+++ b/lib/rack/builder.rb
@@ -157,7 +157,7 @@ module Rack
     def generate_map(default_app, mapping)
       mapped = default_app ? {'/' => default_app} : {}
-      mapping.each { |r,b| mapped[r] = self.class.new(default_app, &b) }
+      mapping.each { |r,b| mapped[r] = self.class.new(default_app, &b).to_app }
The following changes since commit df1506b0825a096514fcb3821563bf9e8fd52743:

  Merge pull request #617 from tmm1/builder-warmup (2013-10-25 21:10:40 -0700)

are available in the git repository at:

  git://git.bogomips.org/rack.git builder-map-to_app

for you to fetch changes up to fd023bafed0ad97e08d15381f35600e3a5b32808:

  builder: avoid to_app on every request when using map (2013-11-06 03:08:38 +0000)

Eric Wong (1):
      builder: avoid to_app on every request when using map


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.

  reply	other threads:[~2013-11-06  3:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-02 23:10 [RFC/PATCH] Add Rack::Builder#warmup method for app preloading ruby
2013-10-02 23:55 ` Konstantin Haase
2013-10-29  0:02   ` James Tucker
2013-10-29  0:21     ` Santiago Pastorino
2013-10-29 17:54     ` Eric Wong
2013-11-06  2:57       ` Eric Wong
2013-11-06  3:12         ` Eric Wong [this message]
2014-07-15  4:09           ` [PATCH] builder: avoid to_app on every request when using map James Tucker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://groups.google.com/group/rack-devel

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131106031207.GA4213@dcvr.yhbt.net \
    --to=rack-devel@googlegroups.com \
    --cc=aman@tmm1.net \
    --subject='Re: [PATCH] builder: avoid to_app on every request when using map' \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).