tags:

views:

21

answers:

1

Hi,

I have a website which loads images from a CDN. I have a requirement to check for the existence of 100s of images on the CDN.

I am using this code to achieve this:

Protected Function RemoteImageExists(ByVal Path As String) As Boolean

    Dim httpRequest As HttpWebRequest = CType(WebRequest.Create(Path), HttpWebRequest)

    httpRequest.Method = "HEAD"

    Try

        Dim httpResponse As HttpWebResponse = CType(httpRequest.GetResponse, HttpWebResponse)

    Catch ex As Exception
        Return False 'Undesirable flow, but seems unavoidable :(
    End Try

    Return True

End Function

This is still very slow, and many requests timeout. Is there a faster way to do this?

WT

A: 

Several suggestions:

  1. If the CDN can serve dynamic content, hosting a service on the CDN which will deliver the list of images would be the best approach in terms of performances.

  2. Are the images in the same directory? If yes, configure CDN to show the list of files available, and query this list. Parsing HTML is an ugly thing, but since the format of those HTML files will not change unexpectedly one day, it can be an acceptable.

  3. If the first two are impossible, use Parallel extensions depending on circumstances (it may make things faster or slower).

  4. Exceptions are slow. Get rid of them. Using sockets directly may help (even if it's ugly).

By the way, finding the bottleneck may help finding a better solution. For example, if the bottleneck is the processor power, Parallel extensions may help, but if is the bandwidth or CDNs performances, it will just slow everything down. Note that the bottleneck may be either the local machine, the local connection, the overall connection or the CDN.

MainMa
Found a solution - the CDN (Rackspace) has an API I can use to get the file list. Thanks for your suggestions!
Wild Thing