none
DirectoryEntry.Children incredibly slow under Windows 10/Server 2012R2 RRS feed

  • Question

  • Our shop has been incredibly behind the times(mostly due to finances) and outside factors are finally forcing the boss to spend money on replacing our aging servers(aka, UPS integration won't work with Server 2003 past May 2016 due to SSL).  I'm almost ready to swap out one of our three Server 2003 boxes with the Server 2012R2 box I've been setting up but discovered a huge issue that I've not figure out how to solve yet.

    We have admin tools that create websites dynamically.  The first task in this is finding out the next available SiteID that we can use on all of the servers.  Here's the code:

    private int GetMaxSiteID(string WebServer, string UserName, string Password)
            {
                int MaxSiteID = 1;
                using (DirectoryEntry root = new DirectoryEntry("IIS://" + WebServer + "/W3SVC", WebServer + "\\" + UserName, Password, AuthenticationTypes.FastBind))
                {
                    foreach (DirectoryEntry e in root.Children)
                    {
                        if (e.SchemaClassName == "IIsWebServer")
                        {
                            int ID = Convert.ToInt32(e.Name);
                            if (ID >= MaxSiteID)
                                MaxSiteID = ID + 1;
                        }
                    }
                }
                return MaxSiteID;
            }

    I'd just call GetMaxSiteID("WebServer1","MyUserName","MyPassword") and I could get my next available SiteID.  I'd run this for all three web servers and get my results in about 6 seconds when run from any of the two Server 2003 boxes and the one Server 2003R2 box.  I have slightly altered code that's thread safe and I get it down to about 3 and a half seconds on the production machines.

    When I run this on the new Server2012R2 box, it takes around *200* seconds to run when connecting to the Server 2003 machines and 100 seconds for the Server 2003R2 box and 19 seconds just to run on itself!  The insane part is when I use the Server 2003 box to connect to the Server 2012R2 box, it only takes 2.5 seconds, why would the reverse take 224 seconds?

    I figured I had some wrong code somewhere, so I ran it in debug mode on my Windows 10 machine and ended up getting even worse results!  What am I missing here?  I'm used to upgrading giving me performance improvements, not making the whole thing unusable.  This is going to be a slow transition of swapping out servers, so I have to use IIS 6 Compat mode.  I can't rewrite everything using newer tech.

    I've tested this with 3 Windows 10 machines, two Server 2012R2, 2 Server2003, 1 Server2013R2, 2 Vista, 2 XP, and 1 Server2008R2.  The Windows 10 and Server 2012R2 machines are insanely slow.

    This is what the timings look like under 2003/2003R2/XP/Vista/Server2008R2.

    Here's the timings during calls on Server2003 to Server2012R2.

    DirectoryEntry root = new DirectoryEntry 46.8861ms
    DirectoryEntry e in root.Children 328.2027ms
    DirectoryEntry e in root.Children 15.6287ms
    DirectoryEntry e in root.Children 0ms
    DirectoryEntry e in root.Children 0ms
    DirectoryEntry e in root.Children 0ms
    DirectoryEntry e in root.Children 0ms
    DirectoryEntry e in root.Children 0ms
    DirectoryEntry e in root.Children 15.6287ms
    DirectoryEntry e in root.Children 0ms
    DirectoryEntry e in root.Children 0ms
    DirectoryEntry e in root.Children 0ms
    DirectoryEntry e in root.Children 0ms
    DirectoryEntry e in root.Children 15.6287ms
    DirectoryEntry e in root.Children 0ms
    DirectoryEntry e in root.Children 0ms
    DirectoryEntry e in root.Children 0ms
    DirectoryEntry e in root.Children 0ms
    DirectoryEntry e in root.Children 0ms
    DirectoryEntry e in root.Children 15.6287ms
    DirectoryEntry e in root.Children 0ms
    DirectoryEntry e in root.Children 0ms
    DirectoryEntry e in root.Children 0ms
    DirectoryEntry e in root.Children 0ms
    DirectoryEntry e in root.Children 15.6287ms

    It has this pretty distinct pattern.

    This is what I get with my Windows 10 machine and get relatively the same results with the other Windows 10 and Server 2012R2 machines.

    DirectoryEntry root = new DirectoryEntry 15.6294ms
    DirectoryEntry e in root.Children 731.6665ms
    DirectoryEntry e in root.Children 153.2571ms
    DirectoryEntry e in root.Children 146.7677ms
    DirectoryEntry e in root.Children 153.2511ms
    DirectoryEntry e in root.Children 147.1619ms
    DirectoryEntry e in root.Children 168.8826ms
    DirectoryEntry e in root.Children 162.8028ms
    DirectoryEntry e in root.Children 137.689ms
    DirectoryEntry e in root.Children 162.3126ms
    DirectoryEntry e in root.Children 153.68ms
    DirectoryEntry e in root.Children 147.216ms
    DirectoryEntry e in root.Children 153.6665ms
    DirectoryEntry e in root.Children 146.7686ms
    DirectoryEntry e in root.Children 153.4868ms
    DirectoryEntry e in root.Children 165.9102ms
    DirectoryEntry e in root.Children 150.1817ms
    DirectoryEntry e in root.Children 153.6632ms
    DirectoryEntry e in root.Children 146.7526ms
    DirectoryEntry e in root.Children 168.8699ms
    DirectoryEntry e in root.Children 147.1472ms
    DirectoryEntry e in root.Children 153.235ms
    DirectoryEntry e in root.Children 162.7893ms
    DirectoryEntry e in root.Children 138.05ms
    DirectoryEntry e in root.Children 162.7808ms

    Here's where I ran the routine and got the total number of seconds.

    Count of sites is 560

    WebServer1 Server 2003
    WebServer2 Server 2003
    WebServer3 Server 2003R2
    WebServer5 Server 2012R2
    DevMachine Windows 10 16042-2217

    WS1 running on WebServer1   0.859
    WS2 running on WebServer1   3.500
    WS3 running on WebServer1   2.391
    WS5 running on WebServer1   2.531

    WS1 running on WebServer2   5.000
    WS2 running on WebServer2   1.640
    WS3 running on WebServer2   3.922
    WS5 running on WebServer2   4.031

    WS1 running on WebServer3   3.156
    WS2 running on WebServer3   4.328
    WS3 running on WebServer3   0.781
    WS5 running on WebServer3   1.609

    WS1 running on WebServer5 214.047
    WS2 running on WebServer5 198.594
    WS3 running on WebServer5  92.812
    WS5 running on WebServer5  19.250

    WS1 running on DevMachine 224.620
    WS2 running on DevMachine 314.421
    WS3 running on DevMachine 142.573
    WS5 running on DevMachine 161.133

    Notice that the Server 2003(WebServer1, 2, and 3) reading from the Server 2012R2 IIS(WebServer5) took 1.6 to 4 seconds.  Meanwhile, 2012R2 to itself took 19.25 seconds!  I'm pulling my hair out trying to figure out what I'm missing here.  I don't have a Windows 7 or 8 machine left to play with to see which end of the spectrum they fall on.  All of this is highly reproducible and a show stopper for me right now.

    Friday, April 8, 2016 7:35 PM

Answers

  • Hi Jason,

    When checking from MSDN DirectoryEntry.Children Property, it looks nothing unusual.

    But based on your description, it looks like an issue under Windows 10/Server 2012R2.

    To make this issue is a bug or not, I would suggest you also test on other Windows 10/Server 2012R2 clean machine, please also note that what the .Net framework target is. As far as I know, WinXP/Win2k3  support a maximum of .Net framework 4.0. But Windows 10/Server 2012R2 can support .net 4.6. Please check if it related to .Net framework.

    If the results are same, please report this issue to MS Connect, some engineer comes from MS will help you resolve it.  Thanks for your effort.

    If you have any updates, please post here. (Reproduce demo is also important, you can upload it to oneDrive)

    Best regards,

    Kristin


    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.


    Monday, April 11, 2016 2:55 AM
  • https://connect.microsoft.com/VisualStudio/feedback/details/2580546/directoryentry-children-incredibly-slow-under-windows-10-server-2012r2

    Thanks for proving that I'm not crazy. :D

    Tuesday, April 12, 2016 1:27 PM

All replies

  • Hi Jason,

    When checking from MSDN DirectoryEntry.Children Property, it looks nothing unusual.

    But based on your description, it looks like an issue under Windows 10/Server 2012R2.

    To make this issue is a bug or not, I would suggest you also test on other Windows 10/Server 2012R2 clean machine, please also note that what the .Net framework target is. As far as I know, WinXP/Win2k3  support a maximum of .Net framework 4.0. But Windows 10/Server 2012R2 can support .net 4.6. Please check if it related to .Net framework.

    If the results are same, please report this issue to MS Connect, some engineer comes from MS will help you resolve it.  Thanks for your effort.

    If you have any updates, please post here. (Reproduce demo is also important, you can upload it to oneDrive)

    Best regards,

    Kristin


    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.


    Monday, April 11, 2016 2:55 AM
  • As a fyi, I originally targeted 4.0. Then tried 2.0 on all the machines, 3.5, and then 4.6 on the Windows 10 and Server 2012R2 machines. Exact same results.

    I'll see about rewriting it after I do my morning maint and get it uploaded so it can pass in server/username/password so others can run it.

    Monday, April 11, 2016 12:02 PM
  • As for the testing on different machines "I've tested this with 3 Windows 10 machines, two Server 2012R2, 2 Server2003, 1 Server2013R2, 2 Vista, 2 XP, and 1 Server2008R2.  The Windows 10 and Server 2012R2 machines are insanely slow." is from the original post.  I don't have a lot of other machines I could try.  I might be able to borrow my gf's Windows 8.1 notebook to see if it has the issue, but that's going to take a bit of convincing.

    Here's the link to the source code and compiled(target 4.0)

    https://onedrive.live.com/redir?resid=72D311029CF46C9E!594617&authkey=!AML07-su94Sz-98&ithint=file%2czip

    Here's just the source if someone doesn't want to bother downloading.

    using System;
    using System.DirectoryServices;
    
    namespace IISNewSiteID
    {
        class Program
        {
            static void Main(string[] args)
            {
                if (args == null || args.Length != 3)
                {
                    Console.WriteLine("IISNewSiteID.exe WebServer UserName Password");
                    Console.WriteLine("Example: IISNewSiteID WebServer1 WebServer1\\MyUserName MyPassword");
                }
                else
                {
                    DateTime dt = DateTime.Now;
                    int MaxSiteID = 1;
                    using (DirectoryEntry root = new DirectoryEntry("IIS://" + args[0] + "/W3SVC", args[1], args[2], AuthenticationTypes.FastBind))
                    {
                        Console.WriteLine("DirectoryEntry root = new DirectoryEntry " + DateTime.Now.Subtract(dt).TotalMilliseconds + "ms");
                        DateTime dt2 = DateTime.Now;
                        foreach (DirectoryEntry e in root.Children)
                        {
                            Console.WriteLine("DirectoryEntry e in root.Children " + DateTime.Now.Subtract(dt2).TotalMilliseconds + "ms");
                            dt2 = DateTime.Now;
                            if (e.SchemaClassName == "IIsWebServer")
                            {
                                int ID = Convert.ToInt32(e.Name);
                                if (ID >= MaxSiteID)
                                    MaxSiteID = ID + 1;
                            }
                        }
                    }
                    Console.WriteLine("Next available SiteID " + MaxSiteID + " took " + DateTime.Now.Subtract(dt).TotalSeconds + "s ");
                }
            }
        }
    }
    

    Monday, April 11, 2016 1:15 PM
  • Hi Jason,

    I also tested your code on my side, looks the same result with yours. Maybe this is a bug. It could be better to submit this issue to MS Connect, if you finished it, please also post the link here, I will help you vote it.

    Tuesday, April 12, 2016 7:11 AM
  • https://connect.microsoft.com/VisualStudio/feedback/details/2580546/directoryentry-children-incredibly-slow-under-windows-10-server-2012r2

    Thanks for proving that I'm not crazy. :D

    Tuesday, April 12, 2016 1:27 PM
  • Hi Jason,

    Please remember to close this thread by marking helpful reply as an answer.

    Best regards,

    Kristin


    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, April 15, 2016 5:21 AM
  • Issue is currently at connect. Not resolved. Will update thread with resolution once had.
    Monday, April 18, 2016 11:17 AM