Bug #71468 [Nab]: increased memory usage with mysqli in php 7
| From: | nikic@php.net | Date: | Mon, 22 Feb 2016 18:46:59 +0000 |
| Subject: | Bug #71468 [Nab]: increased memory usage with mysqli in php 7 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-199399@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71468&edit=1
ID: 71468
Updated by: nikic@php.net
Reported by: ryan dot brothers at gmail dot com
Summary: increased memory usage with mysqli in php 7
Status: Not a bug
Type: Bug
Package: MySQLi related
Operating System: Linux
PHP Version: 7.0.2
Block user comment: N
Private report: N
New Comment:
I've implemented some tweaks in master to reduce memory usage for this case
(https://github.com/php/php-src/commit/2d1559f827477963a3f8a40af64212a409ba9457). There's more
that can be done here, but this was the lowest hanging fruit.
Previous Comments:
------------------------------------------------------------------------
[2016-02-22 18:23:25] rendername at gmail dot com
Ok, we maked new tests to see, how much memory was used for mysqli_query on process:
PHP5: before query 23m, after 237m => so we have 214m (memory_get_usage 45m) NOT OK
PHP7: before query 20m, after 270m => so we have 250m (memory_get_usage 250m) OK
So, php7 need a little more memory for this query, but we get memory usage correctly.
------------------------------------------------------------------------
[2016-02-22 16:18:41] ryan dot brothers at gmail dot com
Thanks for the feedback. I understand the changes, but my scripts in PHP 7 are hitting the memory
limit when they didn't in PHP 5.6, yet one of the advantages of PHP 7 is reduced memory usage.
Is there someone more familiar with the change in mysqlnd that can look into it further to determine
if PHP 7 will use more memory than PHP 5.6 and not less?
------------------------------------------------------------------------
[2016-02-22 15:59:49] nikic@php.net
Which isn't to say that there is nothing wrong with how mysqlnd manages memory. I'm not
familiar with mysqlnd, but the way this works does look distinctly weird. Apart from wasting memory
by being unnecessarily generic (having free_chunk and resize_chunk with always the same values, for
every single chunk) it's very odd to see the chunks being allocated at all -- what's the
point of using an arena allocator if you still use a full blown memory manager for the metadata?
------------------------------------------------------------------------
[2016-02-22 15:38:16] nikic@php.net
store_result uses mysqlnd mempool chunks. In PHP 5.6 those used the system allocator
(http://lxr.php.net/xref/PHP_5_6/ext/mysqlnd/mysqlnd_block_alloc.c#120). In PHP 7.0 they use the
Zend MM (http://lxr.php.net/xref/PHP_MASTER/ext/mysqlnd/mysqlnd_block_alloc.c#119).
So the memory usage didn't actually change (or rather, it did change, but not in a bad way), it
simply wasn't reported previously by memory_get_usage().
------------------------------------------------------------------------
[2016-02-22 14:36:08] ryan dot brothers at gmail dot com
Yes, I am using mysqlnd. I confirmed I'm seeing the memory usage increase comparing the latest
PHP 5.6.18 and PHP 7.0.3 using the reproduce script above.
5.6.18:
mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $
7.0.3:
mysqlnd 5.0.12-dev - 20150407 - $Id: f59eb767fe17a6679589b5c076d9fa88d3d4eac0 $
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=71468
--
Edit this bug report at https://bugs.php.net/bug.php?id=71468&edit=1