in reply to How to do parallel processing within mod_perl

Thanks for all the suggestions but does anyone have any pointers either to docs or better yet sample code?

Search for "mod_perl" and "fork" or "threads" tend to give lots of hits about apache MPMs but very little about fork/threads within mod_perl

POE looks very interesting but also very much like a whole new framework to learn. It is on my todo list but I had hoped for something I could use after reading a man page or two but not hundreds of them ;-)

  • Comment on Re: How to do parallel processing within mod_perl

Replies are listed 'Best First'.
Re^2: How to do parallel processing within mod_perl
by perrin (Chancellor) on Nov 13, 2007 at 12:57 UTC
      Thanks for the pointer, I tried to follow the example as close as possible and came up with this (not proberly working) code:
      sub metasearch { my $self = shift; my $db_ref = $self->db_defs; my @dbs = @{$self->dbs}; my $logger = $self->logger; $SIG{CHLD} = 'IGNORE'; my @result; foreach my $db (@dbs) { defined (my $kid = fork) or die "Cannot fork: $!\n"; $logger->debug("Processing $db in process $kid"); if ($kid) { $logger->debug("Parent $$ has finished, kid's PID: $kid"); } else { # $r->cleanup_for_exec(); # untie the socket open STDIN, '/dev/null' or die "Can't read /dev/null: $!"; open STDOUT, '>/dev/null' or die "Can't write to /dev/null +: $!"; open STDERR, '>/tmp/log' or die "Can't write to /tmp/log: + $!"; # setsid or die "Can't start a new session: $!"; my $oldfh = select STDERR; local $| = 1; select $oldfh; warn "started\n"; sleep 1, warn "$_\n" for 1..20; warn "completed\n"; push @result, "simulate result for $db in $kid"; CORE::exit(0); # terminate the process } $logger->debug("End of $db"); } $logger->debug(join(', ', @result)); }

      The difference is a foreach around the forks and the attempt to collect some result from the forked processes in @result but @result is empty.

      What am I doing wrong?

      As a side-note since I am not really interested in the warn-output: /tmp/log is empty after the run. Does this indicate that the child(s) didn't run?

      I left out the cleanup_for_exec and the setsid lines because from the explanation I gathered they are not necessary in my situation and I didn't know if cleanup_for_exec call is still the same in mod_perl2 (the example is for mod_perl1)

        If you don't tell us what isn't working about the code, we probably can't guess how to fix it.

        I think you may get better help by asking on the mod_perl list, but if you do, make sure to explain how the code is failing.