Speed difference, which version to use?
Michael Ströder
michael at stroeder.com
Fri Jun 14 17:31:49 CEST 2002
Anders Karlsson wrote:
>
> Since it was built for Python 1.x I upgraded to Python-LDAP 2.0.0pre04
> which worked fine, but considerable slower that the old version. A python
> program that changed some posts in the LDAP database and did two searches
> took about five seconds with 2.0.0pre04, compared to less than a second
> with 1.10alpha3.
>
> Why is there such big speed difference?
Hmm, there might be different issues here:
1. I changed the implementation of the synchronous methods *_s()
to avoid getting blocked in OpenLDAP 2 _s() functions. Especially
there's a reimplementation of result() in
ldap.ldapobject.LDAPObject which does the timeout handling itself.
The main reason is that the OpenLDAP libs are not thread-safe and
therefore a module-wide lock is used to serialize all calls into
the OpenLDAP libs.
(If someone manages to use OpenLDAP 2.1's libldap_r instead of
libldap this might help to reduce some of the locking.)
2. You might also have upgraded the LDAP server to OpenLDAP 2
(which does stricter checking) or changed the indexing
configuration (which is a performance penalty when writing)?
3. The OpenLDAP 2.x libs are slower. (python-ldap 1.x was linked
against OpenLDAP 1.x libs.)
Now for 1. issue:
You could try a very simple result() implementation (tweak
Lib/ldap/ldapobject.py):
def result(self,msgid=_ldap.RES_ANY,all=1,timeout=-1):
return self._ldap_call(self._l.result,msgid,all,timeout)
I did some testing with this method implementation for measuring
the overhead of my non-blocking version. I read the RootDSE of
Netscape DS 4.16SP1 running on the same box. (Solely searching the
RootDSE is an appropriate method to eliminate the influence of
database backends and such.)
On average it seems to be approx. 65% faster to use this simple
method above. This is something to consider.
Hmm, but you are experiencing a performance difference which is
much higher (5 times slower as I understand your posting). I'd
really appreciate if you could send more information about your
environment and *all* the changes you did. Performance measurement
numbers done under really the same conditions are also appreciated
off course.
Ciao, Michael.
More information about the python-ldap
mailing list