imageresizer

HybridCache size won't go over 1,08gb with cacheSizeMb set to 100000


First of all, we are using the v5 .net 4.8 version of the image-resizer with HybridCaching hosted on Azure. A couple of days ago we upgraded from v4 to v5 because we wanted more control over the max size of the cache.

For context, we are using the resizer to serve resized images (mostly thumbnail sized) to around 50000 users with upwards of 100000 request an hour

We've set the cacheSizeMb to 100000 but now, after a couple of days, the size of the cache won't go over 1,08gb. The application also has a very high cpu usage, resulting in many more instances then we are used to running at the same time within Azure (we scale out on a certain cpu threshold)

Webconfig:

<hybridCache cacheLocation="D:\home\imageresizercache" cacheSizeMb="100000" />

Now, this should be 100gb of cache. However, I find this in your read-me file about the HybridCache (https://github.com/imazen/resizer/blob/8f7e340d3bd6a6b9e6ddb5d8eb04b7b0a2bd1b81/plugins/ImageResizer.Plugins.HybridCache/README_HYBRIDCACHE.md)

<hybridCache cacheSizeMb="1,000" /> is in bytes and cannot be set below 9MB (9,000,000) or no files will be cached. 1GiB is the suggested minimum.

I am assuming this is incorrect and it is indeed mb, not bytes.

Then we've experimented with deploying a lower cacheSizeMb of only 11 on our test enviroment, to see how it behaves. I found this piece of code (https://github.com/imazen/resizer/blob/4a8aa521f0648c6e08a9a58099315025207e47d1/plugins/ImageResizer.Plugins.HybridCache/HybridCachePlugin.cs#L273)

if (_cacheOptions.CacheSizeMb < 100)issues.Add(new Issue("HybridCache", "cacheSizeMb should not be set below 100 MiB, 1GB is the suggested minimum . Found in the <hybridCache /> element in Web.config.","Setting a value too low will increase latency, increase cache misses, waste energy and reduce server performance.", IssueSeverity.ConfigurationError));

giving me the impression that with these settings, I should be seeing an issue on the resizer.debug.ashx page, which I don't.

If necessary I can post or email the contents of the resizer.debug.ashx to you or send the url so you can look for yourself.


Solution

  • Update: This is fixed in the 5.0.11-preview08 release.

    I think I've found the bug in configuration loading. Lines 56-59 aren't storing the values back in _configOptions, just local variables. I assume this happened during a recent refactor to move cache creation outside the method. I'm out sick today, but it should be an easy fix.

    https://github.com/imazen/resizer/blob/4a8aa521f0648c6e08a9a58099315025207e47d1/plugins/ImageResizer.Plugins.HybridCache/HybridCachePlugin.cs#L56

    And yeah, it should be Mb, the docs didn't get updated with the last refactor.