3

Recently I have noticed my Django project starts up much slower comparing to a month ago, typically 5~6 seconds slower, I don't remember updating any packages and also validated on Ubuntu server that it doesn't suffer the same problem, so my only guess is that due to my MacOS upgrade.

So I ran python profiler:

python -m cProfile -o /tmp/result manage.py

Then inspected the result using snakeviz:

snakeviz /tmp/result

This indicated the slowness is in the ldap package by hovering __init__.py:5:

enter image description here

Then I went into the __init__.py and discovered that the following line took the most of the time:

LIBLDAP_API_INFO = _ldap.get_option(_ldap.OPT_API_INFO)

Further digging into get_option it goes into source code of _ldap.cpython-36m-darwin.so

def get_option(*args, **kwargs): # real signature unknown
    pass

Just wondering if anyone is having similar issues and how to fix it?

James Lin
  • 25,028
  • 36
  • 133
  • 233
  • 1
    Running into the same issue with a dummy `slapd` instance (v2.4.45) used for running tests on my Gentoo box. Recompiling `openldap` and reinstalling `python-ldap` via `pip install python-ldap --force-reinstall --no-cache-dir` helps, but not for too long. Will open a bounty on this question if won't find the solution within a day. – hoefling Mar 25 '19 at 20:00
  • I still haven't got to solve the problem yet, would be great to hear an update from you @hoefling – James Lin Mar 25 '19 at 20:47
  • In my case, it was an extremely slow DNS server used by my company's VPN connection (5 seconds delay on each DNS lookup query). Spinning up a local `dnsmasq` instance with restricting usage of the slow DNS server to a restricted list of domains solved the issue for me. – hoefling Mar 29 '19 at 15:53
  • Thanks for this interesting dive into the profiler. I think the solution is presented here: https://stackoverflow.com/questions/43328378/python-ldap-macos-valueerror-option-error – mvreijn Oct 31 '21 at 20:49
  • @mvreijn it's a bit different, mine works fine, just slow, no errors. – James Lin Aug 23 '22 at 03:35

0 Answers0