mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-12-26 01:39:23 -05:00
Manually run GC on reactor tick.
This also adds a metric for amount of time spent in GC.
This commit is contained in:
parent
96d9d5d388
commit
1f1dee94f6
@ -22,6 +22,7 @@ import functools
|
||||
import os
|
||||
import stat
|
||||
import time
|
||||
import gc
|
||||
|
||||
from twisted.internet import reactor
|
||||
|
||||
@ -155,6 +156,7 @@ get_metrics_for("process").register_callback("fds", _process_fds, labels=["type"
|
||||
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):
|
||||
@ -182,6 +184,18 @@ def runUntilCurrentTimer(func):
|
||||
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)
|
||||
|
||||
return ret
|
||||
|
||||
return f
|
||||
@ -196,5 +210,6 @@ try:
|
||||
# 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
|
||||
|
Loading…
Reference in New Issue
Block a user