[Mono-dev] Ldap and Threading

Mike Glenn mglenn at zoominternet.net
Sun Jan 15 12:00:45 EST 2006


I've been trying to track down some performance issues with a webmail
application that I've writing and I've run into some interesting issues.

First I wrote a simple console app to go through the steps I do for a user
login and profile the execution times. This app simply queues a method (2000
times), to the ThreadPool, that in this case takes an LDAPConnection from a
connection pool and attempts to bind and perform a search. The ldap
connection is then returned to the connection pool and the thread records
execution times. Once all threads complete I print out the time stats per
connection attempt. 

The only issue is that it never completes. The novell ldap lib throws the
following exception from one to three times:


Unhandled Exception: System.ArgumentException: length
in <0x005cc> System.Array:Copy (System.Array sourceArray, Int32 sourceIndex,
System.Array destinationArray, Int32 destinationIndex, Int32 length)
in <0x0004b> System.Array:Copy (System.Array sourceArray, System.Array
destinationArray, Int32 length)
in <0x00016> System.Collections.ArrayList:CopyTo (System.Array array)
in <0x0002a> System.Collections.ArrayList:ToArray ()
in <0x00048> Novell.Directory.Ldap.MessageVector:findMessageById (Int32
msgId)
in <0x001a7> Novell.Directory.Ldap.Connection+ReaderThread:Run ()
in (wrapper delegate-invoke) System.MulticastDelegate:invoke_void ()

Since this exception is thrown inside a thread created by the lib I never
have a chance to catch it and deal. Instead the ldap operation I'm
performing blocks and never completes.

I've also run into a few other issues with threading that I hope can either
be explained or otherwise dealt with.

First if I change the program to just create a new ldap connection each time
instead of using the connection pool things get interesting. The attached
file is a copy of the program setup for this type of run, I've removed the
host and search parameters that are specific to my app. But if you have an
ldap server it shouldn't be hard to set it up for a run against it.

On a single processor box (I've included /proc/cpuinfo and other important
info in the attached files) the program will complete sometimes. Other times
it never completes and throws no exception.

On a multiprocess or box it almost never completes and spits out a mixture
of the following two exceptions (mostly the first one):

Unhandled Exception: System.SystemException: Internal error, cannot create
clone: Thread was being aborted
in <0x0007b> Novell.Directory.Ldap.Asn1.Asn1Identifier:Clone ()
in <0x00230> Novell.Directory.Ldap.Asn1.LBERDecoder:decode (System.IO.Stream
in_Renamed, System.Int32[] len)
in <0x0004d> Novell.Directory.Ldap.Asn1.Asn1Structured:decodeStructured
(Asn1Decoder dec, System.IO.Stream in_Renamed, Int32 len)
in <0x00023> Novell.Directory.Ldap.Asn1.Asn1Sequence:.ctor (Asn1Decoder dec,
System.IO.Stream in_Renamed, Int32 len)
in <0x00041> Novell.Directory.Ldap.Rfc2251.RfcLdapMessage:.ctor (Asn1Decoder
dec, System.IO.Stream in_Renamed, Int32 len)
in <0x0017d> Novell.Directory.Ldap.Connection+ReaderThread:Run ()
in (wrapper delegate-invoke) System.MulticastDelegate:invoke_void ()

Unhandled Exception: System.IndexOutOfRangeException: Asn1Structured: set:
index 1, size 1
in <0x00107> Novell.Directory.Ldap.Asn1.Asn1Structured:get_Renamed (Int32
index)
in <0x0004c> Novell.Directory.Ldap.Rfc2251.RfcLdapMessage:.ctor (Asn1Decoder
dec, System.IO.Stream in_Renamed, Int32 len)
in <0x0017d> Novell.Directory.Ldap.Connection+ReaderThread:Run ()
in (wrapper delegate-invoke) System.MulticastDelegate:invoke_void ()

I've also noted that that the single processor box performs signficantly
faster (60ms per ldap bind and search) than the multiprocessor box (the few
times it does complete) (200ms or higher per ldap bind and search)

On top of that I've found that MONO_THREADS_PER_CPU has a big effect.
Setting it any higher than the default of 5 causes a performance drop on
both boxes and the deadlocks are more likely.

If on the other hand I set it to zero performance is greatly improved,
although the multibox is still slower. Both boxes are running Gentoo Linux
with Mono 1.1.12. The performance differences between the boxes also has me
worried with the effects that its also likely having on mod_mono/XSP.

As this is a work project I'm very eager to solve these issues. So if
there's anything I can do or provide to assist in solving these issues
please let me know.

Mike Glenn
Senior Web Developer
The Armstrong Group of Companies



-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: PerfTest.cs
Url: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20060115/4282c083/attachment.pl 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: singleproc.txt
Url: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20060115/4282c083/attachment.txt 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: mutilproc.txt
Url: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20060115/4282c083/attachment-0001.txt 


More information about the Mono-devel-list mailing list