vapor-http 0.1.0

A dynamically scaling HTTP server that auto-tunes thread count for 85% CPU utilization
Documentation

Vapor HTTP

A dynamically scaling HTTP server that auto-tunes thread count to maintain 85% CPU utilization per thread.

Features

  • Auto-scaling: Starts at 1 thread, grows as needed up to 256 threads
  • Target utilization: Scales up at >70% CPU usage, scales down at <30%
  • Backpressure: Limits concurrent connections to available threads, preventing FD exhaustion
  • Zero config: Works out of the box with sensible defaults

Quick Start

use std::sync::Arc;
use vapor_http::{Photon, Request, Response};

let handler = |_req: Request| -> Response {
    Response::ok("Hello, World!")
};

vapor_http::Photon::new(Arc::new(handler)).run().await;

Configuration

Custom Port

vapor_http::Photon::new(handler).port(3000).run().await;

Custom Thread Pool

use vapor_http::DynamicThreadPool;

let pool = DynamicThreadPool::with_limits(4, 32);
vapor_http::Photon::new(handler).pool(pool).run().await;

Response Types

Response::ok("text")                    // 200 OK, text/plain
Response::json("{\"key\": \"value\"}")  // 200 OK, application/json
Response::not_found()                   // 404 Not Found
Response::internal_error("msg")         // 500 Internal Server Error
Response::status(418).body("I'm a teapot") // Custom status code
Response::ok("data").with_header("X-Custom", "value")

Request Object

struct Request {
    pub method: String,           // "GET", "POST", etc.
    pub path: String,             // "/api/users"
    pub headers: Vec<(String, String)>,
    pub body: Option<String>,
}

Installation

[dependencies]
vapor-http = "0.1"
tokio = { version = "1", features = ["full"] }
tracing-subscriber = "0.3"

Examples

# Run hello world
cargo run --example hello-world

# Run JSON API
cargo run --example json-api

How Scaling Works

Load          Threads    CPU/Thread
Idle          1          ~0%
Low           1          ~30-50%
Moderate      1          ~70% (scale up trigger)
Heavy         2          ~70-85% each
Very Heavy    4+         ~85% each, scales as needed
  • Scale up: +1 thread when utilization > 70%
  • Scale down: -1 thread when utilization < 30%
  • Cooldown: 100ms between scaling decisions
  • Max threads: 256

License

MIT