Skip to content
This repository has been archived by the owner on Oct 24, 2020. It is now read-only.

Commit

Permalink
feat: remove need to specify cpu_units
Browse files Browse the repository at this point in the history
We not allocate sufficient cpu units to ensure distinct task
placement across the cluster without forcing the test plan to
take it into account.

Closes #20
  • Loading branch information
bbangert committed Mar 20, 2017
1 parent 2856cab commit 87624fc
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
41 changes: 40 additions & 1 deletion ardere/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,45 @@
with open(shell_path, 'r') as f:
shell_script = f.read()

# List tracking vcpu's of all instance types for cpu unit reservations
# We are intentionally leaving out the following instance types as they're
# considered overkill for load-testing purposes or any instance req's we have
# experienced so far:
# P2, G2, F1, I3, D2
ec2_vcpu_by_vcpu = {
1: ["t2.nano", "t2.micro", "t2.small", "m3.medium"],
2: ["t2.medium", "t2.large", "m3.large", "m4.large", "c3.large",
"c4.large", "r3.large", "r4.large"],
4: ["t2.xlarge", "m3.xlarge", "m4.xlarge", "c3.xlarge", "c4.xlarge",
"r3.xlarge", "r4.xlarge"],
8: ["t2.2xlarge", "m3.2xlarge", "m4.2xlarge", "c3.2xlarge", "c4.2xlarge",
"r3.2xlarge", "r4.2xlarge"],
16: ["m4.4xlarge", "c3.4xlarge", "c4.4xlarge", "r3.4xlarge", "r4.4xlarge"],
32: ["c3.8xlarge", "r3.8xlarge", "r4.8xlarge"],
36: ["c4.8xlarge"],
40: ["m4.10xlarge"],
64: ["m4.16xlarge", "x1.16xlarge", "r4.16xlarge"],
128: ["x1.32xlarge"]
}

# Build a list of vcpu's by instance type
ec2_vcpu_by_type = {}
for vcpu, instance_types in ec2_vcpu_by_vcpu.items():
for instance_type in instance_types:
ec2_vcpu_by_type[instance_type] = vcpu


def cpu_units_for_instance_type(instance_type):
"""Calculate how many CPU units to allocate for an instance_type
We calculate cpu_units as 1024 * vcpu's for each instance to allocate
almost the entirety of the instance's cpu units to the load-testing
container. We take out 512 to ensure some leftover capacity for other
utility containers we run with the load-testing container.
"""
return (ec2_vcpu_by_type[instance_type] * 1024) - 512


class ECSManager(object):
"""ECS Manager queries and manages an ECS cluster"""
Expand Down Expand Up @@ -165,7 +204,7 @@ def create_service(self, step):
{
"name": step["name"],
"image": step["container_name"],
"cpu": step["cpu_units"],
"cpu": cpu_units_for_instance_type(step["instance_type"]),
# using only memoryReservation sets no hard limit
"memoryReservation": 256,
"environment": env_vars,
Expand Down
2 changes: 0 additions & 2 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"instance_count": 1,
"instance_type": "t2.medium",
"run_max_time": 140,
"cpu_units": 2048,
"environment_data": [
"SOME_VAR=great-value"
],
Expand All @@ -26,7 +25,6 @@
"instance_count": 1,
"instance_type": "t2.medium",
"run_max_time": 140,
"cpu_units": 2048,
"container_name": "bbangert/pushgo:1.5rc4",
"port_mapping": "8080:8090,8081:8081,3000:3000,8082:8082",
"load_balancer": {
Expand Down
4 changes: 4 additions & 0 deletions tests/test_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ def test_create_service(self):

eq_(step["serviceArn"], "arn:of:some:service::")
ecs._ecs_client.register_task_definition.assert_called()
_, kwargs = ecs._ecs_client.register_task_definition.call_args
container_def = kwargs["containerDefinitions"][0]

eq_(container_def["cpu"], 1536)

def test_create_services(self):
ecs = self._make_FUT()
Expand Down

0 comments on commit 87624fc

Please sign in to comment.