Skip to main content

Module limits

Module limits 

Source
Expand description

Resilience limits: request timeouts, load shedding and connection caps

use std::time::Duration;
use ullun::limits::{ConcurrencyLimit, Timeout};
use ullun::prelude::*;

App::new()
    .header_read_timeout(Duration::from_secs(10))
    .max_connections(10_000)
    .max_connections_per_ip(200)
    .middleware(Timeout::new(Duration::from_secs(15)))
    .middleware(ConcurrencyLimit::new(512))
    .get("/", |_req: Request| async { Ok(Response::text("ok")) })
    .run("127.0.0.1:3000")
    .await
    .unwrap();

Both middlewares cover the time until the handler returns its Response; a streaming body (SSE, downloads) is produced afterwards and is not cut off.

Structsยง

ConcurrencyLimit
Allow at most max requests in flight, answer the rest with 503 and Retry-After
Timeout
Fail requests that run longer than a deadline with 504