Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #225 from matrix-org/erikj/reactor_metrics
Browse files Browse the repository at this point in the history
Fix pending_calls metric to not lie
  • Loading branch information
erikjohnston committed Aug 18, 2015
2 parents 128ed32 + 6e7d36a commit a5cbd20
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions synapse/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,40 @@ def runUntilCurrentTimer(func):

@functools.wraps(func)
def f(*args, **kwargs):
pending_calls = len(reactor.getDelayedCalls())
now = reactor.seconds()
num_pending = 0

# _newTimedCalls is one long list of *all* pending calls. Below loop
# is based off of impl of reactor.runUntilCurrent
for delayed_call in reactor._newTimedCalls:
if delayed_call.time > now:
break

if delayed_call.delayed_time > 0:
continue

num_pending += 1

num_pending += len(reactor.threadCallQueue)

start = time.time() * 1000
ret = func(*args, **kwargs)
end = time.time() * 1000
tick_time.inc_by(end - start)
pending_calls_metric.inc_by(pending_calls)
pending_calls_metric.inc_by(num_pending)
return ret

return f


if hasattr(reactor, "runUntilCurrent"):
try:
# Ensure the reactor has all the attributes we expect
reactor.runUntilCurrent
reactor._newTimedCalls
reactor.threadCallQueue

# runUntilCurrent is called when we have pending calls. It is called once
# per iteratation after fd polling.
reactor.runUntilCurrent = runUntilCurrentTimer(reactor.runUntilCurrent)
except AttributeError:
pass

0 comments on commit a5cbd20

Please sign in to comment.