Expand description
Resilience limits: request timeouts, load shedding and connection caps
Timeoutanswers 504 when a handler takes too longConcurrencyLimitsheds load with 503 +Retry-Afterinstead of letting work pile up until the process falls overApp::max_connections,App::max_connections_per_ipandApp::header_read_timeoutbound what a single client (or a slowloris) can hold on to
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ยง
- Concurrency
Limit - Allow at most
maxrequests in flight, answer the rest with 503 andRetry-After - Timeout
- Fail requests that run longer than a deadline with 504