Skip to content

Commit

Permalink
Add docker resource limits for jobs (#241)
Browse files Browse the repository at this point in the history
* Linting changes

* linting

* Use getattr for config
  • Loading branch information
evanyeyeye authored Jan 21, 2024
1 parent 182e322 commit 0b3b3bb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 4 additions & 0 deletions config.template.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ class Config(object):
DOCKER_RM_TIMEOUT = 5
DOCKER_HOST_USER = ""

# Docker autograding container resource limits
DOCKER_CORES_LIMIT = None
DOCKER_MEMORY_LIMIT = None # in MB

# Maximum size for input files in bytes
MAX_INPUT_FILE_SIZE = 10 * 1024 * 1024 * 1024 # 10GB

Expand Down
13 changes: 8 additions & 5 deletions restful_tango/tangoREST.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,19 @@ def checkFileExists(self, directory, filename, fileMD5):
except IOError:
continue

def createTangoMachine(
self, image, vmms=Config.VMMS_NAME, vmObj={"cores": 1, "memory": 512}
):
def createTangoMachine(self, image, vmms=Config.VMMS_NAME, vmObj=None):
"""createTangoMachine - Creates a tango machine object from image"""
cores = getattr(Config, "DOCKER_CORES_LIMIT", None)
memory = getattr(Config, "DOCKER_MEMORY_LIMIT", None)
if vmObj and "cores" in vmObj and "memory" in vmObj:
cores = vmObj["cores"]
memory = vmObj["memory"]
return TangoMachine(
name=image,
vmms=vmms,
image="%s" % (image),
cores=vmObj["cores"],
memory=vmObj["memory"],
cores=cores,
memory=memory,
disk=None,
network=None,
)
Expand Down
4 changes: 4 additions & 0 deletions vmms/localDocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ def runJob(self, vm, runTimeout, maxOutputFileSize):
)
args = ["docker", "run", "--name", instanceName, "-v"]
args = args + ["%s:%s" % (volumePath, "/home/mount")]
if vm.cores:
args = args + [f"--cpus={vm.cores}"]
if vm.memory:
args = args + ["-m", f"{vm.memory}m"]
args = args + [vm.image]
args = args + ["sh", "-c"]

Expand Down

0 comments on commit 0b3b3bb

Please sign in to comment.