From d5e03ac9307c9cc6f79fc22f15e177d3662dc936 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Wed, 17 Dec 2014 08:52:06 -0800 Subject: [PATCH] Only wake relevant connections As a performance improvement, on job submission, only wake connections that handle that job. Also, when a connection sends SLEEP, if there is a pending job it can handle, only wake that connection. Change-Id: Iff7cd28a7534f24ad4ea96c8f3ad55324e0237e2 --- gear/__init__.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/gear/__init__.py b/gear/__init__.py index 1a182de..eb7cb9e 100644 --- a/gear/__init__.py +++ b/gear/__init__.py @@ -2859,12 +2859,19 @@ class Server(BaseClientServer): .encode('utf8')) request.connection.sendRaw(b'.\n') - def wakeConnections(self): + def wakeConnection(self, connection): + p = Packet(constants.RES, constants.NOOP, b'') + if connection.state == 'SLEEP': + connection.changeState("AWAKE") + connection.sendPacket(p) + + def wakeConnections(self, job=None): p = Packet(constants.RES, constants.NOOP, b'') for connection in self.active_connections: if connection.state == 'SLEEP': - connection.changeState("AWAKE") - connection.sendPacket(p) + if job and job.name in connection.functions: + connection.changeState("AWAKE") + connection.sendPacket(p) def reportTimingStats(self, ptype, duration): """Report processing times by packet type @@ -2949,7 +2956,7 @@ class Server(BaseClientServer): elif precedence == PRECEDENCE_LOW: self.low_queue.append(job) self._updateStats() - self.wakeConnections() + self.wakeConnections(job) def handleSubmitJob(self, packet): return self._handleSubmitJob(packet, PRECEDENCE_NORMAL) @@ -2995,7 +3002,7 @@ class Server(BaseClientServer): def handlePreSleep(self, packet): packet.connection.changeState("SLEEP") if self.getJobForConnection(packet.connection, peek=True): - self.wakeConnections() + self.wakeConnection(packet.connection) def handleWorkComplete(self, packet): self.handlePassthrough(packet, True)