473,405 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

DirectorySearcher first access speed

I have always been under the impression that LDAP was optimized for
speed. Fast queries, fast access, slower writes. I have a block of data
in LDAP and in SQL. Exact same data. The query is fast but the first
access to the result set takes longer that to do the query in SQL and
process the sql results.

From my trace.axd
LDAP Test Starting Search 0.000112 0.000043
LDAP Test Done Search 0.003821 0.003374 <--- fast query at .003 sec
LDAP Test Build XML Doc 0.003906 0.000086
LDAP Test For Loop 0.461937 0.458031 <-- The top of the for loop
Trace.Write(Name, "Build XML Doc");
for(int i=0; i<Results.Count; i++)
{
Trace.Write(Name, "For Loop");
.....

I have traced this down to the 'Results.Count' code. If I loop through
it in some other way then the first access into the search results then
takes the nasty hit. No matter what the access is, (the count or a
single property on a SearchResult object). I have re-arranged the loop
that goes through this result set a couple of different ways and
whatever does the first access into the data takes the at least a .44
sec hit.

Does anyone know what I am doing wrong?

-Cam
Nov 16 '05 #1
4 8162
Please post your code, and give us an idea about the size of the directory.
Some details about your configuration would help also.

Willy.

"cameron" <ca****************@appdepot.com> wrote in message
news:u8*************@TK2MSFTNGP12.phx.gbl...
I have always been under the impression that LDAP was optimized for speed.
Fast queries, fast access, slower writes. I have a block of data in LDAP
and in SQL. Exact same data. The query is fast but the first access to the
result set takes longer that to do the query in SQL and process the sql
results.

From my trace.axd
LDAP Test Starting Search 0.000112 0.000043
LDAP Test Done Search 0.003821 0.003374 <--- fast query at .003 sec
LDAP Test Build XML Doc 0.003906 0.000086
LDAP Test For Loop 0.461937 0.458031 <-- The top of the for loop
Trace.Write(Name, "Build XML Doc");
for(int i=0; i<Results.Count; i++)
{
Trace.Write(Name, "For Loop");
....

I have traced this down to the 'Results.Count' code. If I loop through it
in some other way then the first access into the search results then takes
the nasty hit. No matter what the access is, (the count or a single
property on a SearchResult object). I have re-arranged the loop that goes
through this result set a couple of different ways and whatever does the
first access into the data takes the at least a .44 sec hit.

Does anyone know what I am doing wrong?

-Cam

Nov 16 '05 #2
How large your tree is?
What object you are looking for?
What scope you are searching at?
What search condition you used?

The search depends on your whole AD tree, if the tree is too large, and you
also want to search all, then it shall be slow. After the first search, the
related informaiton is cached, then the sebsequent search should be faster.
But if you specify small cache setting, it will also effect your subsequent
searches.

Best regards,
Rhett Gong [MSFT]
Microsoft Online Partner Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.

Nov 16 '05 #3
The Code, I have tried to simplify it as much as possible:

....

Trace.Write(Name, "Starting Search");

DirectoryEntry DE = new DirectoryEntry( "LDAP://" + DN,
NTUsername, Password);
DirectorySearcher Searcher = new DirectorySearcher(DE);
Searcher.Filter = ValidDateFilter();
Searcher.PropertiesToLoad.Add("ADsPath");
Searcher.SearchScope = SearchScope.OneLevel;
SearchResultCollection Results = Searcher.FindAll();

Trace.Write(Name, "Done Search");

IEnumerator EnumResult = Results.GetEnumerator();
while(EnumResult.MoveNext())
{
SearchResult oResult = (SearchResult)EnumResult.Current;
Trace.Write(Name, oResult.Properties["ADsPath"][0].ToString());
}

Trace.Write(Name, "Done Loop");

....

// the filter
protected virtual string ValidDateFilter()
{
StringBuilder SearchFilter = new StringBuilder();
DateTime oBaseDate = new DateTime();
oBaseDate = DateTime.Now;

SearchFilter.Append("(&(appdepot-adxDocType=IDXFund.1)");
SearchFilter.Append("(!(&(appdepot-adxExpirationDate<=");
SearchFilter.Append(oBaseDate.ToUniversalTime().To String("yyMMddHHmmss")+"Z)");
SearchFilter.Append("(appdepot-adxExpirationDate=*)))");
SearchFilter.Append("(|(appdepot-adxReleaseDate<=");
SearchFilter.Append(oBaseDate.ToUniversalTime().To String("yyMMddHHmmss")+"Z)");
SearchFilter.Append("(!(appdepot-adxReleaseDate=*)))");
SearchFilter.Append("(|(appdepot-adxState=Approved)");
SearchFilter.Append("(!(appdepot-adxState=*)))");
SearchFilter.Append(")");

return SearchFilter.ToString();

}//ValidDateFilter

The directory has a at least a million objects in it, (I have never seen
a way to get the exact size from the AD so I am just guessing). As for
the configuration you will have to be more specific, I am a programmer
and have little to nothing to do with the AD configuration, but I can
ask if I know what you want me to ask.

-Cam

Willy Denoyette [MVP] wrote:
Please post your code, and give us an idea about the size of the directory.
Some details about your configuration would help also.

Willy.

"cameron" <ca****************@appdepot.com> wrote in message
news:u8*************@TK2MSFTNGP12.phx.gbl...
I have always been under the impression that LDAP was optimized for speed.
Fast queries, fast access, slower writes. I have a block of data in LDAP
and in SQL. Exact same data. The query is fast but the first access to the
result set takes longer that to do the query in SQL and process the sql
results.

From my trace.axd
LDAP Test Starting Search 0.000112 0.000043
LDAP Test Done Search 0.003821 0.003374 <--- fast query at .003 sec
LDAP Test Build XML Doc 0.003906 0.000086
LDAP Test For Loop 0.461937 0.458031 <-- The top of the for loop
Trace.Write(Name, "Build XML Doc");
for(int i=0; i<Results.Count; i++)
{
Trace.Write(Name, "For Loop");
....

I have traced this down to the 'Results.Count' code. If I loop through it
in some other way then the first access into the search results then takes
the nasty hit. No matter what the access is, (the count or a single
property on a SearchResult object). I have re-arranged the loop that goes
through this result set a couple of different ways and whatever does the
first access into the data takes the at least a .44 sec hit.

Does anyone know what I am doing wrong?

-Cam


Nov 16 '05 #4
Seems like you have some misconception on how LDAP really works.
Whenever you execute - Searcher.FindAll(); the LDAP server executes the
query applying the Filter criteria defined, and stores the resultset in an
internal buffer (at the server), the size of this resultset is limited at
max. 1000 objects.
In your case this query takes :
LDAP Test Done Search 0.003821 0.003374 <--- fast query at .003 sec
Now you start enumerating the resultset, executing something like :
[foreach(SearchResult sc in Results ); or Results.Count; ], at this point
the ADSI client starts to pull the buffered resultset from the server to the
client (and cache it at the client per default - see
DirectorySearcher.CacheResults), and does this in chunks of
DirectorySearcher.PageSize.
Note that the default for PageSize is 0, which means - transfer the whole
resultset (max. 1000 objects).
This is the 0.45 sec. hit you are taking, this transfer time highly depends
on the number of objects in the server buffer and the transport medium (see
1).
If you know that the resultset will be large and you don't want to take the
hit, You could try to set the PageSize value (let say to 10). This will
lower the hit taken, however, this hit will be taken for every 'pagesize'
transfered.

Hope this helps.
Willy.

[1] this is what I meant with configuration. If you are running the client
on a workstation over a network, you have to consider things like the
network speed/topology, authentication scheme, server resources (CPU's,
speed, memory), size of the AD, disk IO subsystem, number of AD users, type
of queries they run, etc.....
So I can't realy comment on the .45 seconds hit if I don't know the size of
the resultset, and the 'distance' between client and server.
If the resultset is 1000 objects and the connection is "same server" the a
..45 sec's hit looks quite normal.


"cameron" <ca****************@appdepot.com> wrote in message
news:ea*************@TK2MSFTNGP11.phx.gbl...
The Code, I have tried to simplify it as much as possible:

...

Trace.Write(Name, "Starting Search");

DirectoryEntry DE = new DirectoryEntry( "LDAP://" + DN,
NTUsername, Password);
DirectorySearcher Searcher = new DirectorySearcher(DE);
Searcher.Filter = ValidDateFilter();
Searcher.PropertiesToLoad.Add("ADsPath");
Searcher.SearchScope = SearchScope.OneLevel;
SearchResultCollection Results = Searcher.FindAll();

Trace.Write(Name, "Done Search");

IEnumerator EnumResult = Results.GetEnumerator();
while(EnumResult.MoveNext())
{
SearchResult oResult = (SearchResult)EnumResult.Current;
Trace.Write(Name, oResult.Properties["ADsPath"][0].ToString());
}

Trace.Write(Name, "Done Loop");

...

// the filter
protected virtual string ValidDateFilter()
{
StringBuilder SearchFilter = new StringBuilder();
DateTime oBaseDate = new DateTime();
oBaseDate = DateTime.Now;

SearchFilter.Append("(&(appdepot-adxDocType=IDXFund.1)");
SearchFilter.Append("(!(&(appdepot-adxExpirationDate<=");
SearchFilter.Append(oBaseDate.ToUniversalTime().To String("yyMMddHHmmss")+"Z)");
SearchFilter.Append("(appdepot-adxExpirationDate=*)))");
SearchFilter.Append("(|(appdepot-adxReleaseDate<=");
SearchFilter.Append(oBaseDate.ToUniversalTime().To String("yyMMddHHmmss")+"Z)");
SearchFilter.Append("(!(appdepot-adxReleaseDate=*)))");
SearchFilter.Append("(|(appdepot-adxState=Approved)");
SearchFilter.Append("(!(appdepot-adxState=*)))");
SearchFilter.Append(")");

return SearchFilter.ToString();

}//ValidDateFilter

The directory has a at least a million objects in it, (I have never seen a
way to get the exact size from the AD so I am just guessing). As for the
configuration you will have to be more specific, I am a programmer and
have little to nothing to do with the AD configuration, but I can ask if I
know what you want me to ask.

-Cam

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jayant Sane | last post by:
I am trying to search a user object that is located in a domain that is sub-ordinate to the one from where I begin my search. For eg. I have the domains as DC=corp,DC=company,DC=com and...
3
by: Zeno Lee | last post by:
I'm trying to authenticate a user against a windows network. I want it to work across any kind of windows network from NT 4.0 up to Windows 2003 ADS. So far I've been using DirectoryEntry and...
3
by: cameron | last post by:
I would like to do a search and have the results sorted by property 1 and then by property 2. My first thought had been //set up the searching object and call it oSearch...
2
by: Jason S | last post by:
Group, I'm hoping someone can shed some light on active directory search pagination for me. For the DirectorySearcher class there are several methods for paging (.PageSize,...
5
by: Dave | last post by:
Hi All C# ADSI samples that I run cause unspecified errors. If I translate them into VB.NET they run fine. Here's an example: public string getEmail(string LDAPPath, string username) {...
1
by: Jay | last post by:
I need to add a parameter to a directorysearcher.filter rather than using hard-coded text. I have the following code that finds all members of an AD group and then for each of those results tries...
6
by: cameron | last post by:
I have always been under the impression that LDAP was optimized for speed. Fast queries, fast access, slower writes. I have a block of data in LDAP and in SQL. Exact same data. The query is fast...
1
by: =?Utf-8?B?TGFtaXM=?= | last post by:
Hi, I have this code sample in my window application project : DirectorySearcher mySearcher = new DirectorySearcher("(CN=WMLIN2)"); foreach( SearchResult resEnt in mySearcher.FindAll()) and it...
2
by: Jim in Arizona | last post by:
I'm trying to do a check to see if a specific active directory user account exists in active directory AND a specific group. I can't seem to get the filter down right. I can do this to find a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.