Performance Issue

Sep 14, 2011 at 8:17 PM

Hello I'm hoping that someone can help me please.

I have installed AD LDS on my dev machine and I am now using the code below to perform queries on around 15 users that I have added. Each search takes around 6 seconds, is there something that I am not doing correclty?

I  have installed the latest beta release from Aug 15 to try and fix theissue, however it hasn' helped

        public List<User2> GetUsers2(List<string> searchTerms)
        {
            List<User2> users = null;

            using (var context = new DirectoryContext(Connection, true))
            {
                IQueryable<User2> query = null;

                if (searchTerms != null)
                {
                    query = context.Query<User2>().Where(u => u.DisplayName.Contains("Niall"));

                    users = query.ToList();
                }
            }

            return users;
        }

        public LdapConnection Connection2
        {
            get
            {
                if (connection2 == null)
                {
                    if (LdapConfiguration.LdapConnectionFactory == null)
                    {
                        new LdapConfiguration().ConfigureFactory("MY_SERVER");
                        new LdapConfiguration().AddMapping(new UserMap2());
                    }

                    connection2 = LdapConfiguration.LdapConnectionFactory.GetConnection();
                }

                return connection;
            }

            set { connection = value; }
        }

        #endregion
    }

    public class UserMap2 : ClassMap<User2>
    {
        public UserMap2()
        {
            NamingContext("CN=Employees,DC=MY_DOMAIN,DC=local");
            ObjectClass("user");

            DistinguishedName(x => x.Key);
            Map(x => x.DisplayName).Named("cn");
        }
    }

    public class User2
    {
        public string Key { get; set; }
        public string DisplayName { get; set; }
    }

Thank you in advance for any help.

 

 

Coordinator
Sep 28, 2011 at 2:44 AM
Edited Sep 28, 2011 at 2:45 AM

Hi ultramods,

The first potential problem is the server name when building the connection.  I noticed that when using S.DS.P and AD LDS, creating a connection is significantly longer if I use the name of my machine instead of "localhost".  Secondly, although I don't think 15 entries is enough to cause that sort of performance issue, Microsoft does not recommend performing contains or endswith wildcard searches on attributes that don't have a medial index.  x.DisplayName.StartsWith("...") will perform a lot better than x.DisplayName.Contains("...").  Please see this article for more information: http://msdn.microsoft.com/en-us/library/ms808539.aspx#efficientadapps_topic01ee.

Oct 15, 2011 at 1:54 PM

Thanks madhatter22, I switched to using localhost and this has made a huge difference.