本文发表在 rolia.net 枫下论坛难道要用 RPC? Share memory?
我在Java中一次开1000个thread, 的确比80个快很多 (其实是占用更多时间片吧) :)
如果用 Perl multi-process ( fork () ). 开80个 process? :-)
#!/usr/bin/perl -w
# Program name: from.pl => Check From: in header files
# then create a hash to see which is the highest
use strict;
$|=1;
my $imdata;
$imdata=`imconfget -m mss messageFilesDir`;
chomp $imdata;
if(!defined($ENV{INTERMAIL})) {
print "Proper environment not loaded. Please run me as 'imail'.\n";
exit;
}
my( $max, $now, $nLines, $filename);
my(%links, %value, @keys);
$max=10000;
$now = localtime();
$nLines=0;
sub dodir {
$nLines=0;
while (<>) {
if ( /MsMsgCreated/ ) {
/MsMsgCreated.+?\s+(.+?):/;
$filename=$1;
#/from=\<.+?@(.+?)\>/;
#$links{$1}++ if length $1;
$nLines ++;
doaction ($filename);
}
last if $nLines > $max;
}
}
sub doaction {
my ($file) = shift;
my ($result, $tmp);
open (THEFILE, "< ${imdata}/$file" ) or return 0;
$tmp=""; $result="";
while (<THEFILE>) {
chomp;
s/#.*//; #No comments
s/^\s+//; #no leading white
s/\s+$//; #no trailing white
next unless length;
if ( /^From:.*@([\w\.]+)/ ) {
$tmp=$1;
$tmp = "NULL" unless length $tmp;
$links{$tmp} ++ if length $tmp;
close (THEFILE);
return;
}
}
close (THEFILE);
}
dodir ();
@keys = sort { $links{$b} <=> $links{$a} } keys %links;
foreach (@keys) {
if ( $links{$_} > 10 ) {
print "$links{$_} ";
print "$_ ";
#print "$value{$_}\n" if ( defined $value{$_});
print "\n";
}
}
#print "Total number found is: $nLines \n";
exit;
__END__更多精彩文章及讨论,请光临枫下论坛 rolia.net
我在Java中一次开1000个thread, 的确比80个快很多 (其实是占用更多时间片吧) :)
如果用 Perl multi-process ( fork () ). 开80个 process? :-)
#!/usr/bin/perl -w
# Program name: from.pl => Check From: in header files
# then create a hash to see which is the highest
use strict;
$|=1;
my $imdata;
$imdata=`imconfget -m mss messageFilesDir`;
chomp $imdata;
if(!defined($ENV{INTERMAIL})) {
print "Proper environment not loaded. Please run me as 'imail'.\n";
exit;
}
my( $max, $now, $nLines, $filename);
my(%links, %value, @keys);
$max=10000;
$now = localtime();
$nLines=0;
sub dodir {
$nLines=0;
while (<>) {
if ( /MsMsgCreated/ ) {
/MsMsgCreated.+?\s+(.+?):/;
$filename=$1;
#/from=\<.+?@(.+?)\>/;
#$links{$1}++ if length $1;
$nLines ++;
doaction ($filename);
}
last if $nLines > $max;
}
}
sub doaction {
my ($file) = shift;
my ($result, $tmp);
open (THEFILE, "< ${imdata}/$file" ) or return 0;
$tmp=""; $result="";
while (<THEFILE>) {
chomp;
s/#.*//; #No comments
s/^\s+//; #no leading white
s/\s+$//; #no trailing white
next unless length;
if ( /^From:.*@([\w\.]+)/ ) {
$tmp=$1;
$tmp = "NULL" unless length $tmp;
$links{$tmp} ++ if length $tmp;
close (THEFILE);
return;
}
}
close (THEFILE);
}
dodir ();
@keys = sort { $links{$b} <=> $links{$a} } keys %links;
foreach (@keys) {
if ( $links{$_} > 10 ) {
print "$links{$_} ";
print "$_ ";
#print "$value{$_}\n" if ( defined $value{$_});
print "\n";
}
}
#print "Total number found is: $nLines \n";
exit;
__END__更多精彩文章及讨论,请光临枫下论坛 rolia.net