From aa032bf62c2e8234a0304b5231e14ed583dbe341 Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Thu, 23 Feb 2023 04:36:14 +0000 Subject: [PATCH] queue: Only set QOS on a newly-opened channel, once. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As written, the QOS parameters are (re)set every time ensure_queue is called, which is every time a message is enqueued. This is wasteful -- particularly QOS parameters only apply for consumers, and setting them takes a RTT to the server. Switch to only setting the QOS once, when a connection is (re)established. In profiling, this reduces the time to call `queue_json_publish("noop", {})` from 878µs to 150µs. --- zerver/lib/queue.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/zerver/lib/queue.py b/zerver/lib/queue.py index b7b469b4ff..8d2d691a7e 100644 --- a/zerver/lib/queue.py +++ b/zerver/lib/queue.py @@ -160,9 +160,10 @@ class SimpleQueueClient(QueueClient[BlockingChannel]): the callback with no arguments.""" if self.connection is None or not self.connection.is_open: self._connect() - - assert self.channel is not None - self.channel.basic_qos(prefetch_count=self.prefetch) + assert self.channel is not None + self.channel.basic_qos(prefetch_count=self.prefetch) + else: + assert self.channel is not None if queue_name not in self.queues: self.channel.queue_declare(queue=queue_name, durable=True)