Appengine гибкая утечка памяти php докера с помощью AWS s3 CommandPool

Я обнаружил, что использование AWS в Google Appengine потребляет в 20 раз больше памяти, чем обычно, при использовании параллельной загрузки файлов из пула команд:

$ cat > index.php
<?php

if (!shell_exec('which composer')) {
passthru('curl https://getcomposer.org/composer.phar > /usr/bin/composer && chmod a+x /usr/bin/composer');
passthru('apt update && apt install -y git');
}

passthru('composer require aws/aws-sdk-php');

require_once 'vendor/autoload.php';

$mem1 = meminfo();

$s3_client = new \Aws\S3\S3Client([
'credentials' => [
'key' => 'xxxxxxxxxx',
'secret' => 'xxxxxxxxxx',
],
'region' => 'us-east-1',
'version' => '2006-03-01'
]);

$commands = [];
foreach (range(1, 200) as $tmp) {
$commands[] = $s3_client->getCommand('PutObject', [
'Bucket' => 'xxxxxxxxxx',
'Key' => "tmp/guzzle-issue/$tmp.txt",
'Body' => $tmp,
'ContentType' => 'text/plain'
]);
}

$pool = new \Aws\CommandPool($s3_client, $commands, ['concurrency' => 100]);
$pool->promise()->wait();

$mem2 = meminfo();
echo sprintf("consumed memory: %s\n", format_bytes($mem1['free'] - $mem2['free']));

function meminfo()
{
preg_match('/^MemFree:\s*(\d+)/m', file_get_contents('/proc/meminfo'), $free);
preg_match('/^MemAvailable:\s*(\d+)/m', file_get_contents('/proc/meminfo'), $available);
$free = $free[1]*1024;
$available = $available[1]*1024;
return compact('free', 'available');
}

function format_bytes($bytes)
{
if ($bytes < 1000) {
return number_format($bytes, 2);
}
$kilo = $bytes/1024;
if ($kilo < 1000) {
return number_format($kilo, 2) . 'K';
}
$mega = $kilo/1024;
if ($mega < 1000) {
return number_format($mega, 2) . 'M';
}
$giga = $mega/1024;
if ($giga < 1000) {
return number_format($giga, 2) . 'G';
}
return number_format($giga/1024, 2) . 'T';
}

$ docker run --rm -v $PWD/index.php:/app/index.php:ro gcr.io/google-appengine/php70 php /app/index.php
[...]
consumed memory: 1.53G

$ docker run --rm -v $PWD/index.php:/app/index.php:ro gcr.io/google-appengine/php71 php /app/index.php
[...]
consumed memory: 1.83G

$ docker run --rm -v $PWD/index.php:/app/index.php:ro gcr.io/google-appengine/php72 php /app/index.php
[...]
consumed memory: 1.81G

$ docker run --rm -v $PWD/index.php:/app/index.php:ro php:7.0 php /app/index.php
[...]
consumed memory: 107.22M

$ docker run --rm -v $PWD/index.php:/app/index.php:ro php:7.1 php /app/index.php
[...]
consumed memory: 109.87M

$ docker run --rm -v $PWD/index.php:/app/index.php:ro php:7.2 php /app/index.php
[...]
consumed memory: 103.11M

$ docker run --rm -v $PWD/index.php:/app/index.php:ro php:7.3 php /app/index.php
[...]
consumed memory: 108.81M

Там нет никаких проблем, когда я запускаю его с помощью простой лампы.
Что может вызвать эту проблему на appengine flex с официальным образом appengine flex php docker?
Ссылка на официальный Google appengine php docker репозиторий github:
https://github.com/GoogleCloudPlatform/php-docker

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector