Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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


In reply to Re: Help me beat NodeJS by marioroy
in thread Help me beat NodeJS by rickyw59

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-19 01:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found