New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Probable memory leak in PHP extension 1.37.0 #26085
Comments
Will look into this. |
It only happens when protobuf extension is enabled. Here is the report of valgrind: ZEND_DONT_UNLOAD_MODULES=1 USE_ZEND_ALLOC=0 valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes php test.php It may be caused by It appears to be the same as protocolbuffers/protobuf#8525 and haberman is working on it for a complete solution as there seems to be some other similar leaks as well. |
I was quite sure protobuf did not matter... However, I did some tests again, and it seems to confirm that protobuf is indeed the culprit. Memory usage (MB)
However, I kept also track of required time to retrieve and process all XML data. It seems enabling gRPC increases the required time, especially when protobuf is disabled. In that case, the CPU utilization of the PHP process also reaches 100%. This was a bit of a surprise to me. Avg time (seconds).
Should I report this in a new issue? |
Yes it's expected - the protobuf extension is supposed to provide a much better performance boost. It's less efficient to use the protobuf composer package. (Btw, the 2 tables above were slightly mis-aligned - it's a bit hard to read) |
The fixes in protocolbuffers/protobuf#8614 make the protobuf C extension Valgrind-clean (except for a few edge cases involving exceptions that I was not able to figure out). This should be released in the next week or two as a patch release of 3.17.x. |
I do indeed expect less performance when disabling the protobuf extension. I did not expect an increased performance when I disable both. This should be a bit easier to read:
(time required to fetch ~125 MB of XML data) |
Need to address memory leak: grpc/grpc#26085
What version of gRPC and what language are you using?
gRPP version 1.37.0 for PHP 7.2.24
What operating system (Linux, Windows,...) and version?
Ubuntu 18.04
uname:
Linux $hostname 5.4.0-72-generic #80~18.04.1-Ubuntu SMP Mon Apr 12 23:26:25 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
What runtime / compiler are you using (e.g. python version or version of gcc)
PHP 7.2.24-0ubuntu0.18.04.7 (cli) (built: Oct 7 2020 15:24:25) ( NTS )
gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Also tested on Ubuntu 20.04:
PHP 7.4.3 (cli) (built: Oct 6 2020 15:47:56) ( NTS )
gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
What did you do?
When querying GCP's Cloud Datastore using the gRPC PECL extension, it will return (in our case) 29k entities containing XML snippets, totaling for ~125 MB of XML data. We got error messages stating out-of-memory errors in our PHP application. Given the two files described below, I query GCP's Datastore. This example does depend on a preconfigured and pre-filled GCP Project though.
composer.json:
test.php:
Script has been run using CLI.
What did you expect to see?
I expected to see reasonably memory usage.
What did you see instead?
Memory usage is very high, considering PHP output buffering in pretty small (even disabled for CLI) and no entities are being held in memory by this code. Using grpc pecl extension, memory usages is up to 204 MB:
<!-- Item #: 28702, usage: 204 MB, peak usage: 204 MB -->
Anything else we should know about your project / environment?
grpc/grpc
instead of the PHP extension. When using this, memory usage stays at a reasonably low level:<!-- Item #: 28702, usage: 14 MB, peak usage: 18 MB -->
The text was updated successfully, but these errors were encountered: