-
Notifications
You must be signed in to change notification settings - Fork 0
/
locust_worker_service.ts
63 lines (54 loc) · 1.81 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
61
62
63
import { Construct } from 'constructs';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import { RetentionDays } from 'aws-cdk-lib/aws-logs';
import { Platform } from 'aws-cdk-lib/aws-ecr-assets';
export interface LocustWorkerServiceProps {
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 } = props;
const image = new ecs.AssetImage('app', { platform: Platform.LINUX_AMD64 });
const workerTaskDefinition = new ecs.FargateTaskDefinition(this, 'TaskDefinition', {
// a locust worker can use only 1 core: https://github.com/locustio/locust/issues/1493
cpu: 1024,
memoryLimitMiB: 2048,
});
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', {
cluster,
taskDefinition: workerTaskDefinition,
// You can adjust spot:on-demand ratio here
capacityProviderStrategies: [
{
capacityProvider: 'FARGATE_SPOT',
weight: 1,
},
{
capacityProvider: 'FARGATE',
weight: 0,
},
],
minHealthyPercent: 0,
});
this.service = service;
}
}