Adds max_rss memory limit for recycle

This commit is contained in:
Ilan Steemers
2020-07-05 17:04:16 +02:00
parent e0beb502dd
commit 83b8b7c0d7
2 changed files with 21 additions and 16 deletions
+3 -1
View File
@@ -1,6 +1,7 @@
# Standard
import ast
import importlib
import resource
import signal
import socket
import traceback
@@ -10,6 +11,7 @@ from time import sleep
# External
import arrow
# Django
from django import db
from django.conf import settings
@@ -433,7 +435,7 @@ def worker(
result_queue.put(task)
timer.value = -1 # Idle
# Recycle
if task_count == Conf.RECYCLE:
if task_count == Conf.RECYCLE or (Conf.MAX_RSS and resource.getrusage(resource.RUSAGE_SELF).ru_maxrss >= Conf.MAX_RSS):
timer.value = -2 # Recycled
break
logger.info(_(f"{name} stopped doing work"))
+3
View File
@@ -104,6 +104,9 @@ class Conf:
# Number of tasks each worker can handle before it gets recycled. Useful for releasing memory
RECYCLE = conf.get("recycle", 500)
# The maximum resident set size in kilobytes before a worker will recycle. Useful for limiting memory usage.
MAX_RSS = conf.get("max_rss", None)
# Number of seconds to wait for a worker to finish.
TIMEOUT = conf.get("timeout", None)