Closed Vheclis closed 1 year ago
@Vheclis I see that this has been raised as a bug for PHP as well. However, I just cannot repro it in my local:
JSON_DECODE Count | Memory usage (in MB) | Peak memory usage (in MB) |
---|---|---|
1000 | 2 | 3 |
2000 | 2 | 3 |
3000 | 2 | 3 |
4000 | 2 | 3 |
5000 | 2 | 3 |
6000 | 2 | 3 |
7000 | 2 | 3 |
8000 | 2 | 3 |
9000 | 2 | 3 |
10000 | 2 | 3 |
My environment details:
google-cloud-php/Core % php -v (git)-[main]-
PHP 8.0.28 (cli) (built: Apr 26 2023 19:05:33) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.28, Copyright (c) Zend Technologies
with Xdebug v3.1.5, Copyright (c) 2002-2022, by Derick Rethans
google-cloud-php/Core %
Closing because unable to repro
Environment details
Hi guys, we have a consumer that consumes from a Kafka topic that is getting increasing amounts of memory on our docker container, after each message. I ran a memory profiling using this extension (https://github.com/arnaud-lb/php-memory-profiler) for PHP, and checked the data using pprof (https://github.com/gperftools/gperftools). I gathered info on the first message consumed and after ten messages, then compared both profiling to see were memory has increased, and a json_decode call was the one who was leaking the most memory, as I'm showing on the image below.
After that, i took the time to go to that part of code
src/RequestBuilder.php
on his constructor (you can see that is there where the main memory is leaking if u see the top square, with nameGoogleCloudCoreRequestBuilder__construct
) and change so that the use of json_decode got unset/set to null after i used it, just to see if my consumed memory was lower.For my surprise, it worked. I ran the profiling again, and see how that changed
There is memory leak, but so much less and from another source. Before making sure json_decode response objects were being freed, i was getting around 8mb per message on RAM. With the change, its close to 0.5mb maximum.
I tried recreate StorageClient on each message consume handle, but even with that there was no effect on the leak. Do you guys agree that this could be a problem on the API or there is something i could do on my side to fix this?
Below I'm sending the
src/RequestBuilder.php
altered just for reference, so you guys can see what i changed so that json_decode was freed. I don't think that we should do something like that to fix, was just a test to see if the problem was really there.