Executing the following code increases the usage memory more and more as requested memory is requested.
using version: latest
use Aws\Sqs\SqsClient;
$client = new SqsClient([
'profile' => 'default',
'region' => 'ap-northeast-1',
'version' => '2012-11-05'
]);
while (true) {
$receiveMessage = $client->receiveMessage([
'AttributeNames' => ['SentTimestamp'],
'MaxNumberOfMessages' => 1,
'MessageAttributeNames' => ['All'],
'QueueUrl' => 'http://192.168.20.31:4576/queue/test', // REQUIRED
'Endpoint' => 'http://192.168.20.31:4576',
'WaitTimeSeconds' => 0,
]);
echo memory_get_usage();
}
I think that there is something that the guzzle sync method obtained keeps on for the promise that has not been scheduled yet maybe.
Hi @sh-ogawa, thanks for reaching out to us about this. This behavior sounds similar to #1645 where we found that the SDK (or one of its dependencies) does appear to have cyclic references that have to be cleaned up by PHP's garbage collector, however garbage collection does occur naturally after a certain amount of references have built up.
When running the code you provided I see that memory usage builds up from 3.29MB to about 8.19MB across ~500 iterations of the loop before PHP's garbage collection begins naturally. This is a result of the SDK favoring a faster runtime over a lighter memory footprint, however you can call gc_collect_cycles() manually to override this behavior. Including this function at the end of the loop resulted in the memory usage remaining at a consistent 3.29MB instead of slowly increasing to ~8MB before garbage collection begins automatically.
Hi @diehlaws , thanks for your reply.
We can also manually invoke garbage collection in PHP.
It became very helpful, so I would like to try this suggestion.
Thank you very much.
I was able to confirm that the memory does not continue to increase by using gc_collect_cycles().
Thank you very much.
Is this being caused by this following issue:
https://forums.aws.amazon.com/message.jspa?messageID=695298
The short of it being something with cURL SSL verification being leaky.
Most helpful comment
Hi @sh-ogawa, thanks for reaching out to us about this. This behavior sounds similar to #1645 where we found that the SDK (or one of its dependencies) does appear to have cyclic references that have to be cleaned up by PHP's garbage collector, however garbage collection does occur naturally after a certain amount of references have built up.
When running the code you provided I see that memory usage builds up from 3.29MB to about 8.19MB across ~500 iterations of the loop before PHP's garbage collection begins naturally. This is a result of the SDK favoring a faster runtime over a lighter memory footprint, however you can call
gc_collect_cycles()manually to override this behavior. Including this function at the end of the loop resulted in the memory usage remaining at a consistent 3.29MB instead of slowly increasing to ~8MB before garbage collection begins automatically.