You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by mm...@apache.org on 2014/09/04 11:22:36 UTC

svn commit: r1622430 - in /spamassassin/trunk: lib/Mail/SpamAssassin/Message.pm lib/Mail/SpamAssassin/PerMsgStatus.pm lib/Mail/SpamAssassin/Util.pm spamassassin.raw

Author: mmartinec
Date: Thu Sep  4 09:22:36 2014
New Revision: 1622430

URL: http://svn.apache.org/r1622430
Log:
MS::PerMsgStatus::create_fulltext_tmpfile(): speed up writing large temporary files by using a larger buffer and avoiding PerlIO; added some debugging

Modified:
    spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm
    spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
    spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm
    spamassassin/trunk/spamassassin.raw

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm?rev=1622430&r1=1622429&r2=1622430&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm Thu Sep  4 09:22:36 2014
@@ -1036,7 +1036,9 @@ sub _parse_normal {
       # we cannot just delete immediately in the POSIX idiom, as this is
       # unportable (to win32 at least)
       push @{$self->{tmpfiles}}, $filepath;
+      dbg("message: storing a message part to file %s", $filepath);
       $fh->print(@{$body})  or die "error writing to $filepath: $!";
+      $fh->flush  or die "error writing (flush) to $filepath: $!";
       $msg->{'raw'} = $fh;
     }
   }

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm?rev=1622430&r1=1622429&r2=1622430&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm Thu Sep  4 09:22:36 2014
@@ -2935,7 +2935,17 @@ sub create_fulltext_tmpfile {
 
   my ($tmpf, $tmpfh) = Mail::SpamAssassin::Util::secure_tmpfile();
   $tmpfh  or die "failed to create a temporary file";
-  print $tmpfh $$fulltext  or die "error writing to $tmpf: $!";
+
+  # PerlIO's buffered print writes in 8 kB chunks - which can be slow.
+  #   print $tmpfh $$fulltext  or die "error writing to $tmpf: $!";
+  #
+  # reducing the number of writes and bypassing extra buffering in PerlIO
+  # speeds up writing of larger text by a factor of 2
+  my $nwrites;
+  for (my $ofs = 0; $ofs < length($$fulltext); $ofs += $nwrites) {
+    $nwrites = $tmpfh->syswrite($$fulltext, length($$fulltext)-$ofs, $ofs);
+    defined $nwrites  or die "error writing to $tmpf: $!";
+  }
   close $tmpfh  or die "error closing $tmpf: $!";
 
   $self->{fulltext_tmpfile} = $tmpf;

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm?rev=1622430&r1=1622429&r2=1622430&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm Thu Sep  4 09:22:36 2014
@@ -1128,6 +1128,7 @@ sub secure_tmpfile {
     return;
   }
 
+  dbg("util: secure_tmpfile created a temporary file %s", $reportfile);
   return ($reportfile, $tmpfh);
 }
 

Modified: spamassassin/trunk/spamassassin.raw
URL: http://svn.apache.org/viewvc/spamassassin/trunk/spamassassin.raw?rev=1622430&r1=1622429&r2=1622430&view=diff
==============================================================================
--- spamassassin/trunk/spamassassin.raw (original)
+++ spamassassin/trunk/spamassassin.raw Thu Sep  4 09:22:36 2014
@@ -344,9 +344,14 @@ for(my $elem = 0; $elem <= $#targets; $e
       binmode $handle  or die "cannot set binmode on file $tempfile: $!";
 
       # avoid slurping the whole file into memory, copy chunk by chunk
-      my($inbuf,$nread);
-      while ( $nread=sysread(STDIN,$inbuf,16384) )
-        { print {$handle} $inbuf  or die "error writing to $tempfile: $!" }
+      my($inbuf,$nread,$nwrites);
+      while ( $nread = sysread(STDIN, $inbuf, 32*1024) ) {
+        for (my $ofs = 0; $ofs < length($inbuf); $ofs += $nwrites) {
+          $nwrites = $handle->syswrite($inbuf, length($inbuf)-$ofs, $ofs);
+          defined $nwrites  or die "error writing to $tempfile: $!";
+        }
+      }
+      undef $inbuf;  # release storage
       defined $nread  or die "error reading from STDIN: $!";
       close $handle   or die "cannot close $tempfile: $!";