]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MEDIUM: resolvers: replace bogus resolv_hostname_cmp() with memcmp()
authorWilly Tarreau <w@1wt.eu>
Fri, 15 Oct 2021 06:53:44 +0000 (08:53 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 18 Oct 2021 08:47:36 +0000 (10:47 +0200)
commit75cc65356f95e6868c9457fcf3fc470edf88ca69
tree178b383545d66583d32fd6c1abfabd13133702dd
parent814889c28a3ce1bf0bfe2669d43489feba5b4e91
MEDIUM: resolvers: replace bogus resolv_hostname_cmp() with memcmp()

resolv_hostname_cmp() is bogus, it is applied on labels and not plain
names, but doesn't make any distinction between length prefixes and
characters, so it compares the labels lengths via tolower() as well.
The only reason for which it doesn't break is because labels cannot
be larger than 63 bytes, and that none of the common encoding systems
have upper case letters in the lower 63 bytes, that could be turned
into a different value via tolower().

Now that all labels are stored in lower case, we don't need to burn
CPU cycles in tolower() at run time and can use memcmp() instead of
resolv_hostname_cmp(). This results in a ~22% lower CPU usage on large
farms using SRV records:

before:
  18.33%  haproxy                   [.] resolv_validate_dns_response
  10.58%  haproxy                   [.] process_resolvers
  10.28%  haproxy                   [.] resolv_hostname_cmp
   7.50%  libc-2.30.so              [.] tolower
  46.69%  total

after:
  24.73%  haproxy                     [.] resolv_validate_dns_response
   7.78%  libc-2.30.so                [.] __memcmp_avx2_movbe
   3.65%  haproxy                     [.] process_resolvers
  36.16%  total
src/resolvers.c