-
Notifications
You must be signed in to change notification settings - Fork 1
/
locust_worker_service.ts
60 lines (52 loc) · 1.66 KB
/
locust_worker_service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { Construct } from 'constructs';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import { RetentionDays } from 'aws-cdk-lib/aws-logs';
export interface LocustWorkerServiceProps {
readonly image: ecs.ContainerImage;
readonly cluster: ecs.ICluster;
readonly locustMasterHostName: string;
}
export class LocustWorkerService extends Construct {
public readonly service: ecs.FargateService;
constructor(scope: Construct, id: string, props: LocustWorkerServiceProps) {
super(scope, id);
const { cluster, image } = props;
const workerTaskDefinition = new ecs.FargateTaskDefinition(this, 'TaskDefinition', {
cpu: 4096,
memoryLimitMiB: 8192,
});
workerTaskDefinition
.addContainer('locust', {
image,
command: ['--worker', '--master-host', props.locustMasterHostName],
logging: ecs.LogDriver.awsLogs({
streamPrefix: 'locust-worker',
logRetention: RetentionDays.SIX_MONTHS,
}),
environment: {},
})
.addUlimits({
name: ecs.UlimitName.NOFILE,
// Set as Locust recommendation https://github.com/locustio/locust/pull/1375
hardLimit: 10000,
softLimit: 10000,
});
const service = new ecs.FargateService(this, 'Service', {
desiredCount: 20, // set number of locust worker nodes
cluster,
taskDefinition: workerTaskDefinition,
// You can adjust spot:on-demand ratio here
capacityProviderStrategies: [
{
capacityProvider: 'FARGATE_SPOT',
weight: 1,
},
{
capacityProvider: 'FARGATE',
weight: 0,
},
],
});
this.service = service;
}
}