Skip to content
This repository was archived by the owner on May 31, 2024. It is now read-only.

Conversation

@josuebc
Copy link
Contributor

@josuebc josuebc commented Apr 20, 2022

Adding the option to provide cpu count and memory size for the engine via the yaml project file.

Issue: #204

Description of Changes
I added the ability to change the cpu count and memory limit of the engine within a specific context.

These was accomplish by adding two new variables that get included on the call to the backend, they get included with all existing variables.

In the backend these new variables will only be used by the engines logic when setting up the workflow via "agc context deploy --context "

engines in context for these changes are: Cromwell, Toil, miniwdl, nextflow and snakemake .

Description of how you validated changes
Unit Test for the changes were verified all pass.
Exiting unit test affected by the changes were update and validated.

Lastly I build the CLI and ran multiple variation for all engines how the end user would update the project file and verified all got reflected as expected in the workflows

agc account activate
agc context deploy --context spotContext
agc workflow run hello --context spotContext

Checklist

  • If this change would make any existing documentation invalid, I have included those updates within this PR
  • I have added/updated unit tests that prove my fix is effective or that my feature works
  • I have linted my code before raising the PR
  • Title of this Pull Request follows Conventional Commits standard: https://www.conventionalcommits.org/en/v1.0.0/

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@josuebc josuebc temporarily deployed to slack April 20, 2022 18:31 Inactive
markjschreiber
markjschreiber previously approved these changes Apr 26, 2022
*/
public readonly vCpus?: number;
/**
* The maximum memory limit that an environment can reach for the nextflow engine.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this NextFlow specific? How it will affect other supported engines? Have we tested this change with other engines?

Copy link
Contributor Author

@josuebc josuebc May 4, 2022

Choose a reason for hiding this comment

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

No, changes got updated to support all engines
I tested for expected behavior was performed on all engines.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should you update comments than?

Copy link
Contributor

@markjschreiber markjschreiber left a comment

Choose a reason for hiding this comment

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

The JSON schema and binding would allow you to provide these parameters for any engine which creates the impression you can do it for all. The docs also don't say this is only for Nextflow.

Is there a reason that the approach cannot be generalized to all engines? Or at least those engines that run as Batch Jobs (miniwdl, nextflow and snakemake).

Copy link
Contributor

@markjschreiber markjschreiber left a comment

Choose a reason for hiding this comment

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

Would it be possible to extend this approach to include Cromwell and Toil? Although they run as ECS tasks rather than Batch jobs they have similarly configurable resource requirements. You would need to make sure that the minimum values are what they are now.

The ECS services are created by packages/cdk/lib/constructs/secure-service.ts and the cpu and memory values are in the SecureServiceProps

@josuebc josuebc requested a review from markjschreiber May 25, 2022 00:23
markjschreiber
markjschreiber previously approved these changes May 25, 2022
Copy link
Contributor

@markjschreiber markjschreiber left a comment

Choose a reason for hiding this comment

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

One minor suggestion in the docs but otherwise great.

@josuebc josuebc requested a review from markjschreiber May 25, 2022 16:42
platformCapabilities: [PlatformCapabilities.FARGATE],
container: {
memoryLimitMiB: this.engineMemoryMiB,
vcpus: props.vcpus || 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

can you create a constant with a meaningful name for this magic number?

const defaultVCPUs = 1;

container: {
memoryLimitMiB: this.engineMemoryMiB,
vcpus: props.vcpus || 1,
memoryLimitMiB: props.engineMemoryMiB || 4096,
Copy link
Contributor

Choose a reason for hiding this comment

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

can you create a constant with a meaningful name for this magic number?

const defaultMemoryMiB = 4096;

*/
public readonly vCpus?: number;
/**
* The maximum memory limit that an environment can reach for the nextflow engine.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should you update comments than?


// TODO: Move log group creation into service construct and make it a property
this.engine = this.getEngineServiceDefinition(props.vpc, props.subnets, engineContainer, this.engineLogGroup);
this.engine = this.getEngineServiceDefinition(props.vpc, props.subnets, engineContainer, this.engineLogGroup, params);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you just cut in between the line of code and the comment that corresponds to that line of code. Now this TODO comment sounds out of context. Could you please rearrange code, so the comment stays close to the related line?

taskRole: this.engineRole,
cpu: serviceContainer.cpu,
memoryLimitMiB: serviceContainer.memoryLimitMiB,
cpu: (params.vCpus ? params.vCpus * 1024 : undefined) || serviceContainer.cpu,
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the meaning of this 1024 magic number? can you use a constant with a meaningful name instead? I think it will improve readability and will serve self-documenting purpose.

const container = definition.addContainer(serviceContainer.serviceName, {
cpu: serviceContainer.cpu,
memoryLimitMiB: serviceContainer.memoryLimitMiB,
cpu: (params.vCpus ? params.vCpus * 1024 : undefined) || serviceContainer.cpu,
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto. By the way, may be we should consider avoiding this duplicated code block?

taskRole: this.engineRole,
cpu: serviceContainer.cpu,
memoryLimitMiB: serviceContainer.memoryLimitMiB,
cpu: (params.vCpus ? params.vCpus * 1024 : undefined) || serviceContainer.cpu,
Copy link
Contributor

Choose a reason for hiding this comment

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

Here we go again... I think if some number has to be repeated more than once, it should be moved to a constant.

definition.addContainer(serviceContainer.serviceName, {
cpu: serviceContainer.cpu,
memoryLimitMiB: serviceContainer.memoryLimitMiB,
cpu: (params.vCpus ? params.vCpus * 1024 : undefined) || serviceContainer.cpu,
Copy link
Contributor

Choose a reason for hiding this comment

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

and one more time...


type ResourceRequirement struct {
VCpus int `yaml:"vcpus,omitempty"`
MemoryLimitMiB int `yaml:"memoryLimit,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it will work as you might expect. "omitempty" means not to include values that absent. In your case values always present.

Here is the test:
https://go.dev/play/p/WB4AzY1JhTT

Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest a unit test for that.

Type: "nextflow",
Engine: "nextflow",
ResourceRequirements: ResourceRequirement{
VCpus: 2,
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets add tests with partial configuration. e.g. either VCpus or MemoryLimitMiB is set, but not both.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants