Dear DSPAM users,
While working on an upgrade to the current DSPAM, I noticed that
the status screen with the bar charts of 24 hour and daily activity
was taking a long time to display. Although we process a lot of
messages in a 24-day period, it was slower than I expected it to
be. After running strace() on the running admin.cgi script, I noticed
a tremendous number of localtime() system calls. The code executes a
localtime() call for every message line in the system.log file and
uses it for its binning test. I changed the test to use a precalculated
values and integer comparisons. For my system, the time to generate the
admin.cgi status pages went from 63s to 30s as a result. I have attached
the minor changes in 'diff -u' format.
Regards,
Ken
--- admin.cgi 2015-10-08 15:37:34.082539789 -0500
+++ admin-less-localtime.cgi 2015-10-09 14:06:43.688654605 -0500
@@ -406,6 +406,7 @@
my(@spam_daily, @nonspam_daily, @period_daily, @fp_daily, @sm_daily,
@inoc_daily, @whitelist_daily, @corpus_daily, @virus_daily,
@black_daily, @block_daily);
+ my(@period_daily_sec, @period_weekly_sec);
my(@spam_weekly, @nonspam_weekly, @period_weekly, @fp_weekly, @sm_weekly,
@inoc_weekly, @whitelist_weekly, @corpus_weekly, @virus_weekly,
@black_weekly, @block_weekly);
@@ -417,8 +418,9 @@
my ($min, $hour, $mday, $mon, $year) = (localtime(time))[1,2,3,4,5];
my ($hmstart) = time - 60;
my ($daystart) = timelocal(0, 0, 0, $mday, $mon, $year);
- my ($periodstart) = $daystart - (3600*24*24); # 2 Weeks ago
+ my ($periodstart) = $daystart - (3600*24*24); # 24 Days ago
my ($dailystart) = time - (3600*23);
+ my ($dailystart) = $daystart - (3600*(23-$hour));
my ($c_weekly) = 0; # Cursor to most recent time slot
my ($c_daily) = 0;
@@ -431,6 +433,7 @@
for(0..23) {
my($h) = To12Hour($hour-(23-$_));
$period_daily[$_] = $h;
+ $period_daily_sec[$_] = $dailystart + ($_ + 1) * 60*60; # Store
seconds offset to next hour to avoid localtime() calls.
$spam_daily[$_] = 0;
$nonspam_daily[$_] = 0;
$sm_daily[$_] = 0;
@@ -449,6 +452,7 @@
$lmon++;
$lyear += 1900;
$period_weekly[$_] = "$lmon/$lday/$lyear";
+ $period_weekly_sec[$_] = $d + 60*60*24 ; # Store seconds for start of
next day value to avoid the localtime() calls.
$spam_weekly[$_] = 0;
$nonspam_weekly[$_] = 0;
$sm_weekly[$_] = 0;
@@ -470,13 +474,13 @@
# Only Parse Log Data in our Time Period
if ($t_log>=$periodstart) {
- my($tmin, $thour, $tday, $tmon, $tyear) = (localtime($t_log))[1,2,3,4,5];
- $tmon++;
- $tyear += 1900;
+ #my($tmin, $thour, $tday, $tmon, $tyear) =
(localtime($t_log))[1,2,3,4,5];
+ #$tmon++;
+ #$tyear += 1900;
# Weekly Graph
$c_weekly = 0;
- while($period_weekly[$c_weekly] ne "$tmon/$tday/$tyear" && $c_weekly<24)
{
+ while($t_log >= $period_weekly_sec[$c_weekly] && $c_weekly<24) {
$c_weekly++;
}
@@ -534,7 +538,7 @@
# Daily Graph
if ($t_log>=$dailystart) {
- while($period_daily[$c_daily] ne To12Hour($thour) && $c_daily<24) {
+ while($t_log >= $period_daily_sec[$c_daily] && $c_daily<24) {
$c_daily++;
}
------------------------------------------------------------------------------
_______________________________________________
Dspam-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dspam-user