Skip to content

Commit

Permalink
more accurate sizing of args
Browse files Browse the repository at this point in the history
Signed-off-by: Paul S. Schweigert <[email protected]>
  • Loading branch information
psschwei committed Sep 26, 2024
1 parent 7118d44 commit 8c94129
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions gateway/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
9 changes: 6 additions & 3 deletions gateway/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
)

Expand Down
3 changes: 2 additions & 1 deletion gateway/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
whitenoise>=6.7.0, <7
objsize>=0.7.0

0 comments on commit 8c94129

Please sign in to comment.