[Date Prev][Date Next] [Chronological] [Thread] [Top]

Slowdowns 1.2.11 -> 2.0.7

I have determined the cause of the significant slowdown I'm seeing in
2.0.7 that wasn't present in 1.2.11.

The problem is that in 1.2.11, OpenLDAP (specifically,
libldap/os-ip.c:ldap_connect_to_host()) used gethostbyname() to do the
hostname lookup.  This elicits a very fast response from my DNS server.

In 2.0.7, the code was switched to use getaddrinfo() (on those hosts
which support it), with an ai_family of PF_UNSPEC (actually the code
says AF_UNSPEC, but according to all the docs I've that's not correct,
although it probably works most places as these constants typically have
the same value).

This invocation of getaddrinfo() is single-handedly causing the slowdown
I'm seeing: I wrote simple test programs using getaddrinfo() and
gethostbyname() that do nothing but look up addresses, and the latter
completes in about 0.01 seconds while the former takes 3.5 to 4 seconds
or more.

If I change the getaddrinfo() call to request only IPv4 addresses (e.g.,
use PF_INET instead of PF_UNSPEC) then I get the same performance as
with the old code.

Note that I have tested and verified this behavior on Linux (Debian
GNU/Linux), FreeBSD 4.0-RELEASE, and Solaris 7, so I can't see how it
could be a bug in the OS implementation of getaddrinfo().  All flavors
were, however, using the same DNS server; maybe it's an issue with my
DNS server.

At any rate, it also turns out that using --disable-ipv6 won't fix the
problem; I enclose a patch below which will allow you to use
--disable-ipv6 to request that only IPv4 lookups should be done.

Actually, I'm not sure this is right: when I run with --disable-ipv6,
the LDAP_PF_INET6 flag is still being set.  It looks to me like it's set
if you can legally link with IPv6 stuff, regardless of what the user
requested on the configure line.  This is the only config constant
dealing with IPv6 that I can find.  Either you need another one
(ENABLE_IPV6 or something), or the configure script has to be enhanced
to not set LDAP_PF_INET6 if the user said --disable-ipv6, regardless of
whether the system supports it or not.

I suspect this post belongs on -devel, but I don't have post permissions
for that list.

Hope this helps someone.

--- os-ip.c-dist	Mon Oct 30 12:36:25 2000
+++ os-ip.c	Mon Mar 26 17:09:56 2001
@@ -303,7 +303,11 @@
 		struct addrinfo hints, *res, *sai;
 		memset( &hints, '\0', sizeof(hints) );
-		hints.ai_family = AF_UNSPEC;
+#ifdef LDAP_PF_INET6
+		hints.ai_family = PF_UNSPEC;
+		hints.ai_family = PF_INET;
 		hints.ai_socktype = SOCK_STREAM;
 		snprintf(serv, sizeof serv, "%d", ntohs(port));

 Paul D. Smith <psmith@baynetworks.com>    HASMAT--HA Software Methods & Tools
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
   These are my opinions---Nortel Networks takes no responsibility for them.