I posted this on StackOverflow but was not able to find an answer so hopefully I can find one here.

I'm running into a problem with cpu / memory usage while using Magick.Net in my server application. A single request in itself increases what is used and as more users are on combined with files that contain many pages, it can grind the server to a halt. I wonder if I am missing something in my code, if there is a way to optimize, or if I just need to limit resources.

This process pulls in a collection of byte arrays from another source with each one representing a single page. It then combines them into a single file which is returned as a byte array.

I am currently using Q16 and I'm thinking of using Q8 since it uses less resources, as long as the image quality is still good. In the long run, I may also setup another server to run this process if I can't find another solution.

Wanted to provide a response to say that using Q8 did improve the resource use without diminished quality for our situation. I am still interested to see if there is any additional settings I can use to improve the resource use.

Have you looked at https://imagemagick.org/script/resources.php policy.xml, for example "throttle" for CPU usage? However, these impose limits on ImageMagick. I don't know what effect they would have on your compiled programs.

I tried using throttle but it seemed to make it even slower, although it's possible I had it configured incorrectly. I'm also worried that if it hits a certain threshold it's just going to make it slower for everyone else.

"Throttle" limits the rate at which a process will consume CPU cycles. This means more processes can run without saturating the CPU (which I think you want), but an obvious side-effect is that each process will run more slowly.

Pegging a server usually is a result of a large image consuming memory resources. To prevent that, limit the memory resource so that any large images are forced to disk instead. We have a server that supports ImageMagick processes and we generally never have a performance issue. We describe how we set policies to ensure uninterrupted service @ https://imagemagick.org/script/security-policy.php.