You are here

public function AcquiaPurgeCapacity::httpRequestsFactor in Acquia Purge 7

Get the number of expected HTTP requests per single queue item.

This number plays an essential role in how Acquia Purge throttles itself, as the higher this number gets, the more work it has to do to process a single queue item. The 'safety first' principle thus dictates that the lower this factor gets, the more items that are processed per queue batch.

Return value

int The number of expected HTTP requests per single queue item.

1 call to AcquiaPurgeCapacity::httpRequestsFactor()
AcquiaPurgeCapacity::queueClaimsLimit in lib/AcquiaPurgeCapacity.php
Get the number of queue items that can be processed during runtime.

File

lib/AcquiaPurgeCapacity.php, line 91
Contains AcquiaPurgeCapacity.

Class

AcquiaPurgeCapacity
Runtime capacity tracker.

Code

public function httpRequestsFactor() {
  if (is_null($this->httpRequestsFactor)) {
    $domains = count($this->service
      ->hostingInfo()
      ->getDomains());
    $schemes = count($this->service
      ->hostingInfo()
      ->getSchemes());

    // Retrieve the total number of loaded executors, but filter out the
    // bundled page cache executor as it doesn't make any HTTP requests.
    $executors = count(array_filter($this->service
      ->executorIds(), function ($v) {
      return $v !== 'AcquiaPurgeExecutorPageCache';
    }));

    // Weigh the role that load balancers play into the equation. Before AP
    // version 7.x-1.4, a standard setup with 2 balancers invalidating just
    // one domain on HTTP, would (logically) get a factor 2X. However, these
    // servers are on the local network, extremely fast and barely ever take
    // longer than 0.2 seconds while we pessimistically assume 2s here. This
    // is why clients with 2 balancers, will now get a factor 1X while odd
    // setups with 3 or higher, are punished (1X, 1X, 3X, 4X) and encouraged
    // to normalize to a standard configuration.
    $balancers = count($this->service
      ->hostingInfo()
      ->getBalancerAddresses());
    if ($balancers == 2) {
      $balancers = 1;
    }

    // Calculate the HTTP request factor as follows:
    $this->httpRequestsFactor = $executors * $schemes * $domains * $balancers;

    // Each balancer, holds copies of the same URL.
    // Outside of Acquia Cloud, the factor could become 0. To prevent division
    // by zero, we make it 1. Not a big deal, as the module shuts down.
    if ($this->httpRequestsFactor === 0) {
      $this->httpRequestsFactor = 1;
    }
  }
  return $this->httpRequestsFactor;
}