Speeding up a Directory Search Process

  • Thread starter Thread starter Robert Barnett
  • Start date Start date
R

Robert Barnett

I having trouble querying for users that have changed, when I have a node that have over 750 users. It takes way to long over 1 hour, if it does return users. How can I improve this?



objADSDirEntry = New DirectoryEntry(sInADSADsPath, strADSUserName, strADSPassword, AuthenticationTypes.ServerBind)
ObjADSDirSearcher = New DirectoryServices.DirectorySearcher(objADSDirEntry)
Err.Clear()
ObjADSDirSearcher.Filter = "(&(|(objectClass=user)(objectClass=group)(objectClass=contact))(&(uSNChanged>=" & LastMod & ")(uSNChanged<=" & NewLastMod & ")))"
'ObjADSDirSearcher.PageSize = 1000
ObjADSDirSearcher.ServerTimeLimit = TimeSpan.FromMinutes(3)
For Each objSearchResult In ObjADSDirSearcher.FindAll
objadsDirEntry2 = objSearchResult.GetDirectoryEntry


Thanks

Robert
 
Take a look at this whitepaper:

http://msdn.microsoft.com/library/en-us/dnactdir/html/efficientadapps.asp

--
Dmitri Gavrilov
SDE, Active Directory Core

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm


I having trouble querying for users that have changed, when I have a node
that have over 750 users. It takes way to long over 1 hour, if it does
return users. How can I improve this?



objADSDirEntry = New DirectoryEntry(sInADSADsPath, strADSUserName,
strADSPassword, AuthenticationTypes.ServerBind)
ObjADSDirSearcher = New DirectoryServices.DirectorySearcher(objADSDirEntry)
Err.Clear()
ObjADSDirSearcher.Filter =
"(&(|(objectClass=user)(objectClass=group)(objectClass=contact))(&(uSNChange
d>=" & LastMod & ")(uSNChanged<=" & NewLastMod & ")))"
'ObjADSDirSearcher.PageSize = 1000
ObjADSDirSearcher.ServerTimeLimit = TimeSpan.FromMinutes(3)
For Each objSearchResult In ObjADSDirSearcher.FindAll
objadsDirEntry2 = objSearchResult.GetDirectoryEntry


Thanks

Robert
 
I tried a lot of this. It is still pausing after about 500 results. It waits
a long time, for new results. Much more then it intially did.
 
THis is my current code.

ObjADSDirSearcher.Filter =
"(&(|(objectCategory=Person)(objectCategory=Group))(&(uSNChanged>=" &
LastMod & ")(uSNChanged<=" & NewLastMod & ")))"

ObjADSDirSearcher.SearchScope = SearchScope.OneLevel

sw.WriteLine(ObjADSDirSearcher.Filter)

ObjADSDirSearcher.PageSize = 500

' ObjADSDirSearcher.CacheResults = F

'ObjADSDirSearcher.ServerTimeLimit = TimeSpan.FromMinutes(3)

' ObjADSDirSearchResults = ObjADSDirSearcher.FindAll

'sw.WriteLine(ObjADSDirSearchResults.Count)

' Parse Users

For Each objSearchResult In ObjADSDirSearcher.FindAll
 
One thing you might consider doing is not using the Count property on the
SearchResultCollection object. The way it works, the collection needs to
enumerate the entire result to get the number of results returned because it
doesn't know the count in advance, so you are basically enumerating twice.
I would avoid using it. It looks like you have the commented out, but it
was sitting there in the code...However, setting CacheResults to False is a
good idea as you only need that if you needed to go back through the
collection.

Otherwise, your filter is not searching on only indexed attributes, so that
part is good. Just out of curiosity, does it go faster if don't use the
upper bound condition on uSNChanged and just look for things newer than the
LastMod value? I'm not sure if your query will work correctly that way or
not.

Another idea to try would be to remove the objectCategory clauses in the
filter and just skip the objects that are returned that aren't the right
type. I'm not sure if that would be faster or not, but it is worth a shot.

Joe K.
 
Back
Top