开发者

Reuse imagemagick process instance in asp.net app

Well, creating thumbnail images in an asp.net app seems more painful then I ever thought.

I first used System.Drawing stuff but then I was not satisfied with the amount of code I had to write just to do some simple resizing on a fixed canvas, then I read about the controversial discussed warning by Microsoft that System.Drawing might or might no开发者_如何学Got work in asp.net web context and lastly the performance of Bitmap operations was rather bad.

So I switchted to Imagemagick (IM) in order to generate thumbnails. This works pretty well actually as I have experience in working with IM in PHP and creating a new System.Diagnostics.Process is a simple operation.

However, when I need to generate many thumbs in one request (30 or more) the CPU usage goes through the roof (100%) and stays there until the last thumb is created. Of course the images are cached once they are written but still - this worries me as there are other application on the server which should not hang forever when some uncached thumbs are created.

If you are not familiar with Imagemagick, here is an example of how I use it:

/path/to/im/convert.exe large.jpg ...some options... small.png

So for each image I create new convert.exe instance (via new System.Diagnostics.Process), and thats what probably puts so much CPU load on the server. Is there any better way to do this? Switching from Imagemagick to another image creation solution is not an option.

PS: Yes, this is a followup to my previous question imagemagick in asp.net via command line where I stated that I would go with the caching solution, but the high CPU usage I noticed when working with larger amounts of data seems like it might be problematic.


As long as you know all images that need converting before the first conversion starts you can use something like

convert.exe ( first_image.jpg ...some options... -write first_image_small.png +delete ) ( ... second image ... ) last_image ... options ... last_image_small.png

This way you won't have to create a new process for every image you want to convert.

If you're worried about one image conversion taking up too much cpu time you might also want to change the priority class of the imagemagick process, so that only the user who requested the images that need conversion will be affected by the conversion.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜