General discussion about memory management #1590
Replies: 3 comments 12 replies
-
Briefly: ImageSharp's defaults are bad for ImageSharp.Web and Orchard. Those defaults have been determined in #475, by an ad-hoc, in-process load-testing method which had the assumption, that there won't be any caching on top of the library. This makes sense thinking of ImageSharp as a library on it's own, but seems to be counter-productive, when it's used together with ImageSharp.Web. If I get it right, in most web applications the variety of image sizes is low, and most images get cached immediately by the middleware, so the value of memory/array pooling seems to be much lower. If we are lucky, something like EDIT: I would actually try keeping
For this, we can try to call (Sidenote: Not being familiar with ImageSharp.Web codebase, I got confused about changing the default |
Beta Was this translation helpful? Give feedback.
-
On our production OrchardCore sites we tend to reset the default This is because we tend to run in Azure, on a low memory / or shared environment, and it becomes a bit resource hungry otherwise, and perhaps something we could introduce by default in OrchardCore. Particularly, if there are a few shared Orchard Core sites, all with ImageSharp.
This is not something we are doing, and yet it seems relevant. How periodically are we talking? once a minute / once in 5? Unless there is a plan to consider introducing a pool that shrinks, it would seem like something that we could and should run from a background task. It looks like it is just resetting the pools, so safe to call, at any point during a pending operation?
Sadly this is often not the case with CMS users, they have a tendency to want to upgrade large files from phones etc, which then get shrunk to tiny files. We quite regularly run into out of memory exceptions, due to the above, however |
Beta Was this translation helpful? Give feedback.
-
@antonfirsov I remember having a chat a while back (on gitter I think?) about the stress tests I ran on the usual set of imaging libraries and I told you I'd share my setup next time I did it. Well, I finally did it! The latest ImageSharp build had major CPU usage improvements, but the memory was still extreme in x64 builds and it still OOMs in x86 builds. Here's the project if you want to take a look: https://github.com/saucecontrol/core-imaging-playground/tree/beeees/MemoryStress |
Beta Was this translation helpful? Give feedback.
-
Just want to start a thread about how memory is best used in the library.
By doing a recent dump of Orchard Core on a page with a single image resized, I noticed the two
ArrayPool<char>
pools that are used in IS. One was 48MB AFAIR. I don't think these would grow higher with higher load, but maybe a solution could be found to use more granular array sizes, even if it can pool more arrays. Another approach that could be optimized is to have these pools shrink overtime since they should not be used once the images are actually resized, which I could prove by restarting the app, and querying the images would then not incur any allocations on these pools.Where it's defined:
ImageSharp/src/ImageSharp/Configuration.cs
Line 120 in a1784a6
The two pools:
ImageSharp/src/ImageSharp/Memory/Allocators/ArrayPoolMemoryAllocator.cs
Lines 19 to 27 in a1784a6
The
MemoryAllocator
seems to be configurable. I am wondering if that is the ultimate answer, and that I could just set these limits myself.Beta Was this translation helpful? Give feedback.
All reactions