The way the performance module calculates averages is totally incorrect.

Currently, the module takes the previously stored value, adds the most recent entry, and divides the whole thing by 2:

For example:

$data = array(
//...
'ms_avg' => ($data['ms_avg'] + $params['timer']) / 2,
//...
);

This does not correctly weight the previous values that were used to generate the datapoint currently stored in the cache.

For example, if I have 1000 accesses at 1000ms each, but then the last access before checking the logs was 9000ms (perhaps I just emptied a cache or something), performance will log the page average as 5000ms, when in actuality the average should be 1004ms. That's a huge difference!!

To correct this, we just need to properly weight the original value with the number of accesses (which thankfully is stored), so we'd have:

$data = array(
//...
'ms_avg' => (($data['ms_avg'] * $data['num_accesses']) + $params['timer'])) / ($data['num_accesses'] + 1),
//...
);

Comments

malc0mn’s picture

Now that is quite shamefull :-s. Never even glanced at the calculation when I took over maintenance of the module. Must have been in there since D5 and not a soul noticed!

Will fix, obviously :-)

malc0mn’s picture

Assigned: Unassigned » malc0mn
Status: Active » Fixed

Implemented and commited for D7 and D6.

All the average calculations were wrong, so fixed them all. For the 2.0 version, I'm going to store the total sum and calculate the average on display. This is much more accurate:

// Build data.
$data = array(
  [...]
  'ms_sum' => $data['ms'] + $params['timer'],
  [...]
);

[...]

// Show data.
  [...] $data['ms'] / $data['num_accesses'];

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.