httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rich Bowen <rbo...@rcbowen.com>
Subject [PATCH] split-logfile script performance
Date Sun, 16 Jun 2002 02:43:39 GMT
Not to pick too many nits, but this patch applies 2, rather than 3,
regular expressions, to each line of the log file, and so runs 1/3
faster than the earlier version. Yeah, I'm probably being overly picky,
but, I started tinkering, and then benchmarked.

Note that this still does not run under 'use strict;'. I'm not feeling
quite that picky this evening.


Index: split-logfile.in
===================================================================
RCS file: /home/cvs/httpd-2.0/support/split-logfile.in,v
retrieving revision 1.3
diff -B -b -u -r1.3 split-logfile.in
--- split-logfile.in	15 Jun 2002 20:35:14 -0000	1.3
+++ split-logfile.in	16 Jun 2002 02:36:48 -0000
@@ -70,34 +70,39 @@
     # identity of the virtual host to which the record
     # applies.
     #
-    ($vhost) = split (/\s/, $log_line);
+    $log_line =~ s/^(\S*)\s+//;
+    $vhost = $1;
     #
     # Normalize the virtual host name to all lowercase.
     # If it's blank, the request was handled by the default
     # server, so supply a default name.  This shouldn't
     # happen, but caution rocks.
     #
-    $vhost = lc ($vhost) or "access";
+    $vhost = lc ($vhost) or 'access';
     #
     # if the vhost contains a "/" or "\", it is illegal so just use
-    # the default log to avoid any security issues due if it is interprted
+    # the default log to avoid any security issues if it is interpreted
     # as a directory separator.
-    if ($vhost =~ m#[/\\]#) { $vhost = "access" }
+    $vhost = 'access' if $vhost =~ m![/\\]!;
     #
     # If the log file for this virtual host isn't opened
     # yet, do it now.
     #
-    if (! $is_open{$vhost}) {
-        open $vhost, ">>${vhost}.log"
-            or die ("Can't open ${vhost}.log");
+    unless ( $is_open{$vhost} ) {
+        open $vhost, '>>' . $vhost . '.log'
+            or die ("Can't open " . $vhost . '.log');
         $is_open{$vhost} = 1;
     }
     #
-    # Strip off the first token (which may be null in the
-    # case of the default server), and write the edited
-    # record to the current log file.
+    # Write the record to the current log file.
     #
-    $log_line =~ s/^\S*\s+//;
-    printf $vhost "%s", $log_line;
+    print $vhost $log_line;
 }
-exit 0;
+
+#
+# Close all open file handles
+#
+foreach $vhost ( keys %is_open ) {
+    close $vhost;
+}
+


Mime
View raw message