You are here

public function CapacityTracker::getTimeHintTotal in Purge 8.3

Get the maximum number of seconds, processing a single invalidation takes.

The capacity tracker calls getTimeHint on all loaded purger plugins and uses the highest outcome as global estimate. When multiple loaded purger plugins support the same type of invalidation (for instance 'tag'), these values will be added up. This means that if 3 plugins all purge tags, this will cause purge to take it a lot easier and to pull less items from the queue per request.

Return value

float The maximum number of seconds - as float - it takes all purgers to process a single cache invalidation (regardless of type).

Throws

\Drupal\purge\Plugin\Purge\Purger\Exception\BadPluginBehaviorException Thrown when a returned floating point value is lower than 0.1, higher than 10 or is not returned as float.

Overrides CapacityTrackerInterface::getTimeHintTotal

See also

\Drupal\purge\Plugin\Purge\Purger\PurgerCapacityDataInterface::getTimeHint()

2 calls to CapacityTracker::getTimeHintTotal()
CapacityTracker::getLeaseTimeHint in src/Plugin/Purge/Purger/CapacityTracker.php
Estimate how long a call to ::invalidate() takes for X amount of objects.
CapacityTracker::getRemainingInvalidationsLimit in src/Plugin/Purge/Purger/CapacityTracker.php
Get the remaining number of allowed cache invalidations for this request.

File

src/Plugin/Purge/Purger/CapacityTracker.php, line 321

Class

CapacityTracker
Provides the capacity tracker.

Namespace

Drupal\purge\Plugin\Purge\Purger

Code

public function getTimeHintTotal() {
  if (is_null($this->timeHintTotal)) {
    $this
      ->gatherTimeHints();
    $this->timeHintTotal = 1.0;
    if (count($this->timeHints)) {
      $hints_per_type = [];

      // Iterate all hints and group the values by invalidation type.
      foreach ($this->timeHints as $id => $hint) {
        foreach ($this->purgers[$id]
          ->getTypes() as $type) {
          if (!isset($hints_per_type[$type])) {
            $hints_per_type[$type] = 0.0;
          }
          $hints_per_type[$type] = $hints_per_type[$type] + $hint;
        }
      }

      // Find the highest time, so that the system takes the least risk.
      $this->timeHintTotal = max($hints_per_type);
    }
  }
  return $this->timeHintTotal;
}