fix: Implement garbage collection in run_conversion_job to prevent memory accumulation and add resource limits in docker-compose for better performance

This commit is contained in:
JB
2025-11-30 05:37:40 -08:00
parent 540b191d5b
commit 040bce1bc1
2 changed files with 15 additions and 0 deletions
+12
View File
@@ -8,6 +8,7 @@ import subprocess
import sys import sys
import tempfile import tempfile
import traceback import traceback
import gc
from datetime import datetime from datetime import datetime
from collections import defaultdict from collections import defaultdict
from contextlib import ExitStack from contextlib import ExitStack
@@ -1949,6 +1950,17 @@ def run_conversion_job(job: Job) -> None:
if subtitle_writer: if subtitle_writer:
subtitle_writer.close() subtitle_writer.close()
# Explicitly release the pipeline and force garbage collection to prevent
# memory accumulation in the worker process, which can lead to host lockups.
pipeline = None
gc.collect()
try:
import torch
if torch.cuda.is_available():
torch.cuda.empty_cache()
except ImportError:
pass
if ( if (
audio_output_path audio_output_path
and job.output_format.lower() == "m4b" and job.output_format.lower() == "m4b"
+3
View File
@@ -33,6 +33,9 @@ services:
# below if you are deploying to a CPU-only host. # below if you are deploying to a CPU-only host.
deploy: deploy:
resources: resources:
limits:
cpus: '4.0'
memory: 8G
reservations: reservations:
devices: devices:
- capabilities: [gpu] - capabilities: [gpu]