Skip to content

Commit

Permalink
draft: add resource limits
Browse files Browse the repository at this point in the history
  • Loading branch information
cmelone committed Sep 27, 2024
1 parent cee9c18 commit 8777cd3
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions gantry/routes/prediction/prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ async def predict(db: aiosqlite.Connection, spec: dict, strategy: str = None) ->
predictions = {}
if not sample:
predictions = {
# TODO: do we want to avoid limits by default?
"cpu_request": DEFAULT_CPU_REQUEST,
"mem_request": DEFAULT_MEM_REQUEST,
}
Expand All @@ -51,6 +52,8 @@ async def predict(db: aiosqlite.Connection, spec: dict, strategy: str = None) ->
# averages the respective metric in the sample
"cpu_request": sum([build[0] for build in sample]) / len(sample),
"mem_request": sum([build[2] for build in sample]) / len(sample),
"cpu_limit": sum([build[1] for build in sample]) / len(sample),
"mem_limit": sum([build[3] for build in sample]) / len(sample),
}

if strategy == "ensure_higher":
Expand All @@ -63,6 +66,7 @@ async def predict(db: aiosqlite.Connection, spec: dict, strategy: str = None) ->
if predictions["mem_request"] < 10_000_000:
logger.warning(f"Warning: Memory request for {spec} is below 10MB")
predictions["mem_request"] = DEFAULT_MEM_REQUEST
# TODO add similar checks for limits

# convert predictions to k8s friendly format
for k, v in predictions.items():
Expand All @@ -78,6 +82,8 @@ async def predict(db: aiosqlite.Connection, spec: dict, strategy: str = None) ->
# and clogging up the code
"KUBERNETES_CPU_REQUEST": predictions["cpu_request"],
"KUBERNETES_MEMORY_REQUEST": predictions["mem_request"],
"KUBERNETES_CPU_LIMIT": predictions["cpu_limit"],
"KUBERNETES_MEMORY_LIMIT": predictions["mem_limit"],
},
}

Expand Down

0 comments on commit 8777cd3

Please sign in to comment.