From: basant dot kukreja at gmail dot com
Operating system: Solaris 10
PHP version: 5.2.9RC3
PHP Bug Type: Performance problem
Bug description: php_stream_fill_read_buffer degrades performance after PR
44607 is fixed
Description:
------------
After bug 44607 is fixed, php_stream_fill_read_buffer does many reallocs
for
medium to large file (e.g 60KB)
Before the bug 44607 was fixed, php_stream_fill_read_buffer returns after
single read so there was no reallocs. But after the fix, it keeps reading
until the entire file is read.
Reproduce code:
---------------
If we add a printf in php_stream_fill_read_buffer function like :
while (stream->writepos - stream->readpos < (off_t)size) {
size_t justread = 0;
size_t toread;
/* grow the buffer if required
* TODO: this can fail for persistent streams */
if (stream->readbuflen - stream->writepos <
stream->chunk_size) {
stream->readbuflen += stream->chunk_size;
fprintf(stderr, "php_stream_fill_read_buffer :reallocating
%d\n",
stream->readbuflen);
stream->readbuf = perealloc(stream->readbuf,
stream->readbuflen,
stream->is_persistent);
}
Then for a php script which includes 60KB html file, following
is printed.
stderr: php_stream_fill_read_buffer :reallocating 8192
stderr: php_stream_fill_read_buffer :reallocating 16384
stderr: php_stream_fill_read_buffer :reallocating 24576
stderr: php_stream_fill_read_buffer :reallocating 32768
stderr: php_stream_fill_read_buffer :reallocating 40960
stderr: php_stream_fill_read_buffer :reallocating 49152
stderr: php_stream_fill_read_buffer :reallocating 57344
Expected result:
----------------
Less number of memcpy. Because of the reallocs, huge amount of memcpy
happens. This happened after php-5.2.6.
http://bugs.php.net/bug.php?id=44607
Actual result:
--------------
Degrade in performance.
--
Edit bug report at http://bugs.php.net/?id=47487&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=47487&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=47487&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=47487&r=trysnapshot60
Fixed in CVS:
http://bugs.php.net/fix.php?id=47487&r=fixedcvs
Fixed in CVS and need be documented:
http://bugs.php.net/fix.php?id=47487&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=47487&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=47487&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=47487&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=47487&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=47487&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=47487&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=47487&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=47487&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=47487&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47487&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=47487&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=47487&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=47487&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=47487&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=47487&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=47487&r=mysqlcfg