gouravnayak97/cloud_resource_allocation
Cloud Resource Allocation
A FastAPI-based cloud autoscaling environment for benchmarking autoscaler agents against synthetic workloads.
The repo provides:
- A reusable OpenEnv-style environment for cloud autoscaling (
app/env.py) - A deterministic workload simulator with steady, diurnal, and flash-crowd patterns (
app/simulator.py) - A FastAPI server exposing task discovery, reset, step, and grading endpoints (
app/main.py) - A rule-based baseline autoscaler agent (
agent.py) - An example inference client that runs an episode against the server (
inference.py) - Task definitions for
easy,medium, andhardscenarios intasks/*.yaml
Features
FastAPIenvironment server with REST endpoints for interactive agent control- Task configs driven by YAML files for easy scenario prototyping
- Step-level reward and episode scoring with latency, cost, instability, and SLA penalties
- Baseline adaptive agent that scales servers using a simple threshold policy
- Deterministic workloads seeded for reproducible evaluation
Repository Structure
app/main.py- FastAPI application and HTTP endpoint definitionsapp/env.py- OpenEnv-style environment wrapper around the simulatorapp/simulator.py- Cloud autoscaling simulator and workload generatorapp/models.py- Pydantic request/response and task schemasapp/grader.py- Episode grader and scoring logicagent.py- Example adaptive autoscaler agentinference.py- Example client that interacts with the servertasks/- Task configuration YAML files:easy.yaml,medium.yaml,hard.yamlrequirements.txt- Python dependencies
Requirements
- Python 3.11+ recommended
fastapiuvicorn[standard]pydanticnumpypyyaml
Install dependencies with:
pip install -r requirements.txtRunning the Server
Start the FastAPI server from the repository root:
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000The server exposes the following endpoints:
GET /health- health check and task countGET /tasks- list available tasks and action schemaPOST /reset- create a new episode for a selected taskPOST /step- advance the environment by one actionGET /state- read the current observation without steppingGET /grader- score the completed episode
Example Inference Flow
Use inference.py as a simple example client to run an episode.
- Start the API server.
- Run:
python inference.pyThis script:
- fetches available tasks
- resets the environment for the first task
- repeatedly calls
/stepusing an LLM prompt via the OpenAI client - uses strict STDOUT logging formatting required by the OpenEnv validation
- retrieves the final graded episode score
Task Definitions
The environment supports three pre-configured scenarios:
easy— steady workload for basic stabilitymedium— diurnal workload for proactive scalinghard— flash crowd workload for rapid reaction
Each task file includes:
- workload settings
- server capacity limits
- grading bounds and weights
- maximum episode length
Agent Interface
Agents should use the environment via the following flow:
from app.models import AutoscalerObservation
from agent import AdaptiveAgent
from app.env import AutoscalerEnv
from app.models import TaskConfig
agent = AdaptiveAgent()
# config = load from task YAML or via server
# env = AutoscalerEnv()
# obs = env.reset(config)
# while not done:
# action = agent.act(obs)
# result = env.step(action)
# agent.learn(result.reward, result.info)
# obs = result.observationThe allowed actions are:
-1— scale down0— no change1— scale up
Observation Space
The observation is an AutoscalerObservation object with the following fields:
current_requests(int): Demand at current timestepprevious_requests(int): Demand at previous timestepactive_servers(int): Supply of active serverscpu_utilization(float): Load per server (0.0 to 1.5)queue_length(int): Backlog of requests
Scoring
The grader computes a final score in [0.0, 1.0] using normalized penalties for:
- latency proxy
- server cost
- instability
- SLA violations
The same normalized components are used by the environment reward function, so agents can learn against a consistent objective.
Baseline Scores
The included AdaptiveAgent (rule-based autoscaler) achieves the following scores:
easy: 0.9200medium: 0.8843hard: 0.7224
These scores represent a reasonable starting point for reinforcement learning agents.
Notes
- The cloud simulator uses a 1-step scaling delay: actions taken at step
tapply at stept+1. - Workloads are deterministic for a given task seed, enabling reproducible trials.
License
No license is specified in the repo. Add one if you want to share or publish this project.
