Perl/mod_perl/DBI: To thread, or not to thread
I'm currently working on... of all things, a book on book about web app
programming with perl/apache/mysql, and I'm trying to explain what
Ubuntu packages to use for installation (and I'm sure other Linux
variants same applies)
Ubuntu gives you:
I've used both prefork and worker (as of late, due to concerns with
forking), both of which seem to work fine. Though, the DBI documentation
warns of caveats of using threaded, especially if the client is not
thread safe (I always compile mysql with a thread-safe client, and
DBD::mysql against that thread safe client).
So... I'm trying to decide if I should explain
1. There are issues with using threads - what all are they?
2. What they should use- prefork or worker?
3. What is the consensus?
4. Is there a document available giving the pros and cons?
5. What is the official state of Perl with regards to threading?
As an author, I'm thinking I don't want to give advice, only inform.
Thanks for you inputs, advice, suggestions, etc.
Satyam Eva Jayate - Truth Alone Triumphs
Re: Perl/mod_perl/DBI: To thread, or not to thread
On Thu, Sep 11, 2008 at 9:07 PM, Patrick Galbraith <email@example.com> wrote:[color=blue]
> 1. There are issues with using threads - what all are they?
> 2. What they should use- prefork or worker?
> 3. What is the consensus?
> 4. Is there a document available giving the pros and cons?
> 5. What is the official state of Perl with regards to threading?[/color]
There's a lot of information about this in the mod_perl archives. The
gist of it is that XS code is often not threadsafe, although mod_perl
itself is and DBI and DBD::mysql appear to be. Pure perl code can
also be unsafe for threads, e.g. by using Cwd in any way. This is the
reason for ModPerl::RegistryPrefork.
I usually advise people to avoid threads unless they're on Win32,
because Perl threads tend to use more memory than forking and
compiling perl with threads support hurts performance. In particular,
if you do use threads, you need to do the exact opposite of the normal
mod_perl approach with module loading, i.e. don't load anything in the
You'll find lots more in the archives, and of course there are threads
documents included with Perl.