Use the last time string parsed by LogTimeProcessor to avoid re-parsing.
authorW. Trevor King <wking@drexel.edu>
Mon, 20 Feb 2012 13:42:06 +0000 (08:42 -0500)
committerW. Trevor King <wking@drexel.edu>
Mon, 20 Feb 2012 13:42:06 +0000 (08:42 -0500)
If you have several requests in the same second, the old approach
would re-parse the time string for each request.  The new approach
recognizes that the time has not changed, and uses the last parsed
value instead of re-parsing.

apachelog/processor/time.py

index c6c1aae3bbd41d0e28bb35fb82729620cbd7b177..fb3922fa14bc449fe323ff9a17147c17e34d5701 100644 (file)
@@ -30,13 +30,18 @@ class LogTimeProcessor (_Processor):
     """
     def __init__(self, previous_log_time_processor=None):
         self.previous_log_time_processor = previous_log_time_processor
-        self.last_time = self.start_time = self.stop_time = None
+        self.last_data = self.last_time = None
+        self.start_time = self.stop_time = None
 
     def process(self, data):
         if self.previous_log_time_processor is None:
-            time = _parse_time(data['%t'])
+            if data['%t'] == self.last_data:
+                time = self.last_time  # don't re-parse a repeated value
+            else:
+                time = _parse_time(data['%t'])
         else:  # avoid re-parsing the time data
             time = self.previous_log_time_processor.last_time
+        self.last_data = data['%t']
         self.last_time = time  # for use by subclasses or other processors
         if self.start_time is None or time < self.start_time:
             self.start_time = time