Re: optimize log parsing
- From: "it_says_BALLS_on_your forehead" <simon.chao@xxxxxxx>
- Date: 5 Oct 2005 07:15:24 -0700
>
> Extremely easy with threads. Here's a complete example of a program that
> spawns off a number of threads where each thread pulls data from a
> global queue until it is empty:
>
> #!/usr/bin/perl -w
>
> use strict;
>
> use threads;
> use threads::shared;
>
> use constant NUM_THREADS => 10;
>
> # shared queue visible to every thread
> my @queue : shared = 1 .. 30;
>
> # create threads
> my @threads;
> push @threads, threads->new("run") for 1 .. NUM_THREADS;
>
> # wait for all threads to finish
> $_->join for @threads;
>
> # code executed by each thread
> sub run {
> while (defined(my $element = pop @queue)) {
> printf "thread %i: working with %i\n", threads->tid, $element;
> # make runtime vary a little for
> # demonstration purpose
> select undef, undef, undef, rand;
> }
> }
>
>
>
> Don't think in terms of processes. If you're using processes for that
> kind of thing you'll need to find a way for them to communicate
> (possibly pipes, or maybe shared memory). Threads takes this work off
> your shoulders as they can share data in a simple and secure manner.
>
Tassilo, thank you very much for your help. If i could trouble you once
more for your insight...
What benefit does the thread model have that the following does not?
What drawbacks?
use Parallel::ForkManager;
$pm = new Parallel::ForkManager($MAX_PROCESSES);
foreach $data (@all_data) {
# Forks and returns the pid for the child:
my $pid = $pm->start and next;
... do some work with $data in the child process ...
$pm->finish; # Terminates the child process
}
> use bigint;
> $n=71423350343770280161397026330337371139054411854220053437565440;
> $m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);
.
- Follow-Ups:
- Re: optimize log parsing
- From: xhoster
- Re: optimize log parsing
- From: Tassilo v. Parseval
- Re: optimize log parsing
- References:
- optimize log parsing
- From: it_says_BALLS_on_your forehead
- Re: optimize log parsing
- From: it_says_BALLS_on_your forehead
- Re: optimize log parsing
- From: Tassilo v. Parseval
- optimize log parsing
- Prev by Date: Re: regexp includes a dot in string
- Next by Date: Re: Sorting a nested array (table) (alphabetically)
- Previous by thread: Re: optimize log parsing
- Next by thread: Re: optimize log parsing
- Index(es):
Relevant Pages
|