开发者

Programming against Azure / CDN

We're in the process of moving an on premise application to the Azure cloud. Internal corporate users routinely upload full size images via an admin interface to our website (these will now be sent to Azure blob storage). The site is responsible for creating the correct images sizes when they are requested. So what happens right now (on premise environment) is this:

1) User uploads full size file.

2) When a smaller version is requested through GetImage HTTP handler (i.e. http://www.site.com/GetImage.aspx?imageid=15&height=100&width=100) the handler checks to see if we have previously created a version of that image in that size. If so, it writes it directly to the Response stream. If not, it takes a second to resize it, save it to the "/iamges/cache" directory and writes the resized image to the Response stream.

3) Next time that file is requested in that size it returns the previously created image.

So I want to implement the same type of mechanism using Azure and Blob storage, but I have a couple of concerns:

1) I can't simply check to see if a blob exists. I have to download the blob first, then call FetchAttributes to see if it throws an exception. However, doing this actually downloads the image. So doesn't this double the number of requests for images (one to see if it exists and another to display to the user)?

2) Let's say the image does not exist in the size I need it (i.e. the blob /images/cache/image_15_100_100.jpg does not exist -- id #15, 100x100 pixels). So I've hit a request to the CDN once to see if it exists. Now I have to download possibly a 5-10 MB full size image (as opposed to reading it off our on-premise file system which is fast), load that 5-10 MB image in memory, resize it and re-upload it to the CDN. This seems time consuming, especially when I could have 10-15 of these images on a single request.

I know Azure is relatively new, but is there anything close to a "best practice" for this type of interaction with blob storage? Is there another approa开发者_开发问答ch that I could consider? This just seems a lot of overhead for image resizing so I figure I must be missing something or overlooking another solution.


OK, I think there's lots going on here. My answer is based on these assumptions:

  • The final use for these images is to be displayed on a website
  • The website mentioned above is running on Azure
  • You want to use the CDN to speed up access to the images
  • You're using the .Net storage client library

If any of these assumptions are wrong, let me know and I'll edit my answer appropriately.

  1. You're right, there is no built in method in the .Net client library which allows you to check if a blob exists. But, by doing the .FetchAttributes() this doesn't actually download the image, it simply attempts to retrieve the header information (much like when you list all of the blobs in a container), the blobs aren't actually downloaded until you call one of the .DownloadX() methods.

  2. Your server side code has no need to talk to use any of the CDN functionality. It should just talk to your images in blob storage like they're any old blob. The only time you need to use the CDN URLs is when you're specifying the path to the images on the page you're displaying.

  3. You don't want you're website to have to return the stream of the image, you want it to point to a URL on the CDN that contains the image. The CDN will be able to deal with much more load than any website that you can build. The website can then check to see if the blob exists, if it does, just return the URL. If it doesn't download the full image, resize it, save it, then return the URL. While accessing the image from blob storage isn't as quick as reading it off of a local disk, it's still pretty quick, particularly for files <10MB like you're talking about.

  4. Presumably somewhere someone is specifying where and what size images to use in your site. Could you capture that and generate the resized image then?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜