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

Manually run GC on reactor tick. #771

Merged
merged 3 commits into from
Jun 7, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions synapse/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import os
import stat
import time
import gc

from twisted.internet import reactor

Expand Down Expand Up @@ -155,6 +156,7 @@ def _process_fds():
reactor_metrics = get_metrics_for("reactor")
tick_time = reactor_metrics.register_distribution("tick_time")
pending_calls_metric = reactor_metrics.register_distribution("pending_calls")
gc_time = reactor_metrics.register_distribution("gc_time")


def runUntilCurrentTimer(func):
Expand Down Expand Up @@ -182,6 +184,18 @@ def f(*args, **kwargs):
end = time.time() * 1000
tick_time.inc_by(end - start)
pending_calls_metric.inc_by(num_pending)

threshold = gc.get_threshold()
counts = gc.get_count()

start = time.time() * 1000
for i in [2, 1, 0]:
if threshold[i] < counts[i]:
logger.info("Collecting gc %d", i)
gc.collect(i)
end = time.time() * 1000
gc_time.inc_by(end - start)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be interesting to collect stats about the different levels of collection going on.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooh, yes, good point.


return ret

return f
Expand All @@ -196,5 +210,6 @@ def f(*args, **kwargs):
# runUntilCurrent is called when we have pending calls. It is called once
# per iteratation after fd polling.
reactor.runUntilCurrent = runUntilCurrentTimer(reactor.runUntilCurrent)
gc.disable()
except AttributeError:
pass