Page 1 of 1
MagicWand memory leak
Posted: 2006-07-31T11:02:53-07:00
by GiantRabbit
MagicWand leaks a lot off memory, and I mean a looot....
PHP 4.4.0
Apache/2.0.53
WindowsXP SP2
Also tested this on:
PHP 4.3.10
Windows 2000/Windows 200 SP4
Steps to reproduce:
1 - Create a test file
test.php
2 - With the code
3 - Make sure Magicwand exists in
php/extensions
4 - Make sure Magicwand is enabled in
php.ini with
Code: Select all
extension=php-4.4.0_magickwand_q32_st.dll
5 - Run a benchmark on the file. I used the
ab.exe in Apache bin dir, with the following command
Code: Select all
ab -n4000 http://localhost/bm/test.php
(or whereever u have put it).
Memory consumption goes from 16.220 Kb to 9980.16 Kb ....*ARGHHH*
To ensure it is MagicWand:
1 - Comment out the extension in
php.ini (step 4 above) like
Code: Select all
; extension=php-4.4.0_magickwand_q32_st.dll
2 - Restart Apache
3 - Run benchmark again.
No more huge memory consumption.
Posted: 2006-07-31T12:00:25-07:00
by magick
Don't use the Q32 version of MagickWand. Instead use the Q16 or Q8 version. Also make sure you are using a modern version of ImageMagick which allocates the pixel cache using anonymous memory mapping. Unlike the system heap, anonymous memory mapping is returned to the system when it is freed. ImageMagick also has the UseEmbeddedMagick define which allocates all memory with anonymous memory mapping and returns all memory to the system when it is freed. UseEmbeddedMagick is still experimental so we cannot assure you it is stable just yet.
Posted: 2006-08-01T05:47:18-07:00
by GiantRabbit
magick wrote:
Don't use the Q32 version of MagickWand. Instead use the Q16 or Q8 version.
Tried Q16 and Q8, still the same problem. With the php-4.4.0_magickwand_dyn.dll there is no such problem, but:
1 - Performance drop from 29.5 seconds to 105.9 seconds for 4.000 requests on
phpinfo() (as described in 1st post)
2 - I can't deliver a standalone ImageMagick with the product we deliver (integrated Apache/PHP + extensions). It all needs to be in 1 package. (Besides that, I have not looked into any licensing issues)
magick wrote:
Also make sure you are using a modern version of ImageMagick which allocates the pixel cache using anonymous memory mapping.
Im just using the *official* binaries from the magicwand website (no update since sep. 2005)
http://www.magickwand.org/download/php/ ... php-4.4.0/
magick wrote:
ImageMagick also has the UseEmbeddedMagick define which allocates all memory with anonymous memory mapping and returns all memory to the system when it is freed. UseEmbeddedMagick is still experimental so we cannot assure you it is stable just yet.
Ok, when I have some spare time, I'll try to compile and test a binary myself. But I'm probably not the only person on earth using the *offical* magicwand dll's.
Posted: 2006-08-01T07:11:30-07:00
by magick
The MagickWand for PHP window binaries should be updated. Unfortunately we have not heard from Watson, the MagickWand for PHP developer, for quite some time. Try building MagickWand for PHP from source and see if the problem persists.
Posted: 2006-08-07T06:07:34-07:00
by GiantRabbit
I did some extended benchmarking and builded a magicwand myself (hell!!!). Tested with 4000 iterations on ab.exe as described in my first post (Apache/2.0.53 - Windows XP SP2).
Here is a summary of memory consumption:
- PHP-4.4.0. : 98.4 Kb --> 1 Gb
- PHP-4.4.2.2 : 98.4 Kb --> 1 Gb
- PHP-4.4.2.2 * : 99.1 Kb --> 112,7 Kb
- PHP-4.4.2.2 ** : 101.2 Kb --> 114.8 Kb
The first two are tested with php-4.4.0_magickwand_q16_st.dll, the *official* binaries.
The third one is compiled without
UseEmbeddableMagick
The fourth one is compiled with
UseEmbeddableMagick
Conclusion
So, compile magicwand yourself and get rid of the (absurd) memory leaking.
Here is the ReleaseTS preprocessor definitons I used:
Code: Select all
ZEND_DEBUG=0,COMPILE_DL_MAGICKWAND,ZTS=0,ZEND_WIN32,PHP_WIN32,_WANDLIB_,_MAGICKLIB_
And these are the libraries included:
Code: Select all
CORE_RL_bzlib_.lib CORE_RL_coders_.lib CORE_RL_filters_.lib CORE_RL_jbig_.lib CORE_RL_jp2_.lib CORE_RL_jpeg_.lib CORE_RL_lcms_.lib CORE_RL_libxml_.lib CORE_RL_magick_.lib CORE_RL_png_.lib CORE_RL_tiff_.lib CORE_RL_ttf_.lib CORE_RL_wand_.lib CORE_RL_wmf_.lib CORE_RL_zlib_.lib php4ts.lib wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
Nb
(Pardon in my first post PHP version was 4.4.0 and NOT 4.3.10)
Posted: 2006-10-25T03:17:02-07:00
by theillustratedlife
GiantRabbit:
Can you please post a more stable dll? I'd hate to crash a shared server with my little experiments. . .
Thanks much!