Adds psutil support for max_rss on other platforms

This commit is contained in:
Ilan Steemers
2020-07-05 18:18:43 +02:00
parent b16878f36f
commit c94f2cb816
5 changed files with 31 additions and 22 deletions
+18 -7
View File
@@ -20,14 +20,21 @@ from django.utils.translation import gettext_lazy as _
# Local
import django_q.tasks
from django_q.brokers import get_broker, Broker
from django_q.conf import Conf, logger, psutil, get_ppid, error_reporter
from django_q.conf import (
Conf,
logger,
psutil,
get_ppid,
error_reporter,
croniter,
resource,
)
from django_q.humanhash import humanize
from django_q.models import Task, Success, Schedule
from django_q.queues import Queue
from django_q.signals import pre_execute
from django_q.signing import SignedPackage, BadSignature
from django_q.status import Stat, Status
from django_q import croniter, resource
class Cluster:
@@ -434,11 +441,7 @@ def worker(
result_queue.put(task)
timer.value = -1 # Idle
# Recycle
if task_count == Conf.RECYCLE or (
resource
and Conf.MAX_RSS
and resource.getrusage(resource.RUSAGE_SELF).ru_maxrss >= Conf.MAX_RSS
):
if task_count == Conf.RECYCLE or rss_check():
timer.value = -2 # Recycled
break
logger.info(_(f"{name} stopped doing work"))
@@ -697,3 +700,11 @@ def set_cpu_affinity(n: int, process_ids: list, actual: bool = not Conf.TESTING)
if actual:
p.cpu_affinity(affinity)
logger.info(_(f"{pid} will use cpu {affinity}"))
def rss_check():
if Conf.MAX_RSS and resource:
return resource.getrusage(resource.RUSAGE_SELF).ru_maxrss >= Conf.MAX_RSS
elif Conf.MAX_RSS and psutil:
return psutil.Process().memory_info().rss >= Conf.MAX_RSS * 1024
return False