[Dancer-users] do something after sending response

thecrux at gmail.com thecrux at gmail.com
Mon Aug 15 10:11:38 CEST 2011


On Fri, Aug 12, 2011 at 09:49:45AM +0600, Nick Knutov wrote:
> I agree, forking is another way to do it, but as far as I know, it can 
> lead to very high load. Also, dying process is a heavy operation, as far 
> as I remember.

Simple benchmark with ab can prove that:

ab2 -c 1 -n 500 http://127.0.0.1:5000/
...
Requests per second:    299.41 [#/sec] (mean)
Time per request:       3.340 [ms] (mean)
...

Adding fork() to a "/" route:

    exit unless(fork);
    waitpid( -1, WNOHANG );

ab2 -c 1 -n 500 http://127.0.0.1:5000/
...
Requests per second:    52.60 [#/sec] (mean)
Time per request:       19.011 [ms] (mean)
...

6X time slower!

> 
> 12.08.2011 0:27, David Precious пишет:
> > On Thursday 11 August 2011 18:17:47 David Precious wrote:
> >> Another possible alternative would be to fork a new process that will do
> >> the  stuff in the background, whilst the original process continues
> >> onwards to send the response back to the client.
> >
> > For the time being, at least, this is probably the easiest option.
> >
> > Something like:
> >
> >      hook after =>  sub {
> >          if (fork) {
> >              # parent - do nothing
> >          } else {
> >              # Child - sleep for a while
> >              sleep 50;
> >              exit;
> >          }
> >      };
> >
> > With a quick test, that works as expected.  (The exit is required, so that the
> > child process doesn't then go on return control to Dancer.)

-- 
Vladimir Lettiev aka crux ✉ theCrux at gmail.com


More information about the Dancer-users mailing list