best way to put the MagickImage object in the cache

258 Views Asked by At

I have two web servers and many images on AWS S3. I load these images from S3 as memorystream and convert that stream into a Bitmap. Then I create a MagickImage obejct from that Bitmap and then apply my MagickImage commands on it.

These images are kind of template that the application uses them many times during the day, maybe 60 times or more in one hour couple tens of them. Converting bitmap to, or even directly converting stream/Memorystream, into MagickImage is a heavy process takes cpu time.

For now I have put the bitmap into the Cache and remove the call to S3; I get a memorystream from cache and convert it into the Bitmap. This helps a lot but not enough, my system is still suffering from performance.

Now the question: When I create the MagickImage object how can I keep it? I have to find a way to remove the converting Bitmap to MagickImage.

I know (maybe i am wrong) I have two ways to keep it: 1) put the MagickImage object in the Cache which is not a good Idea because as I am using out-of-process cache (because we have two web servers) I have to convert the MagickImage obejct into memoryStream and then when I want to load it from cache I have to convert it back again to MagickImage which is too slow. 2) I can save the MagickImage as ".mpc" file but these files are just effective if the MagickImage object has been created in the same machine. With two web servers this is not effective.

0

There are 0 best solutions below