From 2afb9da937d91057d5de88b005dc2fa9e3c1a366 Mon Sep 17 00:00:00 2001 From: Alejandro Cabrera Date: Mon, 2 Dec 2013 13:32:29 -0500 Subject: [PATCH] opt: add hints to make delete/claim checks faster Adding in a few hints so that the mongodb query optimizer can make faster decisions in certain message retrieval cases. Change-Id: Ia80024a9b35f9e2a9aecaedf7162076ba8667d12 --- marconi/queues/storage/mongodb/messages.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/marconi/queues/storage/mongodb/messages.py b/marconi/queues/storage/mongodb/messages.py index 5a30b4f50..f28169b08 100644 --- a/marconi/queues/storage/mongodb/messages.py +++ b/marconi/queues/storage/mongodb/messages.py @@ -316,7 +316,9 @@ class MessageController(storage.MessageBase): preference = pymongo.read_preferences.ReadPreference.PRIMARY collection = self._collection(queue_name, project) msgs = collection.find(query, sort=[('k', 1)], - read_preference=preference) + read_preference=preference).hint( + CLAIMED_INDEX_FIELDS + ) if limit is not None: msgs = msgs.limit(limit) @@ -632,9 +634,11 @@ class MessageController(storage.MessageBase): return now = timeutils.utcnow_ts() - message = collection.find_one(query) + cursor = collection.find(query).hint(ID_INDEX_FIELDS) - if message is None: + try: + message = next(cursor) + except StopIteration: return is_claimed = (message['c']['id'] is not None and