rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / Atom feed
From: ghazel@gmail.com
To: rack-devel@googlegroups.com
Subject: Re: Middleware and post-request processing
Date: Tue, 7 Aug 2012 03:49:18 -0700	[thread overview]
Message-ID: <CAEcY0kJ645p3fp4mic7GJ9ktNTxjD6amAF-tDBWd2C8bA=DGbw@mail.gmail.com> (raw)
In-Reply-To: <A139A2F8-7135-44EE-A098-4F3B8715E1C5@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2431 bytes --]

On Tue, Jun 7, 2011 at 10:20 AM, James Tucker <jftucker@gmail.com> wrote:

>
> On Jun 3, 2011, at 4:23 PM, ghazel wrote:
>
> > It seems to me that Rack is in need of a new post-response stage of
> > processing. This stage would occur after the response is fully written
> > and the client is unblocked, and before the next request is processed.
> >
> > Similar to what OobGC (
> http://bogomips.org/unicorn.git/tree/lib/unicorn/oob_gc.rb#n59
> > ) accomplishes, it is sometimes useful to perform additional
> > operations after the response is written without blocking the client.
> > For example, the Oink middleware logs statistics about the request,
> > but blocks the response since it has no ability not to: (
> >
> https://github.com/noahd1/oink/blob/4158d71bc9150f011072b2c6eefe73c720a78d46/lib/oink/middleware.rb#L16
> > ). This processing takes time, and needlessly delays the response.
> >
> > This proposal would entail something like a single function which is
> > called on each middleware after the response is written to the client
> > and the socket is closed (depending on the server implementation). For
> > servers which have no ability to not block the client or delay further
> > requests the function should still be called, and the impact would be
> > similar to the behavior today.
> >
> > Thoughts?
>
>
> The problem is, this isn't simple. Different servers have different
> scheduling mechanisms, and deferred operations specifications reach into
> scheduling in a horrible way.
>
> Should these run linearly? Should they be able to be pooled if
> env['rack.multithreaded']. In that case should they receive the same number
> of workers as the main request/response pool? Should they work out of the
> same pool?
>
> And that's just some basics with threads...
>
>
Ideally, the callback would be issued from the same process / thread /
fiber / context as the request itself. So all the questions of
parallelization are answered exactly like you would for requests. I'd be
interested to know of a server where this is not possible.


> You can quite easily handle this on your own in middleware or servers a
> number of ways today, without introducing either far reaching / extensive
> specs or incomplete restrictions that parallel some we already have (like
> stack based control).


How can this be quite easily handled today? Many plugins and frameworks do
not manage to do it when they should.

-Greg

[-- Attachment #2: Type: text/html, Size: 3318 bytes --]

      reply	other threads:[~2012-08-07 10:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-03 23:23 Middleware and post-request processing ghazel
2011-06-04  5:33 ` Eric Wong
2011-06-06 17:05 ` George
2011-06-07 17:20 ` James Tucker
2012-08-07 10:49   ` ghazel [this message]

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  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='CAEcY0kJ645p3fp4mic7GJ9ktNTxjD6amAF-tDBWd2C8bA=DGbw@mail.gmail.com' \
    --to=rack-devel@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).