Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add memory/CPU limit, and parameters to docker run #8

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions run_docker.cwl
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ inputs:
type: string
- id: parentid
type: string
- id: status
type: string
- id: synapse_config
type: File
- id: input_dir
Expand All @@ -29,6 +27,10 @@ inputs:
type: File
- id: store
type: boolean?
- id: memory
type: int
- id: cpus
type: int

arguments:
- valueFrom: $(inputs.docker_script.path)
Expand All @@ -40,14 +42,16 @@ arguments:
prefix: -d
- valueFrom: $(inputs.store)
prefix: --store
- valueFrom: $(inputs.status)
prefix: --status
- valueFrom: $(inputs.parentid)
prefix: --parentid
- valueFrom: $(inputs.synapse_config.path)
prefix: -c
- valueFrom: $(inputs.input_dir)
prefix: -i
- valueFrom: $(inputs.memory)
prefix: --memory
- valueFrom: $(inputs.cpus)
prefix: --cpus

requirements:
- class: InitialWorkDirRequirement
Expand Down
30 changes: 21 additions & 9 deletions run_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ def untar(directory, tar_filename):

def main(syn, args):
"""Run docker model"""
if args.status == "INVALID":
raise Exception("Docker image is invalid")

# The new toil version doesn't seem to pull the docker config file from
# .docker/config.json...
# client = docker.from_env()
Expand Down Expand Up @@ -129,16 +126,24 @@ def main(syn, args):
cont.remove()
else:
container = cont
# This is how you calculate the N number of CPUs to use
cpu_period = 100000
cpu_quota = args.cpus * cpu_period
# If the container doesn't exist, make sure to run the docker image
if container is None:
# Run as detached, logs will stream below
print("running container")
try:
container = client.containers.run(docker_image,
detach=True, volumes=volumes,
name=args.submissionid,
network_disabled=True,
mem_limit='6g', stderr=True)
container = client.containers.run(
docker_image,
"--input /data --output /output",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We normally specify the input directory as /input -- should we update the template to /data instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these need to be parameters to the cwl file.

detach=True, volumes=volumes,
name=args.submissionid,
network_disabled=True,
mem_limit=f'{args.memory}g', stderr=True,
cpu_period=cpu_period,
cpu_quota=cpu_quota,
)
except docker.errors.APIError as err:
remove_docker_container(args.submissionid)
errors = str(err) + "\n"
Expand Down Expand Up @@ -203,7 +208,14 @@ def main(syn, args):
help="to store logs")
parser.add_argument("--parentid", required=True,
help="Parent Id of submitter directory")
parser.add_argument("--status", required=True, help="Docker image status")
parser.add_argument(
"--memory", type=int, default=4,
help="Max amount of memory (gb) used by Docker container."
)
parser.add_argument(
"--cpus", type=int, default=1,
help="Max number of CPUs that can be used by Docker container."
)
args = parser.parse_args()
syn = synapseclient.Synapse(configPath=args.synapse_config)
syn.login()
Expand Down
2 changes: 0 additions & 2 deletions workflow.cwl
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ steps:
source: "#get_docker_config/docker_registry"
- id: docker_authentication
source: "#get_docker_config/docker_authentication"
- id: status
source: "#validate_docker/status"
- id: parentid
source: "#submitterUploadSynId"
- id: synapse_config
Expand Down