Update: added pattern matching to the demonstration.
Greetings,
At first glance, am not seeing NodeJS performing regex for fields containing spaces. That's not really fair, IMHO :) The regex in Perl is likely the main reason for taking longer. Having 24 workers reading IO simultaneously from the nfsv3 mounted SAN may be another reason even though NodeJS seems not affected by it. Maybe, the regex statement in Perl is the reason.
The following is an alternative solution. IO is faster for the upcoming 1.700 release versus MCE 1.608. Thus, the note on using 1.699_010. Also, inlined bits for the Windows platform.
#!/usr/local/bin/perl
use strict;
use warnings;
# IO performance in 1.699_010 is faster than MCE 1.608.
# https://metacpan.org/release/MARIOROY/MCE-1.699_010
use MCE::Loop;
use MCE::Candy;
my $dir = 'logs/*.log.gz';
my @files = sort(glob "$dir");
my $pattern = "some_string";
MCE::Loop::init {
gather => MCE::Candy::out_iter_fh(\*STDOUT),
chunk_size => '240k',
max_workers => 24,
use_slurpio => 1,
};
open( my $fh, "-|", "zcat", @files ) or die "open error: $!\n";
mce_loop {
my ( $mce, $slurp_ref, $chunk_id ) = @_;
my $buf = '';
# Quickly determine if a match is found...
# ...and process slurped chunk only if true.
if ( $$slurp_ref =~ /$pattern/m ) {
# The following is fast on Unix, but performance degrades
# drastically on Windows beyond 4 workers.
open my $MEM_FH, '<', $slurp_ref;
while ( my $line = <$MEM_FH> ) {
if ( $line =~ /$pattern/ ) {
my @matches = $line =~ /".*?"|\S+/g;
$buf .= "$matches[0],$matches[1],$matches[3],$matches
+[4]\n";
}
}
close $MEM_FH;
# Therefore, use the following construction on Windows.
# while ( $$slurp_ref =~ /([^\n]+\n)/mg ) {
# # my $line = $1; # possibly save $1 to not lose the value
# # not necessary for this demonstration
# my @matches = $1 =~ /".*?"|\S+/g;
# $buf .= "$matches[0],$matches[1],$matches[3],$matches[4]\
+n";
# }
}
# Send output to the manager process for orderly output to STDOUT
$mce->gather($chunk_id, $buf);
} $fh;
close $fh;
There is one reader across NFS by the manager process only, not workers. The effect is sequential IO which is typically faster than random IO.
Regards, Mario
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.