in reply to Why use threads over processes, or why use processes over threads?

A lot has been said in this thread already. And in Things you need to know before programming Perl ithreads I describe the current status of threads in Perl as I see it.

I agree with chromatic's comments. Perl threads currently provide an interface to doing threads in Perl over doing non-portable stuff in shared memory. It makes it easy and portable. It's not really production ready, especially for a mod_perl environment.

I also agree with most of Abigail-II's comments. Fork() is very cheap on modern *nix systems.

Which is why my forks.pm module gives you a bit of the best of both worlds: the memory savings of fork() and the ability to use a standard Perl executable (even with 5.6.x!) and the portable interface of threads.pm and its shared variables. At the expense of CPU and latency: there is always a price to pay!

Liz

  • Comment on Re: Why use threads over processes, or why use processes over threads?

Replies are listed 'Best First'.
Re: Re: Why use threads over processes, or why use processes over threads?
by perrin (Chancellor) on Nov 11, 2003 at 16:09 UTC
    liz, do you have any benchmarks (performance and memory usage) of threads vs. forks.pm?
      I thought I could easily adapt Benchmark::Thread::Size to use forks, but there is more to it than I can easily fix right now. This will probably need new versions of both forks and Benchmark::Thread::Size. In the meantime, I'm posting the result of using threads on Mac OS X:
      $ perl5.8.2-threaded -MBenchmark::Thread::Size Performing each test 10 times (ref) 10 100 # (ref) + 0 1730 ± 6 1 2085 ± 6 2 2374 ± 6 5 3235 ± 6 10 4664 20 7536 ± 4 50 16144 ± 2 100 30489 ± 8
      I'll post the result using forks as a response to this node.

      Liz

      There still seems to be a problem with processes not getting reaped when calculating sizes. The combination of Benchmark::Thread::Size and forks becomes something akin to a fork bomb. Preliminary size test shows this:
      $ perl5.8.2-unthreaded -Mforks -MBenchmark::Thread::Size=times,1 (ref) 1 100 # (ref) + 0 3364 1 2836 2 2800 5 2800 10 2800 20 2800 50 2800 100 2804
      but I'm starting to have doubts whether the size calculation is correct. I don't have time to look into it further right now...

      This test was done with my internal development versions of forks and Benchmark::Thread::Size. Don't try this at home with the release versions yet!

      Liz