From 42129a50cebae2037375d4a35854cc1db04a8033 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 10 Feb 2022 16:17:49 +0000 Subject: [PATCH] scripts/apache-log-rate: Attempt to speed up with an array slice --- scripts/apache-log-rate | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/apache-log-rate b/scripts/apache-log-rate index d5e9106..f41915b 100755 --- a/scripts/apache-log-rate +++ b/scripts/apache-log-rate @@ -45,9 +45,20 @@ def process_log_file( # print(f'Timestamp: {this_dt}') window_dts.append(this_dt) + # Find the oldest entry that is still within the window: + oldest_of_interest = this_dt - window_time_delta + dti = 0 + for dt in window_dts: + if dt >= oldest_of_interest: + break + dti += 1 + + window_dts = window_dts[dti:] + # Now we need to expire any of the oldest stored timestamps that # are outside the window relative to this - window_dts = list(filter(lambda dt: dt >= this_dt - window_time_delta, window_dts)) + # window_dts = list(filter(lambda dt: dt >= this_dt - window_time_delta, window_dts)) + if len(window_dts) > window_count: window_count = len(window_dts)