From d666050ef7ac53e13544e6a5b5bbc5df2303cbfa Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 5 Oct 2021 10:59:17 -0400 Subject: [PATCH] Consolidate neigh wait time in slp Rather than incurring it on each iteration (causing a scan to take 15 seconds in test), defer to handle them all later (reducing to 5 seconds to scan). --- .../confluent/discovery/protocols/slp.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/confluent_server/confluent/discovery/protocols/slp.py b/confluent_server/confluent/discovery/protocols/slp.py index aaa99f6b..b44c6c2d 100644 --- a/confluent_server/confluent/discovery/protocols/slp.py +++ b/confluent_server/confluent/discovery/protocols/slp.py @@ -246,12 +246,11 @@ def _find_srvtype(net, net4, srvtype, addresses, xid): net4.sendto(data, (bcast, 427)) -def _grab_rsps(socks, rsps, interval, xidmap): +def _grab_rsps(socks, rsps, interval, xidmap, deferrals): r = None res = select.select(socks, (), (), interval) if res: r = res[0] - deferrals = [] while r: for s in r: (rsp, peer) = s.recvfrom(9000) @@ -261,11 +260,6 @@ def _grab_rsps(socks, rsps, interval, xidmap): r = None else: r = res[0] - if deferrals: - eventlet.sleep(2.2) - for defer in deferrals: - rsp, peer = defer - _parse_slp_packet(rsp, peer, rsps, xidmap) @@ -604,15 +598,21 @@ def scan(srvtypes=_slp_services, addresses=None, localonly=False): # First we give fast repsonders of each srvtype individual chances to be # processed, mitigating volume of response traffic rsps = {} + deferrals = [] for srvtype in srvtypes: xididx += 1 _find_srvtype(net, net4, srvtype, addresses, initxid + xididx) xidmap[initxid + xididx] = srvtype - _grab_rsps((net, net4), rsps, 0.1, xidmap) - # now do a more slow check to work to get stragglers, - # but fortunately the above should have taken the brunt of volume, so - # reduced chance of many responses overwhelming receive buffer. - _grab_rsps((net, net4), rsps, 1, xidmap) + _grab_rsps((net, net4), rsps, 0.1, xidmap, deferrals) + # now do a more slow check to work to get stragglers, + # but fortunately the above should have taken the brunt of volume, so + # reduced chance of many responses overwhelming receive buffer. + _grab_rsps((net, net4), rsps, 1, xidmap, deferrals) + if deferrals: + eventlet.sleep(1.2) # already have a one second pause from select above + for defer in deferrals: + rsp, peer = defer + _parse_slp_packet(rsp, peer, rsps, xidmap) # now to analyze and flesh out the responses handleids = set([]) gp = eventlet.greenpool.GreenPool(128)