From 8c94129c97ad29cdc8913063898fcb6f0db9ba4c Mon Sep 17 00:00:00 2001 From: "Paul S. Schweigert" Date: Wed, 25 Sep 2024 20:32:26 -0400 Subject: [PATCH] more accurate sizing of args Signed-off-by: Paul S. Schweigert --- gateway/api/serializers.py | 1 + gateway/api/utils.py | 9 ++++++--- gateway/requirements.txt | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/gateway/api/serializers.py b/gateway/api/serializers.py index c8b93aac3..492f6feb6 100644 --- a/gateway/api/serializers.py +++ b/gateway/api/serializers.py @@ -13,6 +13,7 @@ from django.contrib.auth.models import Group, Permission from django.db.models import Q from rest_framework import serializers +import objsize from api.utils import build_env_variables, encrypt_env_vars from .models import ( diff --git a/gateway/api/utils.py b/gateway/api/utils.py index c1e2de3ce..db9d71691 100644 --- a/gateway/api/utils.py +++ b/gateway/api/utils.py @@ -17,6 +17,7 @@ from ray.dashboard.modules.job.common import JobStatus from django.conf import settings from parsley import makeGrammar +import objsize from .models import Job @@ -123,14 +124,16 @@ def build_env_variables(token, job: Job, args: str = None) -> Dict[str, str]: env variables dict """ extra = {} - # only set arguments if size is <1MB + # only set arguments envvar if not too big + # remove this after sufficient time for users to upgrade client arguments = "{}" if args: - if sys.getsizeof(args) < 1000000: + if objsize.get_deep_size(args) < 100000: + logger.debug("passing arguments as envvar for job [%s]", job.id) arguments = args else: logger.warning( - "arguments for job [%s] are > 1MB and will not be written to env var", + "arguments for job [%s] are too large and will not be written to env var", job.id, ) diff --git a/gateway/requirements.txt b/gateway/requirements.txt index d29458c91..ccf9e62cd 100644 --- a/gateway/requirements.txt +++ b/gateway/requirements.txt @@ -22,4 +22,5 @@ qiskit-ibm-runtime>=0.29.0 tzdata>=2024.1 django-cors-headers>=4.4.0, <5 parsley>=1.3, <2 -whitenoise>=6.7.0, <7 \ No newline at end of file +whitenoise>=6.7.0, <7 +objsize>=0.7.0