none
XDocument.Load() takes ~14 seconds to read a simple xml file from Windows Server 2008 R2 IIS. RRS feed

  • Question

  • Hi,

    I am using the below code to read an XML file from virtual directory (application hosted in IIS)

    DateTime beforeStart = DateTime.Now;
    
    var document = XDocument.Load("http://WindowsServer2008R2Machine/Site/ConfigurationFiles/Configuration.xml");
    
    DateTime afterCompletion = DateTime.Now;
    
    TimeSpan timeDiff = afterCompletion.Subtract(beforeStart);
    
    MessageBox.Show("XDocument.Load took ~14 Milliseconds");

    Trail 1:

    Approach1: IIS present in Windows Server 2008 R2. XDocument.Load() code takes ~14 seconds.

    Approach2: IIS present in Windows Server 2008 R2. Application.GetRemoteStream() code takes ~14 seconds.

    Approach3: IIS present in Windows Server 2008 R2. XMLDocument.Load() code takes ~13 seconds.

    All these approaches timings are so consistent for first time application launch but second time read onwards it takes less than 100 milli seconds.

    Trail 2:

    Approach1: IIS present in Windows Server 2008 R2. XDocument.Load() code takes > 100 ms.

    Approach2: IIS present in Windows Server 2008 R2. Application.GetRemoteStream() code takes > 100 ms.

    Approach3: IIS present in Windows Server 2008 R2. XMLDocument.Load() code takes > 100 ms.

    No first time business here. Every time above 3 approaches takes > 100 milliseconds.


    During My application start up, I need to read the XML file to get the configuration. Due to above reasons, whenever I connect to Windows Server 2008 R2, application start up takes long time.

    Do I need to upgrade / update Windows Server 2008 R2 machine?

    Could some one please help me solving this or any workaround? 


    Thanks and Regards

    Harish Reddy Arumalla

    Senior Software Engineer

    Yokogawa IA Technologies Pvt Ltd, Bangalore


    Wednesday, June 4, 2014 12:57 PM

All replies

  • Since you are loading a file using a URL it is hard to tell whether the issue is related to the network overhead or the XML loading.  It shouldn't take 14 seconds to load an XML file though so my thought is it is probably on the remote server.  If you're using IIS on the remote server then I'd look into whether the app pool that is associated with the site has idled out and therefore you're seeing the site startup costs.  This is more likely if the first request is slow after you've waited a while but fast after that.  I'd recommend trying to retrieve the file outside your code (maybe using your browser) and see how long it takes.

    Michael Taylor
    http://msmvps.com/blogs/p3net

    Wednesday, June 4, 2014 5:43 PM
    Moderator
  • Thanks for the reply.

    I see very peculiar behavior with Window Server 2008.

    Same code execution from any other machine (tried from Windows 7 & Windows 8), then it is faster (>100 milliseconds) and As you said I tried from browser to open that configuration xml (enterting the url directly in the browser) also faster (~10 milliseconds).

    Peculiarity is reading from same machine (i.e. Windows Server 2008) is taking long time and If I specify the IP address, then only it is taking long time. If I specify either localhost or system name in the url, it is not taking long time.

    Could you please suggest which areas I need to look further to analyze better ?

    Regards

    Harish


    Thanks and Regards Harish Reddy Arumalla Senior Software Engineer Larsen and Toubro Ltd, IES, Mysore

    Friday, June 6, 2014 4:42 AM
  • Hi Harish,

    Per my understanding, one possible reason is XmlDocument spends time to read the namespace DTD’s defined in the document. See more from http://stackoverflow.com/questions/5657374/why-does-this-xml-file-load-slowly. So try to load XmlDocument without DTD, use the code on the following link. http://go4answers.webhost4life.com/Example/ignore-dtd-loading-xml-document-13874.aspx.

    Please let me know the result.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, June 6, 2014 7:38 AM
    Moderator
  • Thanks for the reply.

    I tried the way it is mentioned in the links that are given. Still the problem exists. I wonder where the problem is is it really with XML parsing class libraries or with the OS i.e. Server 2008 or with the firewall when we specify the IP address?

    Not able to figure out what would the real cause of the problem. So it may not be good for me to just try in one angle.

    Would it be better, If I post the same question in another category?

    Regards

    Harish Reddy


    Thanks and Regards Harish Reddy Arumalla Senior Software Engineer Larsen and Toubro Ltd, IES, Mysore


    Wednesday, June 11, 2014 4:18 AM
  • Hi Harish,

    Did you mind build a webservice to get the XML? Try it and see the time cost.

     > Would it be better, If I post the same question in another category?

    You can post thread on Microsoft Connect. But I think it’s hard for our product term to reproduce your problem. https://connect.microsoft.com/.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, June 11, 2014 7:45 AM
    Moderator