Merge pull request #2646 from matrix-org/rav/logging_for_limiter

Logging and logcontext fixes for Limiter
This commit is contained in:
Richard van der Hoff 2017-11-07 10:47:00 +00:00 committed by GitHub
commit ec12e7eada
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -278,8 +278,13 @@ class Limiter(object):
if entry[0] >= self.max_count: if entry[0] >= self.max_count:
new_defer = defer.Deferred() new_defer = defer.Deferred()
entry[1].append(new_defer) entry[1].append(new_defer)
logger.info("Waiting to acquire limiter lock for key %r", key)
with PreserveLoggingContext(): with PreserveLoggingContext():
yield new_defer yield new_defer
logger.info("Acquired limiter lock for key %r", key)
else:
logger.info("Acquired uncontended limiter lock for key %r", key)
entry[0] += 1 entry[0] += 1
@ -288,16 +293,21 @@ class Limiter(object):
try: try:
yield yield
finally: finally:
logger.info("Releasing limiter lock for key %r", key)
# We've finished executing so check if there are any things # We've finished executing so check if there are any things
# blocked waiting to execute and start one of them # blocked waiting to execute and start one of them
entry[0] -= 1 entry[0] -= 1
try:
entry[1].pop(0).callback(None) if entry[1]:
except IndexError: next_def = entry[1].pop(0)
# If nothing else is executing for this key then remove it
# from the map with PreserveLoggingContext():
if entry[0] == 0: next_def.callback(None)
self.key_to_defer.pop(key, None) elif entry[0] == 0:
# We were the last thing for this key: remove it from the
# map.
del self.key_to_defer[key]
defer.returnValue(_ctx_manager()) defer.returnValue(_ctx_manager())