ports/81093: lang/php4 - Slow serialize on FreeBSD
Chatchawan Wongsiriprasert
cws at miraclenet.co.th
Mon May 16 06:50:03 UTC 2005
>Number: 81093
>Category: ports
>Synopsis: lang/php4 - Slow serialize on FreeBSD
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-ports-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Mon May 16 06:50:02 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator: Chatchawan Wongsiriprasert
>Release: 4.8 , 5.4
>Organization:
MiracleNet Group
>Environment:
FreeBSD server3.miraclenet.net 4.8-RELEASE-p27 FreeBSD 4.8-RELEASE-p27 #1: Mon Mar 14 23:10:10 UTC 2005 cws at server3.miraclenet.net:/usr/obj/usr/src/sys/RACKSPACE-US i386
FreeBSD server4.miraclenet.net 5.4-RELEASE-p1 FreeBSD 5.4-RELEASE-p1 #1: Mon May 16 00:39:02 EDT 2005 cws at server4.miraclenet.net:/usr/obj/usr/src/sys/SERVER4 i386
>Description:
Serialize use a fix incremental value (SMART_STR_PREALLOC in
php_smart_ptr.h) to expand the serailized string. It better for serialize to use exponential incremential value to reduce number of realloc because
realloc is very slow on FreeBSD
It took about 2 seconds to serialize 2MB array on FreeBSD. The same code run about 0.2 second on Linux
>How-To-Repeat:
The test code and data can be download at
http://freebie.miraclenet.co.th/tmp/test_serialize.tgz
>Fix:
apply the patch http://freebie.miraclenet.co.th/tmp/patch-php_smart_str.h
--- ext/standard/php_smart_str.h.org Wed Apr 16 16:12:37 2003
+++ ext/standard/php_smart_str.h Wed Apr 20 14:17:21 2005
@@ -29,7 +29,11 @@
#define smart_str_0(x) do { if ((x)->c) { (x)->c[(x)->len] = '\0'; } } while (0)
#ifndef SMART_STR_PREALLOC
-#define SMART_STR_PREALLOC 128
+#define SMART_STR_PREALLOC 1024
+#endif
+
+#ifndef SMART_PTR_MAX_PREALLOC
+#define SMART_PTR_MAX_PREALLOC 1048576
#endif
#ifdef SMART_STR_USE_REALLOC
@@ -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; }\
+ else 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; \
}\
}
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-ports-bugs
mailing list