IHttpHandler or IHttpAsyncHandler for Image server

338 Views Asked by At

My task is to develop an Image server, that will:

  • load images from disk
  • resize it, according to HTTP parameter
  • apply one or more watermarks to the original image

The question is what technology should I use, I am going to do it with IHttpHandler, but I wonder if using IHttpAsyncHandler will be faster for this scenario?

Can I benefit from processing images asynchronously in IHttpHandler?

Also maybe I should consider some high level framework e.g. NancyFx or just return the images from controller (MVC2)?

2

There are 2 best solutions below

8
usr On

Asynchronous IO does not make IO faster in any way. It unblocks a thread while that IO runs. All CPU work that is being performed is not impacted at all.

In some cases it is a good idea to use async IO to unblock threads, in others it is a waste of dev time with no benefit to customers whatsoever. Do you expect a high number of concurrent image downloads (like 100 (at the same time!))? Then async IO can be of benefit.

Probably, you should not be using IHttpHandler for anything. Use MVC.

0
Robert McKee On

I would consider using http://imageresizing.net - Redeveloping this would likely cost you or your employer many times over the cost of licensing it. Doing image resizing on the fly is hard to do right. Based on what you describe for your needs, I believe the license would even be free. Only if/when you go beyond your simple needs would you need to upgrade to a pay license.

If you decide to try and roll your own, I suggest reading this first: http://www.nathanaeljones.com/blog/2009/20-image-resizing-pitfalls which will pinpoint some of the pitfalls to try and avoid.