php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #81536 Add ini option to not retain cached allocator chunks across requests
Submitted: 2021-10-18 07:03 UTC Modified: 2021-12-01 15:21 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:0 (0.0%)
From: dev at alepe dot com Assigned:
Status: Open Package: Performance problem
PHP Version: 7+ OS: Linux
Private report: No CVE-ID: None
 [2021-10-18 07:03 UTC] dev at alepe dot com
Description:
------------
PHP7-PHP8 is not releasing "Resident Memory" back to the OS after use (specially Wordpress sites). PHP5 works as expected, example:

PHP5  : 10MB ---> 95MB ---> 10MB
PHP7+ : 10MB ---> 95MB ---> 95MB

Versions Used:
* PHP7 versions 7.2, 7.3, 7.4 and 8.0 (running as FastCGI in lighttpd)
* Linux OS: Alpine 3.10, Alpine 3.14 and Ubuntu 20.04
* Wordpress: 5.7, 5.8

I have tested it without Wordpress (using the provided test script) but the result is not conclusive (across versions), however when using Wordpress, it always happen.

We noticed after several sites (about 500 sites) were updated from PHP 5 to PHP 7 (running in LXD containers), as the memory consumption increased about 3 to 4 times, making the server performance to go down drastically (server started to swap more often). Even when the sites are not accessed for a long time, the memory is not released.

Settings: Almost all sites are running the default settings (opcache is OFF)

Memory checking tools: `htop`, `top` and `lxc info`

Modules used:

ctype
curl
date
dom
filter
gd
hash
iconv
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcre
readline
Reflection
session
SPL
standard
xml
xmlreader
xmlrpc
xmlwriter
zip
zlib


Test script:
---------------
<?php
// NOTE: this code SOMETIMES produces the problem described above, 
//       and sometimes it won't.
$m = "";
for($i = 0; $i < 110000; $i++) {
    $m .= "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii";
}
sleep(3);
echo "DONE";
?>



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-10-18 08:18 UTC] cmb@php.net
This looks like a duplicate of bug #80108.

Also note that PHP 7.3 is no longer actively supported[1].

[1] <https://www.php.net/supported-versions.php>
 [2021-10-18 08:48 UTC] nikic@php.net
It would probably make sense to add an ini option to not retain cached allocator chunks across requests. The current caching strategy assumes that the PHP process is going to be rapidly reused, which is not the case in this particular setup with many rarely accessed sites served by independent PHP processes.
 [2021-10-18 10:16 UTC] dev at alepe dot com
I think the related bug report may be related, however executing `gc_mem_caches()` didn't worked for me. I added it in both: `auto_prepend_file` and `auto_append_file` directives. I confirmed the code is being executed. Tested in two separate containers in two separate servers (hosts).
 [2021-10-18 10:19 UTC] dev at alepe dot com
I forgot to mention that I also tried it directly (without the php.ini directives). It always returns "0".
 [2021-10-19 04:23 UTC] dev at alepe dot com
-PHP Version: 7.3.31 +PHP Version: 7+
 [2021-10-19 04:23 UTC] dev at alepe dot com
Assuming the problem comes from Zend Engine Memory management I agree with nikic@php.net, setting an option to turn ON/OFF this feature would be useful for hosting companies.
 [2021-12-01 15:21 UTC] cmb@php.net
-Summary: Resident Memory not returned after use +Summary: Add ini option to not retain cached allocator chunks across requests -Type: Bug +Type: Feature/Change Request
 [2023-01-31 11:15 UTC] neskemiquel at gmail dot com
The APC extension from retaining cached allocator chunks between requests and will free up memory each time a request is processed. Note that disabling this cache may have a negative impact on performance, so it's important to carefully evaluate the trade-offs before making this change.

<https://www.portal4me.org/>github.com
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 10 22:01:28 2024 UTC