Skip to content

Commit

Permalink
Fix cavalcade runner memory usage leak
Browse files Browse the repository at this point in the history
We recently enabled `opcache.enable_cli` so Cavalcade Runner now has the opcache enabled. This is a bug, it turns out in the opcache whereby including files over and over again will lead to a memory leak. See php/php-src#9812 for details.

This bug causes a very large memory leak in Cavalcade Runner because we naively re-init the Cloudwatchclient on every call to put_metric_data() etc.

So, it makes sense to only create the cloudwatch client once. THis should also drastically reduce the impact of the PHP bug.
  • Loading branch information
joehoyle committed Nov 18, 2023
1 parent 8b386c2 commit a7ab212
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions inc/cavalcade_runner_to_cloudwatch/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,17 @@ function ( $name, $value ) {
* @return CloudWatchClient
*/
function cloudwatch_client() : CloudWatchClient {
return Altis\get_aws_sdk()->createCloudWatch( [
'version' => '2010-08-01',
'http' => [
'synchronous' => false,
],
] );
static $client;
if ( ! $client ) {
$client = Altis\get_aws_sdk()->createCloudWatch( [
'version' => '2010-08-01',
'http' => [
'synchronous' => false,
],
] );
}

return $client;
}

/**
Expand Down

0 comments on commit a7ab212

Please sign in to comment.