Skip to content

Commit

Permalink
Adding DNS cache after profiling identified it as slow (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
djw8605 authored Jan 31, 2024
1 parent 6de4cf6 commit b75bfac
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Collectors/DetailedCollector.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(self, *args, **kw):
self._servers = {}
self._users = {}
self._dictid_map = {}
self._dns_cache = ttldict.TTLOrderedDict(default_ttl=3600*24)

self._exchange = self.config.get('AMQP', 'exchange')
self._wlcg_exchange = self.config.get('AMQP', 'wlcg_exchange')
Expand Down Expand Up @@ -67,7 +68,13 @@ def _determineHostname(self, addr):
# >>> socket.gethostbyaddr("2607:f8b0:4009:81c::200e")
# ('ord38s33-in-x0e.1e100.net', ['e.0.0.2.0.0.0.0.0.0.0.0.0.0.0.0.c.1.8.0.9.0.0.4.0.b.8.f.7.0.6.2.ip6.arpa'], ['2607:f8b0:4009:81c::200e'])
# In this case, we use "ord38s33-in-x0e.1e100.net".
canonical_hostname, _, addrlist = socket.gethostbyaddr(addr)
canonical_hostname = ""
addrlist = []
if addr in self._dns_cache:
canonical_hostname, addrlist = self._dns_cache[addr]
else:
canonical_hostname, _, addrlist = socket.gethostbyaddr(addr)
self._dns_cache[addr] = [canonical_hostname, addrlist]

# addr appears to be an IP address; use the canonical hostname
if addr in addrlist:
Expand Down

0 comments on commit b75bfac

Please # to comment.