From fb4b34d0ee65335a2f954c817ee0d35ce1dbf810 Mon Sep 17 00:00:00 2001 From: kgriffs Date: Fri, 20 Sep 2013 10:16:41 -0500 Subject: [PATCH] fix(mongodb): Remove $or clause used to claim messages The $or clause was removed from one of the queries in ClaimController.create() because it is no longer necessary, and makes the query slower than it would otherwise be. Mongo will just use the _id_ index now, which should be fine since scanning a small set of messages by c.e is fast. Change-Id: Ifcb918ef66d072a10690ad49406f4a787e84becd Implements: blueprint bp/api-perf-tuning --- marconi/queues/storage/mongodb/claims.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/marconi/queues/storage/mongodb/claims.py b/marconi/queues/storage/mongodb/claims.py index 073ebf29c..5c4a1f433 100644 --- a/marconi/queues/storage/mongodb/claims.py +++ b/marconi/queues/storage/mongodb/claims.py @@ -151,15 +151,19 @@ class ClaimController(storage.ClaimBase): now = timeutils.utcnow_ts() - # Set claim field for messages in ids + # NOTE(kgriffs): Set the claim field for + # the active message batch, while also + # filtering out any messages that happened + # to get claimed just now by one or more + # parallel requests. + # + # Filtering by just 'c.e' works because + # new messages have that field initialized + # to the current time when the message is + # posted. There is no need to check whether + # 'c' exists or 'c.id' is None. updated = msg_ctrl._col.update({'_id': {'$in': ids}, - '$or': [ - {'c.id': None}, - { - 'c.id': {'$ne': None}, - 'c.e': {'$lte': now} - } - ]}, + 'c.e': {'$lte': now}}, {'$set': {'c': meta}}, upsert=False, multi=True)['n']