FairshareSchedulingPolicy
- class aws_cdk.aws_batch.FairshareSchedulingPolicy(scope, id, *, compute_reservation=None, scheduling_policy_name=None, share_decay=None, shares=None)
Bases:
Resource
Represents a Fairshare Scheduling Policy. Instructs the scheduler to allocate ComputeEnvironment vCPUs based on Job shareIdentifiers.
The Faireshare Scheduling Policy ensures that each share gets a certain amount of vCPUs. The scheduler does this by deciding how many Jobs of each share to schedule relative to how many jobs of each share are currently being executed by the ComputeEnvironment. The weight factors associated with each share determine the ratio of vCPUs allocated; see the readme for a more in-depth discussion of fairshare policies.
- Resource:
AWS::Batch::SchedulingPolicy
- ExampleMetadata:
infused
Example:
fairshare_policy = batch.FairshareSchedulingPolicy(self, "myFairsharePolicy") fairshare_policy.add_share( share_identifier="A", weight_factor=1 ) fairshare_policy.add_share( share_identifier="B", weight_factor=1 ) batch.JobQueue(self, "JobQueue", scheduling_policy=fairshare_policy )
- Parameters:
scope (
Construct
) –id (
str
) –compute_reservation (
Union
[int
,float
,None
]) – Used to calculate the percentage of the maximum available vCPU to reserve for share identifiers not present in the Queue. The percentage reserved is defined by the Scheduler as:(computeReservation/100)^ActiveFairShares
whereActiveFairShares
is the number of active fair share identifiers. For example, a computeReservation value of 50 indicates that AWS Batch reserves 50% of the maximum available vCPU if there’s only one fair share identifier. It reserves 25% if there are two fair share identifiers. It reserves 12.5% if there are three fair share identifiers. A computeReservation value of 25 indicates that AWS Batch should reserve 25% of the maximum available vCPU if there’s only one fair share identifier, 6.25% if there are two fair share identifiers, and 1.56% if there are three fair share identifiers. Default: - no vCPU is reservedscheduling_policy_name (
Optional
[str
]) – The name of this SchedulingPolicy. Default: - generated by CloudFormationshare_decay (
Optional
[Duration
]) – The amount of time to use to measure the usage of each job. The usage is used to calculate a fair share percentage for each fair share identifier currently in the Queue. A value of zero (0) indicates that only current usage is measured. The decay is linear and gives preference to newer jobs. The maximum supported value is 604800 seconds (1 week). Default: - 0: only the current job usage is consideredshares (
Optional
[Sequence
[Union
[Share
,Dict
[str
,Any
]]]]) – The shares that this Scheduling Policy applies to. Note: It is possible to submit Jobs to the queue with Share Identifiers that are not recognized by the Scheduling Policy. Default: - no shares
Methods
- add_share(*, share_identifier, weight_factor)
Add a share this to this Fairshare SchedulingPolicy.
- Parameters:
share_identifier (
str
) – The identifier of this Share. All jobs that specify this share identifier when submitted to the queue will be considered as part of this Share.weight_factor (
Union
[int
,float
]) – The weight factor given to this Share. The Scheduler decides which jobs to put in the Compute Environment such that the following ratio is equal for each job:sharevCpu / weightFactor
, wheresharevCpu
is the total amount of vCPU given to that particular share; that is, the sum of the vCPU of each job currently in the Compute Environment for that share. See the readme of this module for a detailed example that shows how these are used, how it relates tocomputeReservation
, and howshareDecay
affects these calculations.
- Return type:
None
- apply_removal_policy(policy)
Apply the given removal policy to this resource.
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you’ve removed it from the CDK application or because you’ve made a change that requires the resource to be replaced.
The resource can be deleted (
RemovalPolicy.DESTROY
), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN
).- Parameters:
policy (
RemovalPolicy
) –- Return type:
None
- to_string()
Returns a string representation of this construct.
- Return type:
str
Attributes
- compute_reservation
Used to calculate the percentage of the maximum available vCPU to reserve for share identifiers not present in the Queue.
The percentage reserved is defined by the Scheduler as:
(computeReservation/100)^ActiveFairShares
whereActiveFairShares
is the number of active fair share identifiers.For example, a computeReservation value of 50 indicates that AWS Batch reserves 50% of the maximum available vCPU if there’s only one fair share identifier. It reserves 25% if there are two fair share identifiers. It reserves 12.5% if there are three fair share identifiers.
A computeReservation value of 25 indicates that AWS Batch should reserve 25% of the maximum available vCPU if there’s only one fair share identifier, 6.25% if there are two fair share identifiers, and 1.56% if there are three fair share identifiers.
- env
The environment this resource belongs to.
For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.
- node
The tree node.
- scheduling_policy_arn
The arn of this scheduling policy.
- scheduling_policy_name
The name of this scheduling policy.
- share_decay
The amount of time to use to measure the usage of each job.
The usage is used to calculate a fair share percentage for each fair share identifier currently in the Queue. A value of zero (0) indicates that only current usage is measured. The decay is linear and gives preference to newer jobs.
The maximum supported value is 604800 seconds (1 week).
- shares
The shares that this Scheduling Policy applies to.
Note: It is possible to submit Jobs to the queue with Share Identifiers that are not recognized by the Scheduling Policy.
- stack
The stack in which this resource is defined.
Static Methods
- classmethod from_fairshare_scheduling_policy_arn(scope, id, fairshare_scheduling_policy_arn)
Reference an exisiting Scheduling Policy by its ARN.
- Parameters:
scope (
Construct
) –id (
str
) –fairshare_scheduling_policy_arn (
str
) –
- Return type:
- classmethod is_construct(x)
Checks if
x
is a construct.Use this method instead of
instanceof
to properly detectConstruct
instances, even when the construct library is symlinked.Explanation: in JavaScript, multiple copies of the
constructs
library on disk are seen as independent, completely different libraries. As a consequence, the classConstruct
in each copy of theconstructs
library is seen as a different class, and an instance of one class will not test asinstanceof
the other class.npm install
will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of theconstructs
library can be accidentally installed, andinstanceof
will behave unpredictably. It is safest to avoid usinginstanceof
, and using this type-testing method instead.- Parameters:
x (
Any
) – Any object.- Return type:
bool
- Returns:
true if
x
is an object created from a class which extendsConstruct
.
- classmethod is_owned_resource(construct)
Returns true if the construct was created by CDK, and false otherwise.
- Parameters:
construct (
IConstruct
) –- Return type:
bool
- classmethod is_resource(construct)
Check whether the given construct is a Resource.
- Parameters:
construct (
IConstruct
) –- Return type:
bool