From 8c21c594598928b04ab5273c13d6b9f119b621f5 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 27 Oct 2017 16:50:39 -0400 Subject: [PATCH] Dynamic backoff for switch scan Have switch scan back off propritonate to time it takes to walk the switches. Avoid being back to back on switch scans. --- confluent_server/confluent/networking/macmap.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/confluent_server/confluent/networking/macmap.py b/confluent_server/confluent/networking/macmap.py index 58036d58..7bf4caa8 100644 --- a/confluent_server/confluent/networking/macmap.py +++ b/confluent_server/confluent/networking/macmap.py @@ -241,13 +241,17 @@ def _map_switch_backend(args): _nodesbymac[mac] = nodename +switchbackoff = 30 + + def find_node_by_mac(mac, configmanager): now = util.monotonic_time() if vintage and (now - vintage) < 90 and mac in _nodesbymac: return _nodesbymac[mac] # do not actually sweep switches more than once every 30 seconds # however, if there is an update in progress, wait on it - for _ in update_macmap(configmanager, vintage and (now - vintage) < 30): + for _ in update_macmap(configmanager, + vintage and (now - vintage) < switchbackoff): if mac in _nodesbymac: return _nodesbymac[mac] # If update_mac bailed out, still check one last time @@ -294,6 +298,8 @@ def _full_updatemacmap(configmanager): global _nodesbymac global _switchportmap global _macsbyswitch + global switchbackoff + start = util.monotonic_time() with mapupdating: vintage = util.monotonic_time() # Clear all existing entries @@ -338,6 +344,13 @@ def _full_updatemacmap(configmanager): for ans in pool.imap(_map_switch, switchauth): vintage = util.monotonic_time() yield ans + endtime = util.monotonic_time() + duration = endtime - start + duration = duration * 15 # wait 15 times as long as it takes to walk + # avoid spending a large portion of the time hitting switches with snmp + # requests + if duration > switchbackoff: + switchbackoff = duration def _dump_locations(info, macaddr, nodename=None):