This commit is contained in:
Leo Vasanko 2023-11-21 03:46:06 -08:00
parent 58b9dd3dd4
commit e2a9a6903c

View File

@ -2,6 +2,7 @@ import asyncio
import datetime import datetime
import mimetypes import mimetypes
import threading import threading
import tracemalloc
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from pathlib import Path, PurePath, PurePosixPath from pathlib import Path, PurePath, PurePosixPath
from stat import S_IFDIR, S_IFREG from stat import S_IFDIR, S_IFREG
@ -9,6 +10,7 @@ from urllib.parse import unquote
from wsgiref.handlers import format_date_time from wsgiref.handlers import format_date_time
import brotli import brotli
import objgraph
import sanic.helpers import sanic.helpers
from blake3 import blake3 from blake3 import blake3
from sanic import Blueprint, Sanic, empty, raw, redirect from sanic import Blueprint, Sanic, empty, raw, redirect
@ -32,6 +34,7 @@ app.exception(Exception)(handle_sanic_exception)
@app.before_server_start @app.before_server_start
async def main_start(app, loop): async def main_start(app, loop):
tracemalloc.start()
config.load_config() config.load_config()
app.ctx.threadexec = ThreadPoolExecutor( app.ctx.threadexec = ThreadPoolExecutor(
max_workers=8, thread_name_prefix="cista-ioworker" max_workers=8, thread_name_prefix="cista-ioworker"
@ -39,6 +42,17 @@ async def main_start(app, loop):
await watching.start(app, loop) await watching.start(app, loop)
@app.add_task
async def mem_task():
while True:
await asyncio.sleep(10)
snapshot = tracemalloc.take_snapshot()
top_stats = snapshot.statistics("lineno")
for stat in top_stats[:10]:
print(stat)
objgraph.show_growth(limit=10)
@app.after_server_stop @app.after_server_stop
async def main_stop(app, loop): async def main_stop(app, loop):
quit.set() quit.set()