apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andi Gutmans <a...@zend.com>
Subject Memory manager
Date Mon, 24 Jun 2002 20:07:43 GMT
Hi,

PHP uses memory allocation extensively. During the life cycle of a PHP 
script there is a huge amount of malloc()'s and free()'s. We found that 
under multi-threaded web servers this leads to decreased performance due to 
memory fragmentation and locking within the memory manager.
The solution is using per-thread memory pools which don't lock and are 
completely freed at the end of each request.
Win32 supports this kind of per-thread memory pool with the 
HeapCreate(HEAP_NO_SERIALIZE, ...) family of functions. Using these kind of 
functions gave us a huge performance gain.
Now with Apache 2 coming out I wanted to solve this problem in a 
cross-platform way as I don't have Bill's API available on UNIX :) The APR 
memory pools aren't good enough for us because they don't allow for any 
freeing which just doesn't work for PHP.
What we did was write a memory manager (similar to Doug Lea's malloc.c but 
much more lightweight) which allows you to have many instances (pools) and 
it supports allocation, freeing, reallocation. At the end of each request 
it quickly frees all of the huge memory chunks it used. I started using it 
with the new PHP scripting engine and am allocating memory in 64KB blocks 
(run-time definable) and it seems to work pretty well. To allocate the 
memory blocks themselves it uses malloc() which makes it extremely 
portable. (I actually got that idea from APR).

Do you guys have any interest in adding this kind of "smarter" memory pool 
into APR? I think it's extremely useful.

If you reply please cc: me because I'm not on the APR dev list.

Andi


Mime
View raw message