parallele Suchanfragen auf LDAP-Server

Sockets, TCP/IP, (XML-)RPC und ähnliche Themen gehören in dieses Forum
Antworten
Gast

Hallo,

ich möchte mir ein kleines Tool programmieren, mit dem ich Aussagen über die Performance eines OpenLDAP-Servers machen kann. Das Tool soll ein bestimmte Anzahl Clients (>1) simulieren, die parallel eine große Anzahl Suchanfragen losschicken.

bisheriger Quellcode:

Code: Alles auswählen

import ldap
import random
import time

try:
	#number of clients which are connected to the server
	number_of_clients = 2
	# Pass in a valid username and password to get
	# privileged directory access.
	# If you leave them as empty strings or pass an invalid value
	username = "cn=admin,o=vodafone"
	password = "DaVD_2AT"
	l= []
	for i in range(number_of_clients):
		l.append(ldap.open("10.1.56.200"))
	for item in l:
		# you should  set this to ldap.VERSION2 if you're using a v2 directory
		item.protocol_version = ldap.VERSION2
		# you will still bind to the server but with limited privileges.
		item.simple_bind_s(username, password)

	# Any errors will throw an ldap.LDAPError exception
	# or related exception so you can ignore the result

except ldap.LDAPError, e:
	print e
	# handle error however you like

	## The next lines will also need to be changed to support your search requirements and directory
try:
	for item in l:
		#number of parallel searches
		number_of_searches = 3
		average = 0
		result_list = []
		for counter in range(number_of_searches):
			# search for randomly chosen subscribers
			vfsid_list = ["vfsid=491731000001", "vfsid=491731000002", "vfsid=491731000003", "vfsid=491731000005", "vfsid=491731000009"]
			x = random.choice(vfsid_list)
			result_list.append(item.search("o=vodafone", ldap.SCOPE_SUBTREE, x, None))
		for y in result_list:
			startzeit = time.time()
			result_set = []
			while 1:
				result_type, result_data = item.result(y, 0)
				if (result_data == []):
					break
				else:
					## here you don't have to append to a list
					## you could do whatever you want with the individual entry
					## The appending to list is just for illustration.
					if result_type == ldap.RES_SEARCH_ENTRY:
						result_set.append(result_data)
			print result_set

			if result_list.index(y) == 0:
				endzeit = time.time() - startzeit - 1
			else:
				endzeit = time.time() - startzeit

			print "\tLaufzeit =", endzeit, "\n"
			average = endzeit + average

except ldap.LDAPError, e:
	print e

try:
	for item in l:
		item.unbind_s()

	sum = average / (number_of_clients*number_of_searches)
	print "\n\nAverage = ", sum

except ldap.LDAPError, e:
	print e
Was muss ich machen, damit die Suchanfragen parallel gestartet werden?

Edit (Leonidas): Code in Python-Tags gesetzt.
Benutzeravatar
jens
Python-Forum Veteran
Beiträge: 8502
Registriert: Dienstag 10. August 2004, 09:40
Wohnort: duisburg
Kontaktdaten:

Es gibt diesen "multithreaded portscanner": http://aspn.activestate.com/ASPN/Cookbo ... ipe/286240

Der im Prinzip eine ähnliche "Aufgabe" erfüllt...

(Du solltest den Code in [python]...[/python] Tags einfügen!!!)

GitHub | Open HUB | Xing | Linked in
Bitcoins to: 1JEgSQepxGjdprNedC9tXQWLpS424AL8cd
Gast

Danke für den Link. Werde ich mir gleich mal anschauen.

Leider hatte ich mich vergessen einzuloggen und konnte im Nachhinein den Eintrag nicht mehr editieren.
Aber das mit den [.python]...[./python] Tags ist gemerkt

Gruß
Toni
Antworten