The first delay can be caused by a combination of the following:
- Time to resolve DNS server records
- Proxy server autoconfig script load time, compile and execute it to determine effective proxy
- Network timeout from your application to the proxy server (if your environment has a proxy server)
- network timeout from the proxy server to the actual target server.
- Server latency for serving XML document. If it needs to go through the representation of an object in memory and generate an XML document, which may take some time. In addition, if it is using methods such as XML serialization to generate the document, then depending on how the serializer is configured, the first to call serialization / deserialization always takes a lot of time, due to the fact that an intermediate assembly is required to create and compile.
- Parsing XML on the client side may take time, esp, if the XML structure of the document is very complex.
- If XLinq (such as XMLSerializer) generates a temporary assembly for XML parsing and querying, then the first query will take longer than the subsequent ones.
To figure out which part takes time, paste some time 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 is for the different components between the first query and subsequent queries.
If you find that the difference is in the download, and not in the request, then you can continue the study by receiving a network sniff using Wireshark .
Hope this helps.
feroze
source share