MagicWand memory leak

MagickWand for PHP is an object-oriented PHP interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning MagickWand for PHP.
Post Reply
GiantRabbit

MagicWand memory leak

Post 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

Code: Select all

<?php phpinfo; ?>
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.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post 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.
GiantRabbit

Post 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.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post 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.
GiantRabbit

Post 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:
  1. PHP-4.4.0. : 98.4 Kb --> 1 Gb
  2. PHP-4.4.2.2 : 98.4 Kb --> 1 Gb
  3. PHP-4.4.2.2 * : 99.1 Kb --> 112,7 Kb
  4. 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)
theillustratedlife

Post by theillustratedlife »

GiantRabbit:

Can you please post a more stable dll? I'd hate to crash a shared server with my little experiments. . . :cry:

Thanks much!
Post Reply