mirror of
https://github.com/dgtlmoon/changedetection.io.git
synced 2026-09-21 12:56:16 +00:00
Memory - GC freeze after startup to save CPU cycles and improve memory management (#4351)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import flask_login
|
||||
import gc
|
||||
import hashlib
|
||||
import locale
|
||||
import os
|
||||
@@ -1095,6 +1096,15 @@ def changedetection_app(config=None, datastore_o=None):
|
||||
"snapshot reads are NOT confined to the watch data directory. "
|
||||
"This disables protection against path traversal via restored backups (GHSA-8757-69j2-hx56).")
|
||||
|
||||
# Memory/CPU management -
|
||||
# Freeze the startup object graph into the "permanent generation" so that the cyclic
|
||||
# garbage collector never traverses it again, this allows more of the app to swap into 'cold' RAM
|
||||
if 'pytest' not in sys.modules and 'PYTEST_CURRENT_TEST' not in os.environ \
|
||||
and not strtobool(os.getenv('DISABLE_GC_FREEZE', 'no')):
|
||||
gc.collect()
|
||||
gc.freeze()
|
||||
logger.debug(f"GC: froze {gc.get_freeze_count()} startup objects into the permanent generation")
|
||||
|
||||
# Start the async workers during app initialization
|
||||
# Can be overridden by ENV or use the default settings
|
||||
n_workers = int(os.getenv("FETCH_WORKERS", datastore.data['settings']['requests']['workers']))
|
||||
|
||||
Reference in New Issue
Block a user