Don't update node request in assign handlers loop
Most of the evaluations that happen in the assignHandlers method are safe to operate on slightly out-of date node requests. They mostly consist of comparing what the request is asking for to what the provider has available. The loop iterates over a set of cached node requests which can be slightly out of date (but not too much) because they are updated out-of-band by a cache listener. It's safe for us to make these comparisons on request data that generally doesn't change over time any way. We can greatly speed up the loop by avoiding the explicit refresh of every request. If we're a little wrong and we defer request handling, we'll get it on the next time through the loop. Later in the loop, we lock the request, and at that point, the lock routine automatically refreshes the request object in place, so we know we have current data. There are a few things we check that can change: the request status, and the declined worker list(though it's very unlikely to be out of sync in such a way that it's missing our own name). We can check those again after the lock to be sure. Change-Id: Ib9e16f9e16d05537171b1acb37aa110477495a6e
This commit is contained in:
parent
3209226fc1
commit
fada5d9edf
|
@ -156,10 +156,6 @@ class PoolWorker(threading.Thread, stats.StatsReporter):
|
|||
req_count + 1, len(requests), elapsed)
|
||||
return False
|
||||
|
||||
req = self.zk.getNodeRequest(req.id)
|
||||
if not req:
|
||||
continue
|
||||
|
||||
# Only interested in unhandled requests
|
||||
if req.state != zk.REQUESTED:
|
||||
continue
|
||||
|
@ -263,6 +259,11 @@ class PoolWorker(threading.Thread, stats.StatsReporter):
|
|||
log.debug("Request is in state %s", req.state)
|
||||
continue
|
||||
|
||||
# Skip it if we've already declined
|
||||
if self.launcher_id in req.declined_by:
|
||||
log.debug("Request is already declined")
|
||||
continue
|
||||
|
||||
if not reasons_to_decline:
|
||||
# Got a lock, so assign it
|
||||
log.info("Assigning node request %s" % req)
|
||||
|
|
Loading…
Reference in New Issue