0

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.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
Meysam
  • 555
  • 1
  • 3
  • 16
  • What is an `mcp` file? What is the actual technology of the thing you refer to as `Cache`. Have you parallelised the conversions of the images - I mean is the problem that it takes 40 seconds to convert N images and you want them sooner - in which case you could parallelise? Or is the problem that it takes so much CPU your server can't cope with its other responsibilities in which case parallelising might make it worse. What times are you seeing? What processing are you doing? What language and what OS are you using? How chunky is your server - RAM/CPUs? – Mark Setchell Jul 21 '16 at 08:15
  • sorry by mcp I meant MPC "Magick Persistent Cache image file format". I am using Memcache. I have paralleised the conversions. Let me explain more: I have to load 6 different images each of them is around 2 MG size and then convert them to MagickImage. Each conversion takes about 300 to 400 ms. Consider that I have 50 users online at the same time so the cpu time is about 50 x 6 x 300 ms = 90 s just for 50 users. Now I have 10 users and it is still not critical but it will grow soon. my application is MVC c# , and our servers is on Amazon AWS. Both servers have about 60 GIG ram. – Meysam Jul 21 '16 at 09:24
  • One idea may be to use REDIS as a cache... http://stackoverflow.com/a/32268028/2836621 – Mark Setchell Jul 21 '16 at 09:39
  • 1
    `.mpc` files should be interchangeable between machines as long as you are running the same IM version. – Mark Setchell Jul 21 '16 at 10:03

0 Answers0