Skip to content

Commit d0ba59f

Browse files
committed
Introduction of the input structure for endpoints
1 parent 6f06bb7 commit d0ba59f

14 files changed

Lines changed: 146 additions & 52 deletions

documentation/backend_documentation/requests_generator.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class RVConfig(BaseModel):
4040
distribution: Literal["poisson", "normal", "gaussian"] = "poisson"
4141
variance: float | None = None # required only for normal/gaussian
4242

43-
class SimulationInput(BaseModel):
43+
class RqsGeneratorInput(BaseModel):
4444
"""Define simulation inputs."""
4545
avg_active_users: RVConfig
4646
avg_request_per_minute_per_user: RVConfig

src/app/api/simulation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
from fastapi import APIRouter
55

66
from app.core.simulation.simulation_run import run_simulation
7-
from app.schemas.simulation_input import SimulationInput
7+
from app.schemas.requests_generator_input import RqsGeneratorInput
88
from app.schemas.simulation_output import SimulationOutput
99

1010
router = APIRouter()
1111

1212
@router.post("/simulation")
13-
async def event_loop_simulation(input_data: SimulationInput) -> SimulationOutput:
13+
async def event_loop_simulation(input_data: RqsGeneratorInput) -> SimulationOutput:
1414
"""Run the simulation and return aggregate KPIs."""
1515
rng = np.random.default_rng()
1616
return run_simulation(input_data, rng=rng)

src/app/config/constants.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
from enum import IntEnum, StrEnum
44

5+
# --------------------------------------------------------
6+
# CONSTANTS FOR THE REQUESTS GENERATOR
7+
# --------------------------------------------------------
58

69
class TimeDefaults(IntEnum):
710
"""Default time-related constants (all in seconds)."""
@@ -20,4 +23,45 @@ class Distribution(StrEnum):
2023
POISSON = "poisson"
2124
NORMAL = "normal"
2225

26+
# --------------------------------------------------------
27+
# CONSTANTS FOR THE REQUESTS ENDPOINT STRUCTURE IN THE
28+
# REQUESTS HANDLER
29+
# --------------------------------------------------------
30+
31+
# Idea here is to create an ordered nested dict with
32+
# this structure: {endpoint_name: {
33+
# operation_type:
34+
# latency (s)/ram (kb): value}}
35+
# we need Enum to have a better control on the dict keys in the
36+
# pydantic schema
37+
38+
class EndpointIO(StrEnum):
39+
"""Name of I/O operations"""
40+
41+
IO_WITH_CHILD = "io_new_coroutine" #Child task exit
42+
IO_LLM_BOUND = "io_llm" # Llm speicif task
43+
IO_SLEEP = "i/o_bound" # No child task
44+
45+
46+
class EndpointCPU(StrEnum):
47+
"""Name of CPU bound operations"""
48+
49+
INITIAL_PARSING = "initial_parsing"
50+
CPU_BOUND_OPERATION = "cpu_bound_operation"
51+
52+
53+
class EndpointRAM(StrEnum):
54+
"""Name of the operation to add ram"""
55+
56+
RAM = "ram"
57+
58+
59+
class MetricKeys(StrEnum):
60+
"""
61+
Name of the key to quantify the operation
62+
in terms of Ram or latency
63+
"""
64+
65+
LATENCY = "latency"
66+
NECESSARY_RAM = "necessary_ram"
2367

src/app/core/event_samplers/gaussian_poisson.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
truncated_gaussian_generator,
1717
uniform_variable_generator,
1818
)
19-
from app.schemas.requests_generator_input import SimulationInput
19+
from app.schemas.requests_generator_input import RqsGeneratorInput
2020

2121

2222
def gaussian_poisson_sampling(
23-
input_data: SimulationInput,
23+
input_data: RqsGeneratorInput,
2424
*,
2525
rng: np.random.Generator | None = None,
2626
) -> Generator[float, None, None]:

src/app/core/event_samplers/poisson_poisson.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
poisson_variable_generator,
1414
uniform_variable_generator,
1515
)
16-
from app.schemas.requests_generator_input import SimulationInput
16+
from app.schemas.requests_generator_input import RqsGeneratorInput
1717

1818

1919
def poisson_poisson_sampling(
20-
input_data: SimulationInput,
20+
input_data: RqsGeneratorInput,
2121
*,
2222
rng: np.random.Generator | None = None,
2323
) -> Generator[float, None, None]:

src/app/core/simulation/requests_generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
import numpy as np
1818

19-
from app.schemas.requests_generator_input import SimulationInput
19+
from app.schemas.requests_generator_input import RqsGeneratorInput
2020

2121

2222
def requests_generator(
23-
input_data: SimulationInput,
23+
input_data: RqsGeneratorInput,
2424
*,
2525
rng: np.random.Generator | None = None,
2626
) -> Generator[float, None, None]:

src/app/core/simulation/simulation_run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414

1515
import numpy as np
1616

17-
from app.schemas.simulation_input import SimulationInput
17+
from app.schemas.requests_generator_input import RqsGeneratorInput
1818

1919

2020

2121

2222
def run_simulation(
23-
input_data: SimulationInput,
23+
input_data: RqsGeneratorInput,
2424
*,
2525
rng: np.random.Generator,
2626
) -> SimulationOutput:
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""Definition of the full input for the simulation"""
2+
3+
from pydantic import BaseModel
4+
5+
from app.schemas.requests_generator_input import RqsGeneratorInput
6+
from app.schemas.requests_handler_input import Endpoint
7+
8+
9+
class SimulationPayload(BaseModel):
10+
"""Full input structure to perform a simulation"""
11+
12+
rqs_input: RqsGeneratorInput
13+
all_endpoints: list[Endpoint]

src/app/schemas/requests_generator_input.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def default_variance(cls, model: "RVConfig") -> "RVConfig": # noqa: N805
3131
model.variance = model.mean
3232
return model
3333

34-
class SimulationInput(BaseModel):
34+
class RqsGeneratorInput(BaseModel):
3535
"""Define the expected variables for the simulation"""
3636

3737
avg_active_users: RVConfig
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""Defining the input schema for the requests handler"""
2+
3+
from pydantic import BaseModel, field_validator
4+
5+
from app.config.constants import EndpointCPU, EndpointIO, EndpointRAM, MetricKeys
6+
7+
8+
class Step(BaseModel):
9+
"""Full step structure to be validated with pydantic"""
10+
11+
kind: EndpointIO | EndpointCPU | EndpointRAM
12+
metrics: dict[MetricKeys, float | int]
13+
14+
@field_validator("metrics", mode="before")
15+
def ensure_metric_exist_positive(
16+
cls, # noqa: N805
17+
v: dict[MetricKeys, float | int],
18+
) -> dict[MetricKeys, float | int]:
19+
"""Ensure the measure of an operation exist and is positive"""
20+
for key, value in v.items():
21+
if not value or value <= 0:
22+
msg = f"{key} must be a positive number"
23+
raise ValueError(msg)
24+
return v
25+
26+
27+
class Endpoint(BaseModel):
28+
"""full endpoint structure to be validated with pydantic"""
29+
30+
endpoint_name: str
31+
steps: list[Step]
32+
33+
@field_validator("endpoint_name", mode="before")
34+
def name_to_lower(cls, v: str) -> str: # noqa: N805
35+
"""Standardize endpoint name to be lowercase"""
36+
return v.lower()
37+

0 commit comments

Comments
 (0)