mirror of
https://github.com/element-hq/synapse.git
synced 2026-05-18 01:05:34 +00:00
Decrease GC tick frequency; only create instance IDs if we'll use them
Both _maybe_gc and random_string_insecure_fast feature in CPU profiles.
This commit is contained in:
@@ -693,7 +693,11 @@ class PreserveLoggingContext:
|
||||
self, new_context: LoggingContextOrSentinel = SENTINEL_CONTEXT
|
||||
) -> None:
|
||||
self._new_context = new_context
|
||||
self._instance_id = random_string_insecure_fast(5)
|
||||
self._instance_id = (
|
||||
random_string_insecure_fast(5)
|
||||
if logcontext_debug_logger.isEnabledFor(logging.DEBUG)
|
||||
else ""
|
||||
)
|
||||
|
||||
def __enter__(self) -> None:
|
||||
logcontext_debug_logger.debug(
|
||||
@@ -889,7 +893,11 @@ def run_in_background(
|
||||
Note that the returned Deferred does not follow the synapse logcontext
|
||||
rules.
|
||||
"""
|
||||
instance_id = random_string_insecure_fast(5)
|
||||
instance_id = (
|
||||
random_string_insecure_fast(5)
|
||||
if logcontext_debug_logger.isEnabledFor(logging.DEBUG)
|
||||
else ""
|
||||
)
|
||||
calling_context = current_context()
|
||||
logcontext_debug_logger.debug(
|
||||
"run_in_background(%s): called with logcontext=%s", instance_id, calling_context
|
||||
@@ -1052,7 +1060,11 @@ def make_deferred_yieldable(deferred: "defer.Deferred[T]") -> "defer.Deferred[T]
|
||||
restores the old context once the awaitable completes (execution passes from the
|
||||
reactor back to the code).
|
||||
"""
|
||||
instance_id = random_string_insecure_fast(5)
|
||||
instance_id = (
|
||||
random_string_insecure_fast(5)
|
||||
if logcontext_debug_logger.isEnabledFor(logging.DEBUG)
|
||||
else ""
|
||||
)
|
||||
logcontext_debug_logger.debug(
|
||||
"make_deferred_yieldable(%s): called with logcontext=%s",
|
||||
instance_id,
|
||||
|
||||
@@ -141,7 +141,8 @@ def install_gc_manager() -> None:
|
||||
# We can ignore the lint here since this looping call does not hold a `HomeServer`
|
||||
# reference so can be cleaned up by other means on shutdown.
|
||||
gc_task = task.LoopingCall(_maybe_gc) # type: ignore[prefer-synapse-clock-looping-call]
|
||||
gc_task.start(0.1)
|
||||
# tick every second. Previously this was every 100ms. Increased to reduce CPU time spent inside _maybe_gc.
|
||||
gc_task.start(1.0)
|
||||
|
||||
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user