From: jacob m. <mar...@gm...> - 2005-07-27 22:12:21
|
I have a small script using python-ldap in python-2.3 and it takes about 3.5 seconds to perform a simple bind to our server. I can perform a complete search from the command line with ldapsearch in about 0.02 sec. I've appended the code & timing output. Am I missing something here? Thanks! -Jacob $ time ldapsearch -x -h host -D "cn=3DJones\, Bob,cn=3DUsers,dc=3Ddom,dc=3D= com" \ > -w pass -b "cn=3Dusers,dc=3Ddom,dc=3Dcom" "sAMAccountName=3Dacct" mail # extended LDIF # # LDAPv3 <snip> # search result search: 2 result: 0 Success # numResponses: 2 # numEntries: 1 real 0m0.024s user 0m0.003s sys 0m0.006s $ cat ldaptest.py #!/usr/bin/python import ldap import profile import time from pprint import pprint def ldapsearch(): passwd=3D'adsf' t0 =3D time.time() l =3D ldap.initialize("ldap://server:389") t1 =3D time.time() print 'ldap.initialize() ' + str(t1 - t0) t0 =3D time.time() l.bind(who=3D"cn=3DJones\, Bob,cn=3DUsers,dc=3Ddom,dc=3Dcom",cred=3Dpasswd,method=3Dldap.AUTH_SIMPLE) t1 =3D time.time() print 'l.bind() ' + str(t1 - t0) t0 =3D time.time() msgid =3D l.search(base=3D"cn=3Dusers,dc=3Ddom,dc=3Dcom",scope=3Dldap.SCOPE_SUBTREE,f= ilterstr=3D"sAMAccountName=3Dacct",attrlist=3D['mail']) t1 =3D time.time() print 'l.search() ' + str(t1 - t0) t0 =3D time.time() res =3D l.result(msgid) t1 =3D time.time() print 'l.result() ' + str(t1 - t0) if __name__ =3D=3D '__main__': ldapsearch() which produces: $ time ./ldaptest.py ldap.initialize() 0.00811719894409 l.bind() 3.45404982567 l.search() 0.00253987312317 l.result() 0.00940012931824 real 0m3.557s user 0m0.030s sys 0m0.070s |
From: Wido D. <wid...@gm...> - 2005-08-01 13:40:18
|
On 7/28/05, jacob martinson <mar...@gm...> wrote: > I have a small script using python-ldap in python-2.3 and it takes > about 3.5 seconds to perform a simple bind to our server. I can > perform a complete search from the command line with ldapsearch in > about 0.02 sec. >=20 > I've appended the code & timing output. Am I missing something here? Your code seems to be okay, although I'm using simple_bind() instead of bind(). On a local server Luma needs about 0,006 sec for an authenticated bind and about 0,1s for a complete search, which includes creating a thread, updating the gui and packing the ldap results in a special object. For me the only difference are the functions used for the bind operation. I didn't have a look at the sourcecode, but maybe the others have an idea what's going wrong. mfg. Wido --=20 Wido Depping ICQ: 51303067 AIM: wido3379 Jabber: wi...@ja... |
From: Sean O'C. <oco...@so...> - 2005-08-01 16:04:53
|
Jacob Here is a little code snippet from a search in AD. I am using ldaps to talk to our AD DCs, hence the TLS options. #-----------------------------------------------------------------------------# # Make LDAP connection to AD # Tip from python-ldap list ldap.set_option(ldap.OPT_REFERRALS,0) # Another tip from python-ldap list ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT,ldap.OPT_X_TLS_NEVER) # Open the LDAPS connection to AD try: l = ldap.initialize(myAdLdapUri) except ldap.LDAPError,e: print e sys.exit(1) # Set protocol version to LDAPv3 l.protocol_version = ldap.VERSION3 # Bind to AD try: l.simple_bind(myAdBindDn,myAdPasswd) except ldap.LDAPError, e: print e sys.exit(1) On Wed, 2005-07-27 at 17:12 -0500, jacob martinson wrote: > I have a small script using python-ldap in python-2.3 and it takes > about 3.5 seconds to perform a simple bind to our server. I can > perform a complete search from the command line with ldapsearch in > about 0.02 sec. > > I've appended the code & timing output. Am I missing something here? > > Thanks! > > -Jacob > > > $ time ldapsearch -x -h host -D "cn=Jones\, Bob,cn=Users,dc=dom,dc=com" \ > > -w pass -b "cn=users,dc=dom,dc=com" "sAMAccountName=acct" mail > # extended LDIF > # > # LDAPv3 > <snip> > # search result > search: 2 > result: 0 Success > # numResponses: 2 > # numEntries: 1 > > real 0m0.024s > user 0m0.003s > sys 0m0.006s > > $ cat ldaptest.py > #!/usr/bin/python > > import ldap > import profile > import time > > from pprint import pprint > > def ldapsearch(): > passwd='adsf' > > t0 = time.time() > l = ldap.initialize("ldap://server:389") > t1 = time.time() > print 'ldap.initialize() ' + str(t1 - t0) > > t0 = time.time() > l.bind(who="cn=Jones\, > Bob,cn=Users,dc=dom,dc=com",cred=passwd,method=ldap.AUTH_SIMPLE) > t1 = time.time() > print 'l.bind() ' + str(t1 - t0) > > t0 = time.time() > msgid = > l.search(base="cn=users,dc=dom,dc=com",scope=ldap.SCOPE_SUBTREE,filterstr="sAMAccountName=acct",attrlist=['mail']) > t1 = time.time() > print 'l.search() ' + str(t1 - t0) > > t0 = time.time() > res = l.result(msgid) > t1 = time.time() > print 'l.result() ' + str(t1 - t0) > > > if __name__ == '__main__': > ldapsearch() > > which produces: > > $ time ./ldaptest.py > ldap.initialize() 0.00811719894409 > l.bind() 3.45404982567 > l.search() 0.00253987312317 > l.result() 0.00940012931824 > > real 0m3.557s > user 0m0.030s > sys 0m0.070s -- Sean |