Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for empty top-level models and non-empty sub-models #73

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions service_capacity_modeling/capacity_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,7 @@ def _plan_percentiles(

mean_plans = []
for mean_sub_model, mean_sub_desire in model_mean_desires.items():
mean_plans.append(
self._plan_certain(
mean_sub_plan = self._plan_certain(
model_name=mean_sub_model,
region=region,
desires=mean_sub_desire,
Expand All @@ -380,7 +379,8 @@ def _plan_percentiles(
instance_families=instance_families,
drives=drives,
)
)
if mean_sub_plan:
mean_plans.append(mean_sub_plan)

mean_plan = cast(
Sequence[CapacityPlan],
Expand All @@ -392,8 +392,7 @@ def _plan_percentiles(
for percentile_sub_model, percentile_sub_desire in model_percentile_desires[
index
].items():
percentile_plan.append(
self._plan_certain(
percentile_sub_plan = self._plan_certain(
model_name=percentile_sub_model,
region=region,
desires=percentile_sub_desire,
Expand All @@ -404,7 +403,9 @@ def _plan_percentiles(
instance_families=instance_families,
drives=drives,
)
)
if percentile_sub_plan:
percentile_plan.append(percentile_sub_plan)

percentile_plans[percentile] = cast(
Sequence[CapacityPlan],
[
Expand Down Expand Up @@ -443,8 +444,7 @@ def plan_certain(
desires=desires,
extra_model_arguments=extra_model_arguments,
):
results.append(
self._plan_certain(
sub_plan = self._plan_certain(
model_name=sub_model,
region=region,
desires=sub_desires,
Expand All @@ -455,7 +455,8 @@ def plan_certain(
instance_families=instance_families,
drives=drives,
)
)
if sub_plan:
results.append(sub_plan)

return [functools.reduce(merge_plan, composed) for composed in zip(*results)]

Expand Down
68 changes: 67 additions & 1 deletion tests/netflix/test_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_es_increasing_qps_simple():
for zonal in cap_plan.least_regret[0].candidate_clusters.zonal:
zonal_result[zonal.cluster_type].append(zonal_summary(zonal))

expected_families = set(["r", "m", "i"])
expected_families = {"r", "m", "i"}
for cluster_type in list(zonal_result.keys()):
zonal_by_increasing_qps = zonal_result[cluster_type]

Expand All @@ -62,6 +62,72 @@ def test_es_increasing_qps_simple():
), f"disk for {cluster_type} going down as QPS went up?"


def test_es_simple_mean_percentiles():
simple = CapacityDesires(
service_tier=1,
query_pattern=QueryPattern(
estimated_read_per_second=Interval(
low=100, mid=1000, high=10_000, confidence=0.98
),
estimated_write_per_second=Interval(
low=100, mid=1000, high=10_000, confidence=0.98
),
),
data_shape=DataShape(
estimated_state_size_gib=Interval(
low=20, mid=200, high=2000, confidence=0.98
),
),
)

cap_plan = planner.plan(
model_name="org.netflix.elasticsearch",
region="us-east-1",
desires=simple,
simulations=256,
)

assert len(cap_plan.mean) > 0, "mean is empty"
assert (
all(mean_plan for mean_plan in cap_plan.mean)
), "One or more mean plans are empty"

assert len(cap_plan.percentiles) > 0, "percentiles are empty"
assert (
all(percentile_plan for percentile_plan in cap_plan.percentiles.values())
), "One or more percentile plans are empty"


def test_es_simple_certain():
simple = CapacityDesires(
service_tier=1,
query_pattern=QueryPattern(
estimated_read_per_second=Interval(
low=100, mid=1000, high=10_000, confidence=0.98
),
estimated_write_per_second=Interval(
low=100, mid=1000, high=10_000, confidence=0.98
),
),
data_shape=DataShape(
estimated_state_size_gib=Interval(
low=20, mid=200, high=2000, confidence=0.98
),
),
)

cap_plan = planner.plan_certain(
model_name="org.netflix.elasticsearch",
region="us-east-1",
desires=simple,
)

assert len(cap_plan) > 0, "Resulting cap_plan is empty"
assert (
all(plan for plan in cap_plan)
), "One or more plans is empty"


def zonal_summary(zlr):
zlr_cpu = zlr.count * zlr.instance.cpu
zlr_cost = zlr.annual_cost
Expand Down
Loading