Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise libvips operation cache defaults #1585

Closed
jcupitt opened this issue Mar 23, 2020 · 5 comments
Closed

Revise libvips operation cache defaults #1585

jcupitt opened this issue Mar 23, 2020 · 5 comments

Comments

@jcupitt
Copy link
Member

jcupitt commented Mar 23, 2020

The libvips operation cache is useful if you are doing many operations on a few images, but less useful if you are doing a few operations on many images. Web servers, for example, will often do just one or two operations on millions of images.

  1. We could set the libvips operation cache defaults to much smaller numbers, perhaps the last 10 operations and just a few MB of memory. People could grow the cache if they wanted.
  2. Alternatively, we could keep the current default, but have an environment variable (VIPS_SERVER?), compile-time option or API which turns down all the defaults. It'd be handy to have a single control which set everything small.

Any thoughts? Other options? My 2p would probably be option 2., but I'm very persuadable.

@lovell
Copy link
Member

lovell commented Mar 24, 2020

I believe most sharp users who change the defaults do so only to disable caching entirely.

https://github.com/search?q=%22sharp.cache%28false%29%22&type=Code

@jcupitt
Copy link
Member Author

jcupitt commented Mar 24, 2020

@ioquatix your cache issue fyi.

@DFKSingleton
Copy link

My (long-running) program regularly reports its vips memory usage as per the following example:

Vips Sub-system
vips Cachegrosse:672
vips 'tracked mem' (Mb):99
vips max mem benutzt (Mb):145

I am doing relatively few operations on lots of images. The cache size can rise to nearly 1000.
PS: translating from German: Grosse -> Size and benuzt -> used

@jcupitt
Copy link
Member Author

jcupitt commented Jun 27, 2020

Another idea:

The libvips cache doesn't know about a lot of memory -- for example, if you use vips_image_new_from_memory(), it won't add that memory area to the tracked pool, and therefore it won't add to the pressure on the cache.

We could add a little API to the memory tracker to let operations record "foreign" memory, ie. memory allocations which libvips knows must be there, but which are not allocated and freed via tracked_new/tracked_free. Operations like vips_image_new_from_memory() could note memory on startup, and clear it during ::close handling.

Operations which have knowledge of foreign memory:

  • vips_image_new_from_memory() -- we should hook into foreign_buffer handling in vips_image_build()
  • vips_image_new_from_buffer() -- add some code inside foreign.c somewhere

Can anyone think of any others?

jcupitt added a commit that referenced this issue Jun 28, 2020
@jcupitt
Copy link
Member Author

jcupitt commented Jun 28, 2020

Actually maybe that's not a great idea. External memory could be from eg. mmap and should not be counted as a malloc.

I've just dropped the default cache_max to 100 operations.

@jcupitt jcupitt closed this as completed Jun 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants