Friday, March 20, 2009

.NET 1.1 LDAP performance: System.DirectoryServices.DirectorySearcher lags!

This short posting describes performance problem with .Net 1.1 LDAP (in particular, System.DirectoryServices namespace). Problem was solved.

VB.NET 1.1 performance problem with System.DirectoryServies.DirectorySearcher
While working on one of my projects (VB/C# .Net 1.1), I've run into strange performance problems. Controls were loading slowly. After some research, I narrowed the problem - server made several requests to ActiveDirectory through LDAP protocol. Each of those requests took about 7-8 seconds to complete. Same program, written on Java, worked blazingly fast.
Honestly saying, I spent several days fixing this problem.

Problem is caused by DirectorySearcher implementation
Problem was actually caused by System.DirectoryServices library (really a COM wrapper) having some lags with memory allocation, or something like that. I'll add a link once find it in bookmarks.
So, each time request is performed, it at first spends 7 seconds for authentication, or something like that.

Possible solution (worked for me)
Honestly: I did not manage to make this correct. What I've done, is just a plain caching. So, I just saved link to System.DirectoryServices.DirectorySearcher in the static (even not instance, byt in Class variable!), and pinged it in some period.

Caching for DirectorySearcher gave expected results
Yes. First query was awfully long. But subsequent calls were re-using the initialized object, and thus were working blazingly fast! As there are no side effects yet - application is web application, its uptime is more than 2 months.

Useful links on DirectorySearcher performance problem

No comments: