8 Commits

Author SHA1 Message Date
Leo Vasanko
fdbf9b2610 Attempt to reduce leak of ffmpeg previews 2023-11-21 12:26:16 +00:00
Leo Vasanko
8437c1f60e Attempt to reduce leak of ffmpeg previews 2023-11-21 12:23:24 +00:00
Leo Vasanko
02c5e484b5 Attempt to reduce leak of ffmpeg previews 2023-11-21 12:22:03 +00:00
Leo Vasanko
71eb252b8d Restrict the number of workers. 2023-11-21 12:13:57 +00:00
Leo Vasanko
27422ae1e2 Attempt to reduce leak of ffmpeg previews 2023-11-21 04:01:51 -08:00
Leo Vasanko
c3d6aecffd Attempt to reduce leak of ffmpeg previews 2023-11-21 04:00:20 -08:00
Leo Vasanko
e2a9a6903c Memtrace 2023-11-21 03:46:06 -08:00
Leo Vasanko
58b9dd3dd4 Cleanup 2023-11-20 16:35:34 -08:00
3 changed files with 28 additions and 12 deletions

View File

@@ -2,6 +2,7 @@ import asyncio
import datetime
import mimetypes
import threading
import tracemalloc
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path, PurePath, PurePosixPath
from stat import S_IFDIR, S_IFREG
@@ -9,6 +10,7 @@ from urllib.parse import unquote
from wsgiref.handlers import format_date_time
import brotli
import objgraph
import sanic.helpers
from blake3 import blake3
from sanic import Blueprint, Sanic, empty, raw, redirect
@@ -32,13 +34,25 @@ app.exception(Exception)(handle_sanic_exception)
@app.before_server_start
async def main_start(app, loop):
tracemalloc.start()
config.load_config()
app.ctx.threadexec = ThreadPoolExecutor(
max_workers=8, thread_name_prefix="cista-ioworker"
max_workers=3, thread_name_prefix="cista-ioworker"
)
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
async def main_stop(app, loop):
quit.set()

View File

@@ -1,4 +1,5 @@
import asyncio
import gc
import io
import mimetypes
import urllib.parse
@@ -9,6 +10,7 @@ from wsgiref.handlers import format_date_time
import av
import av.datasets
import fitz # PyMuPDF
from av.streams import SideData
from PIL import Image
from sanic import Blueprint, empty, raw
from sanic.exceptions import NotFound
@@ -96,19 +98,20 @@ def process_pdf(path, *, maxsize, maxzoom, quality, page_number=0):
def process_video(path, *, maxsize, quality):
with av.open(str(path)) as container:
stream = container.streams.video[0]
rotation = (
stream.side_data
and stream.side_data.get(av.stream.SideData.DISPLAYMATRIX)
or 0
)
stream.codec_context.skip_frame = "NONKEY"
stream.codec_context.threads = 1
rot = stream.side_data and stream.side_data.get(SideData.DISPLAYMATRIX) or 0
container.seek(container.duration // 8)
frame = next(container.decode(stream))
img = frame.to_image()
img = next(container.decode(stream)).to_image()
del stream
img.thumbnail((maxsize, maxsize))
imgdata = io.BytesIO()
if rotation:
img = img.rotate(rotation, expand=True)
if rot:
img = img.rotate(rot, expand=True)
img.save(imgdata, format="webp", quality=quality, method=4)
return imgdata.getvalue()
del img
ret = imgdata.getvalue()
del imgdata
gc.collect()
return ret

View File

@@ -27,7 +27,6 @@ import Router from '@/router/index'
import { needleFormat, localeIncludes, collator } from '@/utils'
import { sorted } from '@/utils/docsort'
import FileExplorer from '@/components/FileExplorer.vue'
import cog from '@/assets/svg/cog.svg'
const store = useMainStore()
const fileExplorer = ref()