Skip to content

Instantly share code, notes, and snippets.

@tiran
Created January 4, 2021 15:24
Show Gist options
  • Save tiran/4b56faf5a8b14b9828ef8ba2ad9292ba to your computer and use it in GitHub Desktop.
Save tiran/4b56faf5a8b14b9828ef8ba2ad9292ba to your computer and use it in GitHub Desktop.
Profile LDAP SASL bind performance
#!/usr/bin/python3
import collections
import configparser
import time
import socket
import ldap
import ldap.sasl
SASL_GSSAPI = ldap.sasl.sasl({}, 'GSSAPI')
SASL_GSS_SPNEGO = ldap.sasl.sasl({}, 'GSS-SPNEGO')
METH = SASL_GSSAPI
with open("/etc/ipa/default.conf") as f:
cfg = configparser.RawConfigParser()
cfg.read_file(f)
URI = cfg.get("global", "ldap_uri")
assert URI.startswith("ldapi://")
def profile(uri, meth):
conn = ldap.initialize(uri)
conn.whoami_s() # start connection
start = time.perf_counter()
try:
conn.sasl_interactive_bind_s('', meth)
return time.perf_counter() - start
finally:
conn.unbind()
# acquire service ticket
profile(URI, METH)
ctr = collections.Counter()
for i in range(2000):
dur = profile(URI, METH)
dur = round(dur * 1000)
ctr.update({dur: 1})
# print(f"{dur}ms")
if dur > 500:
c = "O"
elif dur > 20:
c = "x"
else:
c = "."
print(c, end="", flush=True)
print()
for dur, count in sorted(ctr.items()):
print(f"{dur}ms\t{count}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment