Adding a delay in body filter response

Yichun Zhang (agentzh) agentzh at gmail.com
Sat Nov 29 05:53:59 UTC 2014


Hello!

On Fri, Nov 28, 2014 at 2:46 PM, Tod Baudais wrote:
> I am developing a body filter module that processes html and has to do a
> process in the middle of sending a response that can take upwards of a
> couple seconds.

What is this "process" exactly? Is it CPU-bound computation or just a
(nonblocking) IO operation?

> So for example, the first half of the HTML gets sent
> immediately, a process happens and eventually finishes, then second half
> gets sent (the contents of the second half being dependent on the results of
> the process).

If the "process" is an IO operation, this looks trivial if it is
implemented as a content handler instead of a body filter.

>  How to I get a body filter to "wait" for a bit and then
> continue sometime later?

Alas. The nginx output body filter does not provide a "wait" mode by
its design. To make it actually wait, we need to cheat a bit by
exhausting the "busy bufs" of the content handler (so as to make it
stop sending more bufs in non-buffered mode). That's the only way I'm
aware of. (Feel free to prove me wrong.)

And the closest thing in the stock nginx distribution is the
limit_rate mechanism which can serve as an example. But again, this is
complicated, so be careful :)

Regards,
-agentzh



More information about the nginx-devel mailing list