The first time delay can be due to a combination of the following:
- Time to resolve the server DNS entry
- Time to download the proxy
autoconfig script, compile and
execute it to determine the
effective proxy
- network latency from your app to the proxy server (if there is a proxy server in your environment)
- network latency from
the proxy server to the actual
destination server.
- The latency on
the server to serve the XML
document. If it has to traverse an
in-memory object representation and
generate the XML document, that
might take some time. Also, if it is
using techniques like
XML-Serialization to generate the
document, then depending on how the
serializer is configured, the first
call to serialize/deserialize always
takes a long time, due to the fact
that an intermediate assembly needs
to be generated and compiled.
- Parsing the XML on the client side
might take time, esp if the XML
document structure is very complex.
- If XLinq (like the XMLSerializer)
generates temp assembly for the XML
parsing & querying, then the first
request will take more time than the
subsequent ones.
To figure out which part is taking time, insert some time logging into your code using System.Diagnostics.Stopwatch():
// this is the time to get the XML doc from the server, including the time to resolve DNS, get proxy etc.
System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
timer.Start();
HttpWebResponse resp = (HttpWebResponse)request.GetResponse();
timer.Stop();
Console.WriteLine("XML download took: " + timer.ElapsedMilliseconds);
timer.Start();
// now, do your XLinq stuff here...
timer.Stop();
Console.WriteLine("XLinq took: " + timer.ElapsedMilliseconds);
You can insert a loop around this, and see what the difference for the various components between the first request and subsequent requests is.
If you find that the difference is in the downloading, and not the querying, then you can investigate further by getting a network sniff using Wireshark.
Hope this helps.