php-vips icon indicating copy to clipboard operation
php-vips copied to clipboard

Question: any way to get memory usage?

Open alexander-schranz opened this issue 5 years ago • 7 comments

I'm trying to debug some memory usages but couldn't find anything in vips to get the real memory usage. I'm searching for a equivalent to imagicks $imagick->getResource(\Imagick::RESOURCETYPE_MEMORY);

alexander-schranz avatar Jan 09 '20 11:01 alexander-schranz

Hello @alexander-schranz,

libvips has calls to do this, but they are not exposed by php-vips-ext, unfortunately. If you are OK compiling stuff yourself, you could add a few lines to vips.c, perhaps here:

https://github.com/libvips/php-vips-ext/blob/master/vips.c#L2073

Something like:

	vips_snprintf(digits, 256, "%zd", vips_tracked_get_mem_highwater());
	php_info_print_table_row(2, "Memory high water", digits);

Will add a line to php-info giving the memory high water in bytes.

That's the high water mark for memory directly allocated by libvips for image data (pixel buffers). It won't include things like libvips internal hash tables etc. etc.

jcupitt avatar Jan 09 '20 12:01 jcupitt

I added some stuff for this. It would probably be better to have some API.

If you're seeing high memory usage, I would check that you are using sequential where you can, and that references are not being held accidentally. You could try disabling the libvips operation cache, though I wouldn't myself.

https://libvips.github.io/php-vips/docs/classes/Jcupitt.Vips.Config.html#method_cacheSetMax

I'd be happy to look at your code if you can make a small example which shows high usage.

jcupitt avatar Jan 09 '20 12:01 jcupitt

We added lately support for the imagine vips adapter and I just wanted to compare memory usage vips vs imagick in the case how we convert images in sulu.

Sadly I'm not familiar about compiling vips myself it would be create if the library could provide functions to access the memory usage of it.

alexander-schranz avatar Jan 09 '20 12:01 alexander-schranz

You don't need to compile libvips, just the binary extension for PHP. There are notes on the process here:

https://github.com/libvips/php-vips-ext#development-regenerate-build-system

It's just:

phpize
./configure
make
sudo make install

But if you are using imagine, you should be OK. You could watch RES for the php process to track memory usage under load.

jcupitt avatar Jan 09 '20 12:01 jcupitt

@jcupitt Ok I'm getting the infos know in the phpinfo() but calling vips_tracked_get_mem_highwater() or vips_tracked_get_mem() itself doesnt work or what is the name of the function?

alexander-schranz avatar Jan 14 '20 21:01 alexander-schranz

But think the values are not comparable or I'm just not sure how vips or imagick calculate them. Imagick returns me 8,25mb using the above function and Vips returns me 69mb (mem) 1,28GB (mem_highwater)

alexander-schranz avatar Jan 14 '20 21:01 alexander-schranz

We'd need to make some kind of reproducible benchmark to track down high memory usage.

If you can make a standalone script that does what you need, I'd be happy to investigate.

jcupitt avatar Jan 14 '20 22:01 jcupitt