API question: large data processing handler
Maxim Dounin
mdounin at mdounin.ru
Tue Jun 4 16:08:31 UTC 2013
Hello!
On Tue, Jun 04, 2013 at 09:45:19AM -0600, Julien Zefi wrote:
> On Tue, Jun 4, 2013 at 8:29 AM, Maxim Dounin <mdounin at mdounin.ru> wrote:
>
> > Hello!
> >
> > On Tue, Jun 04, 2013 at 12:23:33AM -0600, Julien Zefi wrote:
> >
> > > On Sun, Jun 2, 2013 at 8:29 PM, Julien Zefi <jzefip at gmail.com> wrote:
> > >
> > > > hi,
> > > >
> > > > i am writing a module that creates and returns large amount of data,
> > > > obviously this is blocking the worker but my main function that create
> > the
> > > > data can be called many times to get the result by parts.
> > > >
> > > > I cannot find what's the right way to setup my handler, the intention
> > is
> > > > to invoke my function many times as required and send out the results
> > by
> > > > chunks, whats the best approach ?
> >
> > I would recommend to set r->write_event_handler, and use
> > ngx_add_timer() with 1ms timeout to schedule another call to your
> > handler.
> >
> >
> hi Maxim,
>
> thanks for your response. Why a timer is required ?, my expectation is that
> my function be called when the client socket is ready for write again. My
> function is encoding video packets so i expect this:
>
> 1. initial handler called, setup the write event callback
> 2. once the client socket is ready for write, invoke my write_event
> callback
> 3. write the packet
> 4. repeat #2 and #3 until the callback decide to finish the request
>
> is that possible ?
This will work, but only if you'll send enough data to fill
socket's send buffer. A timer is needed if you want nginx to call
your write event handler again while not filing socket's send
buffer.
(You may also try to emulate filing socket's send buffer by
setting c->write->ready to 0 before calling the
ngx_handle_write_event(), but not sure if it's safe/will actually
work will all event methods.)
--
Maxim Dounin
http://nginx.org/en/donation.html
More information about the nginx-devel
mailing list