You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Pasquale Pagano <pa...@iei.pi.cnr.it> on 2002/07/16 15:26:45 UTC

worker thread

We are trying to use:
1)	Apache 2.0.39 compiled with the option --with-mpm=worker
2)	with modperl 2.0
under Sun Solaris 2.8 with Perl 5.8 RC2.

Although everything seems to work fine, the creation of a custom worker
thread takes more or less 2 minutes.

Here below a section of the code used:

my $t1 = new Thread(\&my_thread,'t1');
my $t2 = new Thread(\&my_thread,'t2');

$t1->join();
$t2->join();

sub my_thread{
    my $name = shift;
    print "I’m $name\n "
    return "$name: done\n";
}

In the example above, each new thread call takes about 2 minutes.

Thanks for any help,

Lino
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
Pasquale Pagano
CNR - Istituto di Elaborazione della Informazione
Via G. Moruzzi, 1 - 56124 Pisa,Italy
Area della Ricerca CNR di Pisa
Tel +39 050 3152891
E-mail: pagano@iei.pi.cnr.it
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-


R: R: worker thread

Posted by Pasquale Pagano <pa...@iei.pi.cnr.it>.
Ok, as you have seen in my first e-mail, I have installed Perl 5.8.0 RC2.
Now, I'm moving to RC3 and and tomorrow I will tell you what happens.
Thanks for the moment,

Lino

-----Messaggio originale-----
Da: Elizabeth Mattijsen [mailto:liz@dijkmat.nl]
Inviato: martedi 16 luglio 2002 17.32
A: Stas Bekman; Pasquale Pagano
Cc: modperl@perl.apache.org
Oggetto: Re: R: worker thread


At 11:19 PM 7/16/02 +0000, Stas Bekman wrote:
>> From the command line, it works very well.
>>We are impleminting a very complex digital library system.
>>In same cases, we want to start parallel threads in order to minimize the
>>wait.
>>Let me try to explain with an example.
>>'A' start 4 threads, each of which prepares, and sends a request to
another
>>server, and then collects its result. When all threads will be terminated,
>>'A' will merge the 4 results.
>>Is now more clear?

You should be able to use Thread::Pool for this.

   $pool = Thread::Pool->new(
    {
     workers => 10, # or higher or lower, max simultaneous requests
     do => sub {fetch from URL and return it},
    } );

    @jobid = ();
    push( @jobid,$pool->job( $_ ) ) foreach @url;
    foreach (@jobid) {
       my $result = $pool->result; # do whatever you want with result X
    }



>your problem is that you use the *old* threads (5005threads, pre-5.6.0),
>whereas mod_perl 2.0 is using ithreads (5.6.0+).
>>>my $t2 = new Thread(\&my_thread,'t2');
>do 'perldoc threads' with perl-5.8.0

Actually, to add to the confusion: only the Thread.pm and Thread::Signal.pm
modules are old 5.005threads modules.  All the other Thread:: namespace
modules (except Malcolm Beattie's old version of Thread::Pool on CPAN) are
new "ithreads" modules.   Only the true "pragma" modules threads.pm and
threads::shared.pm have remaind untouched.  This was changed last week, as
described in Rafael's p5p
summary  http://use.perl.org/article.pl?sid=02/07/15/0732235   ;-)


Liz



Re: R: worker thread

Posted by Elizabeth Mattijsen <li...@dijkmat.nl>.
At 11:19 PM 7/16/02 +0000, Stas Bekman wrote:
>> From the command line, it works very well.
>>We are impleminting a very complex digital library system.
>>In same cases, we want to start parallel threads in order to minimize the
>>wait.
>>Let me try to explain with an example.
>>'A' start 4 threads, each of which prepares, and sends a request to another
>>server, and then collects its result. When all threads will be terminated,
>>'A' will merge the 4 results.
>>Is now more clear?

You should be able to use Thread::Pool for this.

   $pool = Thread::Pool->new(
    {
     workers => 10, # or higher or lower, max simultaneous requests
     do => sub {fetch from URL and return it},
    } );

    @jobid = ();
    push( @jobid,$pool->job( $_ ) ) foreach @url;
    foreach (@jobid) {
       my $result = $pool->result; # do whatever you want with result X
    }



>your problem is that you use the *old* threads (5005threads, pre-5.6.0), 
>whereas mod_perl 2.0 is using ithreads (5.6.0+).
>>>my $t2 = new Thread(\&my_thread,'t2');
>do 'perldoc threads' with perl-5.8.0

Actually, to add to the confusion: only the Thread.pm and Thread::Signal.pm 
modules are old 5.005threads modules.  All the other Thread:: namespace 
modules (except Malcolm Beattie's old version of Thread::Pool on CPAN) are 
new "ithreads" modules.   Only the true "pragma" modules threads.pm and 
threads::shared.pm have remaind untouched.  This was changed last week, as 
described in Rafael's p5p 
summary  http://use.perl.org/article.pl?sid=02/07/15/0732235   ;-)


Liz


Re: R: worker thread

Posted by Stas Bekman <st...@stason.org>.
Pasquale Pagano wrote:
>>>From the command line, it works very well.
> We are impleminting a very complex digital library system.
> In same cases, we want to start parallel threads in order to minimize the
> wait.
> Let me try to explain with an example.
> 
> 'A' start 4 threads, each of which prepares, and sends a request to another
> server, and then collects its result. When all threads will be terminated,
> 'A' will merge the 4 results.
> 
> Is now more clear?

sure, thanks

your problem is that you use the *old* threads (5005threads, pre-5.6.0), 
whereas mod_perl 2.0 is using ithreads (5.6.0+).

>>my $t2 = new Thread(\&my_thread,'t2');
                ^^^^^^^

do 'perldoc threads' with perl-5.8.0

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


R: worker thread

Posted by Pasquale Pagano <pa...@iei.pi.cnr.it>.
>From the command line, it works very well.
We are impleminting a very complex digital library system.
In same cases, we want to start parallel threads in order to minimize the
wait.
Let me try to explain with an example.

'A' start 4 threads, each of which prepares, and sends a request to another
server, and then collects its result. When all threads will be terminated,
'A' will merge the 4 results.

Is now more clear?

-----Messaggio originale-----
Da: Stas Bekman [mailto:stas@stason.org]
Inviato: mercoledi 17 luglio 2002 00.13
A: Pasquale Pagano
Cc: modperl@perl.apache.org
Oggetto: Re: worker thread


Pasquale Pagano wrote:
> We are trying to use:
> 1)	Apache 2.0.39 compiled with the option --with-mpm=worker
> 2)	with modperl 2.0
> under Sun Solaris 2.8 with Perl 5.8 RC2.
>
> Although everything seems to work fine, the creation of a custom worker
> thread takes more or less 2 minutes.
>
> Here below a section of the code used:
>
> my $t1 = new Thread(\&my_thread,'t1');
> my $t2 = new Thread(\&my_thread,'t2');
>
> $t1->join();
> $t2->join();
>
> sub my_thread{
>     my $name = shift;
>     print "I'm $name\n "
>     return "$name: done\n";
> }
>
> In the example above, each new thread call takes about 2 minutes.

May I ask, why do you create these threads? Under worker you already
have the threads created for you and and the perl interpreters handed to
you when you need them.

BTW, what happens if you run the same code from the command line?

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com



Re: worker thread

Posted by Stas Bekman <st...@stason.org>.
Pasquale Pagano wrote:
> We are trying to use:
> 1)	Apache 2.0.39 compiled with the option --with-mpm=worker
> 2)	with modperl 2.0
> under Sun Solaris 2.8 with Perl 5.8 RC2.
> 
> Although everything seems to work fine, the creation of a custom worker
> thread takes more or less 2 minutes.
> 
> Here below a section of the code used:
> 
> my $t1 = new Thread(\&my_thread,'t1');
> my $t2 = new Thread(\&my_thread,'t2');
> 
> $t1->join();
> $t2->join();
> 
> sub my_thread{
>     my $name = shift;
>     print "I'm $name\n "
>     return "$name: done\n";
> }
> 
> In the example above, each new thread call takes about 2 minutes.

May I ask, why do you create these threads? Under worker you already 
have the threads created for you and and the perl interpreters handed to 
you when you need them.

BTW, what happens if you run the same code from the command line?

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com