#32727 [Com]: Slow serialize on FreeBSD
| From: | runner at protom dot org | Date: | Wed, 27 Apr 2005 01:02:20 +0000 |
| Subject: | #32727 [Com]: Slow serialize on FreeBSD | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-78248@lists.php.net to get a copy of this message | ||
ID: 32727
Comment by: runner at protom dot org
Reported By: cws at miraclenet dot co dot th
Status: Open
Bug Type: Performance problem
Operating System: FreeBSD
PHP Version: 4.*, 5.*
New Comment:
Very Good!
Previous Comments:
------------------------------------------------------------------------
[2005-04-19 02:48:30] cws at miraclenet dot co dot th
I forget to mension that the previous result is
from my patched version.
The result of unpatch one is
cws@t42# ./php test_serialize.php
version:4.3.11
Length: 2798041
Serialize time: elapse(2.554760)
------------------------------------------------------------------------
[2005-04-19 02:36:12] cws at miraclenet dot co dot th
No it don't help me to speed up my test code.
This is the result
cws@t42$ ./php test.php
Content-type: text/html
X-Powered-By: PHP/5.1.0-dev
<PRE>version:5.1.0-dev
Length: 2798041
Serialize time: elapse(2.136879)
cws@t42$ /usr/local/bin/php test.php
<PRE>version:4.3.11
Length: 2798041
Serialize time: elapse(0.200818)
The test code and data can be download at
http://freebie.miraclenet.co.th/tmp/test_serialize.tgz
The test data may seem too extreme (an array of 2.8M) but it is the one
that our customer really use.
------------------------------------------------------------------------
[2005-04-16 16:38:42] sniper@php.net
Please try using this CVS snapshot:
http://snaps.php.net/php5-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php5-win32-latest.zip
PHP 5.1-dev has got some optimizing done in this part, see if it's any
better (without your patch of course)
------------------------------------------------------------------------
[2005-04-16 13:39:18] cws at miraclenet dot co dot th
This is a patch
t42# diff -u ext/standard/php_smart_str.h /home/cws/php_smart_str.h
--- ext/standard/php_smart_str.h Wed Apr 16 16:12:37 2003
+++ /home/cws/php_smart_str.h Sat Apr 16 18:27:30 2005
@@ -32,6 +32,10 @@
#define SMART_STR_PREALLOC 128
#endif
+#ifndef SMART_PTR_MAX_PREALLOC
+#define SMART_PTR_MAX_PREALLOC 1048576
+#endif
+
#ifdef SMART_STR_USE_REALLOC
#define SMART_STR_REALLOC(a,b,c) realloc((a),(b))
#else
@@ -42,8 +46,11 @@
if (!d->c) d->len = d->a = 0; \
newlen = d->len + n; \
if (newlen >= d->a) {\
- d->c = SMART_STR_REALLOC(d->c, newlen +
SMART_STR_PREALLOC + 1, what); \
- d->a = newlen + SMART_STR_PREALLOC; \
+ size_t pre_alloc = newlen *2;\
+ if ( pre_alloc > SMART_PTR_MAX_PREALLOC ) { pre_alloc =
SMART_PTR_MAX_PREALLOC; }\
+ if ( pre_alloc < SMART_STR_PREALLOC) { pre_alloc =
SMART_STR_PREALLOC; }\
+ d->c = SMART_STR_REALLOC(d->c, newlen + pre_alloc + 1,
what); \
+ d->a = newlen + pre_alloc; \
}\
}
------------------------------------------------------------------------
[2005-04-16 13:08:32] cws at miraclenet dot co dot th
Description:
------------
serialize use a lot of realloc which are very slow on FreeBSD
From - http://rgarciasuarez.free.fr/p5p/p5p-200307-1.pod
-
Dan Kogai explained that FreeBSD comes with an implementation of
malloc()
that is optimized for paged memory, and safe from duplicate free()
calls.
But the downside is that realloc() is very slow. That's usually not a
big
deal, because most programs don't use realloc() very often -- but perl
does. (The default configuration of perl on FreeBSD is to use perl's
internal malloc, that hasn't this realloc limitation.)
Serialize use a fix incremental value (SMART_STR_PREALLOC in
php_smart_ptr.h). It better for serialize to use exponential
incremential value to reduce number of realloc.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=32727&edit=1