diff --git a/frameworks/actix-h2c/Cargo.toml b/frameworks/actix-h2c/Cargo.toml index 73f622c28a..29c96bd46c 100644 --- a/frameworks/actix-h2c/Cargo.toml +++ b/frameworks/actix-h2c/Cargo.toml @@ -5,9 +5,9 @@ edition = "2021" [dependencies] actix-web = { version = "4.13" } +mimalloc = { version = "0.1", default-features = false } serde = { version = "1", features = ["derive"] } serde_json = "1" -num_cpus = "1" futures-util = "0.3" [profile.release] diff --git a/frameworks/actix-h2c/meta.json b/frameworks/actix-h2c/meta.json index 5441457a5b..d763b58d4a 100644 --- a/frameworks/actix-h2c/meta.json +++ b/frameworks/actix-h2c/meta.json @@ -10,7 +10,7 @@ "response": true }, "engine": "actix", - "description": "Actix-web 4 h2c-only listener with TCP_NODELAY enabled on port 8082 using bind_auto_h2c. A middleware rejects HTTP/1.1 requests so the port serves HTTP/2 cleartext prior-knowledge exclusively. Handlers share the same shape as the main actix entry (serde_json per request).", + "description": "Actix-web 4 h2c-only listener with TCP_NODELAY enabled on port 8082 using bind_auto_h2c. A middleware rejects HTTP/1.1 requests so the port serves HTTP/2 cleartext prior-knowledge exclusively. Handlers share the same shape as the main actix entry (serde_json per request). mimalloc as the allocator.", "repo": "https://github.com/actix/actix-web", "enabled": true, "tests": [ diff --git a/frameworks/actix-h2c/src/main.rs b/frameworks/actix-h2c/src/main.rs index 8bbf2b3446..901d720a4e 100644 --- a/frameworks/actix-h2c/src/main.rs +++ b/frameworks/actix-h2c/src/main.rs @@ -1,27 +1,12 @@ -fn cgroup_cpus() -> usize { - std::fs::read_to_string("/sys/fs/cgroup/cpu.max") - .ok() - .and_then(|s| { - let mut parts = s.trim().split(' '); - let quota = parts.next()?; - if quota == "max" { return None; } - let period: usize = parts.next()?.parse().ok()?; - let q: usize = quota.parse().ok()?; - let cpus = q / period; - if cpus >= 1 { Some(cpus) } else { None } - }) - .unwrap_or_else(num_cpus::get) -} - use actix_web::dev::{Service, ServiceRequest, ServiceResponse}; -use actix_web::http::header::{HeaderValue, SERVER}; use actix_web::http::Version; use actix_web::{web, App, HttpResponse, HttpServer}; use futures_util::future::{ready, Either}; use serde::{Deserialize, Serialize}; use std::io; -static SERVER_HDR: HeaderValue = HeaderValue::from_static("actix"); +#[global_allocator] +static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; #[derive(Deserialize)] struct BaselineQuery { @@ -34,13 +19,13 @@ struct JsonQuery { m: Option, } -#[derive(Deserialize, Clone)] +#[derive(Deserialize)] struct Rating { score: i64, count: i64, } -#[derive(Deserialize, Clone)] +#[derive(Deserialize)] struct DatasetItem { id: i64, name: String, @@ -52,47 +37,47 @@ struct DatasetItem { rating: Rating, } -#[derive(Serialize, Clone)] +#[derive(Serialize)] struct RatingOut { score: i64, count: i64, } -#[derive(Serialize, Clone)] -struct ProcessedItem { +// Field order is the wire order: id..rating, then the computed total. +#[derive(Serialize)] +struct ProcessedItem<'a> { id: i64, - name: String, - category: String, + name: &'a str, + category: &'a str, price: i64, quantity: i64, active: bool, - tags: Vec, + tags: &'a [String], rating: RatingOut, total: i64, } #[derive(Serialize)] -struct JsonResponse { - items: Vec, +struct JsonResponse<'a> { + items: Vec>, count: usize, } -struct AppState { - dataset: Vec, -} - -fn build_json_body(dataset: &[DatasetItem], count: usize, m: i64) -> Vec { +// The first `count` items with their totals. Strings and tags are borrowed from +// the dataset: the response is still built and serialized on every request, it +// just does not copy every name, category and tag into it first. +fn build_json(dataset: &[DatasetItem], count: usize, m: i64) -> JsonResponse<'_> { let count = count.min(dataset.len()); - let items: Vec = dataset[..count] + let items = dataset[..count] .iter() .map(|d| ProcessedItem { id: d.id, - name: d.name.clone(), - category: d.category.clone(), + name: &d.name, + category: &d.category, price: d.price, quantity: d.quantity, active: d.active, - tags: d.tags.clone(), + tags: &d.tags, rating: RatingOut { score: d.rating.score, count: d.rating.count, @@ -100,8 +85,7 @@ fn build_json_body(dataset: &[DatasetItem], count: usize, m: i64) -> Vec { total: d.price * d.quantity * m, }) .collect(); - let resp = JsonResponse { count, items }; - serde_json::to_vec(&resp).unwrap_or_default() + JsonResponse { items, count } } fn load_dataset() -> Vec { @@ -115,34 +99,31 @@ fn load_dataset() -> Vec { async fn baseline2(query: web::Query) -> HttpResponse { let sum = query.a.unwrap_or(0) + query.b.unwrap_or(0); HttpResponse::Ok() - .insert_header((SERVER, SERVER_HDR.clone())) .content_type("text/plain") .body(sum.to_string()) } async fn json_endpoint( - state: web::Data, + web::ThinData(dataset): web::ThinData<&'static [DatasetItem]>, path: web::Path, query: web::Query, ) -> HttpResponse { - let count = path.into_inner().min(state.dataset.len()); - let m = query.m.unwrap_or(1); - let body = build_json_body(&state.dataset, count, m); - HttpResponse::Ok() - .insert_header((SERVER, SERVER_HDR.clone())) - .content_type("application/json") - .body(body) + HttpResponse::Ok().json(&build_json( + dataset, + path.into_inner(), + query.m.unwrap_or(1), + )) } #[actix_web::main] async fn main() -> io::Result<()> { - let dataset = load_dataset(); - let state = web::Data::new(AppState { dataset }); - let workers = cgroup_cpus(); + // Leaked once at startup so handlers borrow the items instead of cloning + // every string into each response. + let dataset: &'static [DatasetItem] = Box::leak(load_dataset().into_boxed_slice()); HttpServer::new(move || { App::new() - .app_data(state.clone()) + .app_data(web::ThinData(dataset)) // bind_auto_h2c accepts H1 and h2c on the same socket; this // middleware short-circuits H1 requests with 400 so the port // serves h2c exclusively from the app's perspective. The @@ -161,7 +142,6 @@ async fn main() -> io::Result<()> { .route("/baseline2", web::get().to(baseline2)) .route("/json/{count}", web::get().to(json_endpoint)) }) - .workers(workers) .tcp_nodelay(true) .bind_auto_h2c("0.0.0.0:8082")? .run() diff --git a/frameworks/actix-websocket/Cargo.toml b/frameworks/actix-websocket/Cargo.toml index 7cbd5741cc..6e8fe382ff 100644 --- a/frameworks/actix-websocket/Cargo.toml +++ b/frameworks/actix-websocket/Cargo.toml @@ -6,4 +6,11 @@ edition = "2021" [dependencies] actix-web = "4.13" actix-ws = "0.3" +mimalloc = { version = "0.1", default-features = false } tokio = { version = "1", features = ["macros", "rt-multi-thread"] } + +[profile.release] +opt-level = 3 +codegen-units = 1 +lto = "thin" +panic = "abort" diff --git a/frameworks/actix-websocket/Dockerfile b/frameworks/actix-websocket/Dockerfile index eb8d3b843f..f0d7fcb522 100644 --- a/frameworks/actix-websocket/Dockerfile +++ b/frameworks/actix-websocket/Dockerfile @@ -4,7 +4,8 @@ WORKDIR /app COPY Cargo.toml Cargo.lock* ./ COPY src/ src/ -RUN cargo build --release +# Build on the benchmark host, or a CPU with compatible instruction sets. +RUN RUSTFLAGS="-C target-cpu=native" cargo build --release FROM debian:trixie-slim WORKDIR /app diff --git a/frameworks/actix-websocket/meta.json b/frameworks/actix-websocket/meta.json index 17a3edd31e..2c31e811ff 100644 --- a/frameworks/actix-websocket/meta.json +++ b/frameworks/actix-websocket/meta.json @@ -4,12 +4,13 @@ "type": "flagship", "mode": "standard", "engine": "actix", - "description": "Actix-web WebSocket echo server with TCP_NODELAY enabled", + "description": "Actix-web WebSocket echo server with TCP_NODELAY enabled and mimalloc as the allocator", "repo": "https://github.com/actix/actix-web", "enabled": true, "tests": [ "echo-ws", - "echo-ws-pipeline" + "echo-ws-pipeline", + "echo-ws-limited" ], "maintainers": [] } diff --git a/frameworks/actix-websocket/src/main.rs b/frameworks/actix-websocket/src/main.rs index 6636837c90..579d3b2bcb 100644 --- a/frameworks/actix-websocket/src/main.rs +++ b/frameworks/actix-websocket/src/main.rs @@ -1,6 +1,9 @@ use actix_web::{web, App, HttpServer, HttpRequest, HttpResponse}; use actix_ws; +#[global_allocator] +static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; + async fn ws_handler(req: HttpRequest, body: web::Payload) -> actix_web::Result { let (response, mut session, mut msg_stream) = actix_ws::handle(&req, body)?; actix_web::rt::spawn(async move { diff --git a/frameworks/actix/Cargo.lock b/frameworks/actix/Cargo.lock index e6ba2043c8..9a0ac0b2a3 100644 --- a/frameworks/actix/Cargo.lock +++ b/frameworks/actix/Cargo.lock @@ -261,6 +261,59 @@ dependencies = [ "alloc-no-stdlib", ] +[[package]] +name = "askama" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6024d73179f43f15ccd2b881bfea6fee7f3a46ec53f33b52210dea749ebebaa4" +dependencies = [ + "askama_macros", + "itoa", + "percent-encoding", + "serde", + "serde_json", +] + +[[package]] +name = "askama_derive" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071ee5ebf2138e3ad180e0aacf6940c2cab5e6d8333741d9925c7bee2b153f39" +dependencies = [ + "askama_parser", + "basic-toml", + "glob", + "memchr", + "proc-macro2", + "quote", + "rustc-hash", + "serde", + "serde_derive", + "syn 3.0.4", +] + +[[package]] +name = "askama_macros" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "643e1c7cbb6aec1d920332fe51a7c0d8219e273dcb8602db03f5263e4d16487b" +dependencies = [ + "askama_derive", +] + +[[package]] +name = "askama_parser" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c5ae75772275d268b03ab8bdccdd12117b6169ee23256942b34e46c9f476583" +dependencies = [ + "rustc-hash", + "serde", + "serde_derive", + "unicode-ident", + "winnow", +] + [[package]] name = "async-trait" version = "0.1.92" @@ -278,6 +331,15 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "basic-toml" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba62675e8242a4c4e806d12f11d136e626e6c8361d6b829310732241652a178a" +dependencies = [ + "serde", +] + [[package]] name = "bitflags" version = "2.13.1" @@ -420,12 +482,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "crossbeam-utils" -version = "0.8.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61803da095bee82a81bb1a452ecc25d3b2f1416d1897eb86430c6159ef717c17" - [[package]] name = "crypto-common" version = "0.2.2" @@ -444,20 +500,6 @@ dependencies = [ "cmov", ] -[[package]] -name = "dashmap" -version = "6.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6361d5c062261c78a176addb82d4c821ae42bed6089de0e12603cd25de2059c" -dependencies = [ - "cfg-if", - "crossbeam-utils", - "hashbrown 0.14.5", - "lock_api", - "once_cell", - "parking_lot_core", -] - [[package]] name = "deadpool" version = "0.13.1" @@ -690,6 +732,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "glob" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b" + [[package]] name = "h2" version = "0.3.27" @@ -709,24 +757,12 @@ dependencies = [ "tracing", ] -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hashbrown" version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" -[[package]] -name = "hermit-abi" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" - [[package]] name = "hmac" version = "0.13.0" @@ -760,11 +796,11 @@ dependencies = [ "actix-files", "actix-rt", "actix-web", - "dashmap", + "askama", "deadpool-postgres", "flate2", "futures-util", - "num_cpus", + "mimalloc", "rustls", "rustls-pemfile", "serde", @@ -916,7 +952,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07aa2048142242915a31d35844fb311e0e53fcca590c3a0a40dcf1b841fa09eb" dependencies = [ "equivalent", - "hashbrown 0.17.1", + "hashbrown", ] [[package]] @@ -958,6 +994,15 @@ version = "0.2.189" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" +[[package]] +name = "libmimalloc-sys" +version = "0.1.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a45a52f43e1c16f667ccfe4dd8c85b7f7c204fd5e3bf46c5b0db9a5c3c0b8e9" +dependencies = [ + "cc", +] + [[package]] name = "libredox" version = "0.1.21" @@ -1021,6 +1066,15 @@ version = "2.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" +[[package]] +name = "mimalloc" +version = "0.1.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d4139bb28d14ad1facf21d5eb8825051b326e172d216b39f6d31df53cc97862" +dependencies = [ + "libmimalloc-sys", +] + [[package]] name = "mime" version = "0.3.17" @@ -1065,16 +1119,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "521739c6d2bac4aa25192232afe6841231376b2b26d4d9fae5ecf8ca5772e441" -[[package]] -name = "num_cpus" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91df4bbde75afed763b708b7eee1e8e7651e02d97f6d5dd763e89367e957b23b" -dependencies = [ - "hermit-abi", - "libc", -] - [[package]] name = "objc2-core-foundation" version = "0.3.2" @@ -1304,6 +1348,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rustc-hash" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" + [[package]] name = "rustc_version" version = "0.4.1" @@ -2011,6 +2061,15 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "winnow" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3b93199df0ab874cdf0c6a94f0a0dc3423fe41f1cafb62b8bd7b1deb277aef" +dependencies = [ + "memchr", +] + [[package]] name = "wit-bindgen" version = "0.57.1" diff --git a/frameworks/actix/Cargo.toml b/frameworks/actix/Cargo.toml index 29db3568b4..0ba5c15f62 100644 --- a/frameworks/actix/Cargo.toml +++ b/frameworks/actix/Cargo.toml @@ -8,12 +8,12 @@ actix-web = { version = "4.13", features = ["rustls-0_23", "compress-brotli", "c flate2 = "1" actix-files = "0.7" actix-rt = "2" -dashmap = "6" +askama = "0.16" +mimalloc = { version = "0.1", default-features = false } rustls = { version = "0.23", default-features = false, features = ["ring", "logging", "std", "tls12"] } rustls-pemfile = "2" serde = { version = "1", features = ["derive"] } serde_json = "1" -num_cpus = "1" tokio-postgres = { version = "0.7", features = ["with-serde_json-1"] } deadpool-postgres = { version = "0.14", features = ["rt_tokio_1"] } futures-util = "0.3" diff --git a/frameworks/actix/Dockerfile b/frameworks/actix/Dockerfile index 29fc2486d3..e90d92940d 100644 --- a/frameworks/actix/Dockerfile +++ b/frameworks/actix/Dockerfile @@ -1,11 +1,16 @@ FROM rust:1.94-trixie AS build WORKDIR /app +# Build on the benchmark host, or a CPU with compatible instruction sets. +ENV RUSTFLAGS="-C target-cpu=native" COPY Cargo.toml Cargo.lock ./ -RUN mkdir src && echo "fn main() {}" > src/main.rs && cargo build --release --locked && rm -rf src/ target/release/httparena-actix* target/release/deps/httparena_actix* +RUN mkdir src && echo "fn main() {}" > src/main.rs && cargo build --release --locked \ + && cargo clean --release -p httparena-actix && rm src/main.rs COPY src ./src -RUN RUSTFLAGS="-C target-cpu=native" cargo build --release --locked +COPY askama.toml ./ +COPY templates ./templates +RUN cargo build --release --locked FROM debian:trixie-slim COPY --from=build /app/target/release/httparena-actix /server -EXPOSE 8080 +EXPOSE 8080 8081 8443 CMD ["/server"] diff --git a/frameworks/actix/README.md b/frameworks/actix/README.md index 6dfa35b121..1b6e638028 100644 --- a/frameworks/actix/README.md +++ b/frameworks/actix/README.md @@ -4,28 +4,66 @@ Actix-web 4 HTTP server with rustls for TLS/HTTP/2 support, compiled with thin L ## Stack -- **Language:** Rust 1.88 +- **Language:** Rust 1.94 - **Framework:** Actix-web 4 - **TLS:** rustls +- **Allocator:** mimalloc - **Build:** Multi-stage, `debian:trixie-slim` runtime ## Endpoints | Endpoint | Method | Description | |----------|--------|-------------| -| `/pipeline` | GET | Returns `ok` (plain text) | | `/baseline11` | GET | Sums query parameter values | | `/baseline11` | POST | Sums query parameters + request body | | `/baseline2` | GET | Sums query parameter values (HTTP/2 variant) | -| `/json` | GET | Processes 50-item dataset, serializes JSON | -| `/compression` | GET | Gzip-compressed large JSON response | -| `/db` | GET | SQLite range query with JSON response | +| `/pipeline` | GET | Returns `ok` (plain text) | +| `/delay/{ms}` | GET | Asynchronously waits `ms` milliseconds and returns the delay | +| `/json/{count}?m=N` | GET | First `count` dataset items with `total = price * quantity * m` | | `/echo` | POST | Returns the request body back verbatim | -| `/static/{filename}` | GET | Serves preloaded static files with MIME types | +| `/static/{name}` | GET | Serves `/data/static/{name}` from disk, preferring a `.br`/`.gz` sibling | +| `/async-db?min=&max=&limit=` | GET | Items with `price` in range from Postgres, up to `limit` (1-50) | +| `/fortunes` | GET | Fortune rows from Postgres plus a runtime row, sorted and rendered as HTML | + +The same routes are served over TLS on port 8081 (`json-tls`, `static-tls`, +`8gbit`) and on port 8443 (`baseline-h2`, `static-h2`). The h2c profiles are +served by the `actix-h2c` entry and WebSocket by `actix-websocket`. ## Notes -- Per-worker SQLite connections via thread-local storage -- Backlog set to 4096 for connection queuing -- Static files preloaded into memory at startup -- Gzip compression level 1 +- Default worker count (one per CPU the container may use) and HTTP settings, + with `TCP_NODELAY` enabled +- Routing and extraction through `web::resource`/`App::route` and the `Query`, + `Path`, `Bytes` and `Payload` extractors +- The dataset is loaded once and leaked, so responses borrow its strings + instead of cloning them; the JSON body is still built and serialized with + serde_json on every request +- json-comp: gzip at level 1 is driven in the handler. Actix-web's encoder + compresses in place only below 1 KiB and sends everything larger through + `spawn_blocking`, and every body on this profile is 2-6 KB. The `Compress` + middleware wraps this one route and serves any other encoding the client + asks for; it leaves the gzip response alone because it already carries a + `Content-Encoding` +- No other route is wrapped in `Compress`. Wrapped around the whole app it + compressed the static files that have no pre-compressed sibling on every + request +- Static files are opened per request through `actix_files::Files`, so a + replaced file is served immediately. `try_compressed()` picks the `.br`/`.gz` + sibling the client accepts +- `/async-db` uses tokio-postgres behind deadpool-postgres. Every worker is a + single-threaded runtime, so each one keeps its own pool of + `DATABASE_MAX_CONN / workers` connections (default 256 in total) and a query + never leaves the thread serving its request. Statements are prepared once + per connection through `prepare_cached`. Without `DATABASE_URL`, or when the + pool or the query fails, the endpoint returns `500 Internal Server Error` +- `/fortunes` runs `SELECT id, message FROM fortune`, appends the runtime row, + sorts by message in byte order and renders the Askama template + `templates/fortunes.html`. `askama.toml` registers an escaper that writes + named entities (`<`) instead of Askama's numeric ones. Database errors + return `500` +- Both TLS listeners use the mounted certificate through rustls with ring. + Actix-web offers `h2` and `http/1.1` by ALPN on every rustls listener; the + client picks +- A missing `/certs` leaves the TLS listeners down instead of aborting startup +- Docker release builds use `target-cpu=native` and ThinLTO, together with the + manifest's `opt-level=3` and `codegen-units=1` diff --git a/frameworks/actix/askama.toml b/frameworks/actix/askama.toml new file mode 100644 index 0000000000..d587eb98ca --- /dev/null +++ b/frameworks/actix/askama.toml @@ -0,0 +1,3 @@ +[[escaper]] +path = "crate::fortunes::NamedHtml" +extensions = ["html"] diff --git a/frameworks/actix/meta.json b/frameworks/actix/meta.json index 21a3493c75..a82e0ed448 100644 --- a/frameworks/actix/meta.json +++ b/frameworks/actix/meta.json @@ -10,14 +10,15 @@ "response": true }, "engine": "actix", - "description": "Actix-web 4 with rustls for TLS. Standard configuration with TCP_NODELAY enabled: actix-files serves static content from disk per request via try_compressed(), which selects a pre-compressed .br/.gz sibling by Accept-Encoding through the framework API (no hand-rolled suffix lookup); the Compress middleware compresses dynamic responses (json-comp) on-the-fly. deadpool-postgres for async DB pooling (sized from DATABASE_MAX_CONN); crud reads go through an in-memory cache-aside (X-Cache MISS/HIT, invalidated on update \u2014 no Redis required). json-tls is served over HTTP/1.1-with-TLS on :8081; baseline-h2/static-h2 over h2 on :8443. serde_json per request. Compiled with -O3 and thin LTO.", + "description": "Actix-web 4 with rustls for TLS and mimalloc as the allocator. Default worker count, TCP_NODELAY enabled. actix-files serves static content from disk per request via try_compressed(), which selects a pre-compressed .br/.gz sibling by Accept-Encoding through the framework API (no hand-rolled suffix lookup). JSON is serialized per request with serde_json; on json-comp gzip (level 1) is driven in the handler, because actix-web's encoder sends every body over 1 KiB through the blocking pool, and the Compress middleware on that route serves any other encoding. async-db through a deadpool-postgres pool per worker (DATABASE_MAX_CONN split between the workers). fortunes rendered through an Askama template. json-tls and static-tls are served over HTTP/1.1-with-TLS on :8081; baseline-h2/static-h2 over h2 on :8443. Compiled with -O3 and thin LTO.", "repo": "https://github.com/actix/actix-web", "enabled": true, "tests": [ "baseline", "async", "latency-1m", - "latency-10k", "latency-500k-8cpu", + "latency-10k", + "latency-500k-8cpu", "pipelined", "limited-conn", "json-comp", @@ -25,6 +26,7 @@ "8gbit", "static-tls", "async-db", + "fortunes", "baseline-h2", "static-h2" ], diff --git a/frameworks/actix/src/db.rs b/frameworks/actix/src/db.rs new file mode 100644 index 0000000000..d496aba559 --- /dev/null +++ b/frameworks/actix/src/db.rs @@ -0,0 +1,148 @@ +//! `/async-db` and the `/fortunes` query: tokio-postgres behind a +//! deadpool-postgres pool, one pool per worker. + +use std::cell::OnceCell; +use std::sync::OnceLock; + +use actix_web::{web, HttpResponse}; +use deadpool_postgres::{Manager, ManagerConfig, Pool, RecyclingMethod}; +use serde::{Deserialize, Serialize}; +use tokio_postgres::{NoTls, Row}; + +const QUERY: &str = "SELECT id, name, category, price, quantity, active, tags, rating_score, \ + rating_count FROM items WHERE price BETWEEN $1 AND $2 LIMIT $3"; +const FORTUNES: &str = "SELECT id, message FROM fortune"; + +/// Workers sharing `DATABASE_MAX_CONN`, recorded by `main` before they start. +static WORKERS: OnceLock = OnceLock::new(); + +thread_local! { + // The app factory runs once per listener on every worker, so the pool is + // kept per thread: the three listeners of a worker share one pool. + static POOL: OnceCell> = const { OnceCell::new() }; +} + +#[derive(Deserialize)] +pub struct PriceQuery { + min: Option, + max: Option, + limit: Option, +} + +#[derive(Serialize)] +struct DbRating { + score: i32, + count: i32, +} + +#[derive(Serialize)] +struct DbItem<'a> { + id: i32, + name: &'a str, + category: &'a str, + price: i32, + quantity: i32, + active: bool, + tags: serde_json::Value, + rating: DbRating, +} + +#[derive(Serialize)] +struct DbList<'a> { + items: Vec>, + count: usize, +} + +/// Records how many workers split `DATABASE_MAX_CONN` between their pools. +pub fn set_workers(workers: usize) { + let _ = WORKERS.set(workers.max(1)); +} + +/// The calling worker's pool, or `None` when `DATABASE_URL` is unset or invalid. +/// +/// Every actix-web worker is a single-threaded runtime of its own. A pool +/// shared by all of them hands a worker connections whose socket is driven +/// from whichever worker happened to open it, so each query crosses threads +/// on the way out and again on the way back. With a pool per worker a query +/// never leaves the thread that serves its request. +/// +/// Each pool holds its worker's share of `DATABASE_MAX_CONN`, so together +/// they stay within what Postgres accepts. Connections open on first use. +pub fn worker_pool() -> Option { + POOL.with(|pool| pool.get_or_init(open).clone()) +} + +fn open() -> Option { + let config: tokio_postgres::Config = std::env::var("DATABASE_URL").ok()?.parse().ok()?; + let max_conn = std::env::var("DATABASE_MAX_CONN") + .ok() + .and_then(|v| v.parse::().ok()) + .unwrap_or(256); + let workers = WORKERS.get().copied().unwrap_or(1); + let manager = Manager::from_config( + config, + NoTls, + ManagerConfig { + recycling_method: RecyclingMethod::Fast, + }, + ); + Pool::builder(manager) + .max_size((max_conn / workers).max(1)) + .build() + .ok() +} + +/// Runs `sql` as a cached prepared statement on a pooled connection. `None` +/// without a pool or on any database error. +async fn query( + pool: &Option, + sql: &str, + params: &[&(dyn tokio_postgres::types::ToSql + Sync)], +) -> Option> { + let client = pool.as_ref()?.get().await.ok()?; + let statement = client.prepare_cached(sql).await.ok()?; + client.query(&statement, params).await.ok() +} + +fn item(row: &Row) -> DbItem<'_> { + DbItem { + id: row.get(0), + name: row.get(1), + category: row.get(2), + price: row.get(3), + quantity: row.get(4), + active: row.get(5), + tags: row.get(6), + rating: DbRating { + score: row.get(7), + count: row.get(8), + }, + } +} + +/// All `fortune` rows as `(id, message)`, or `None` without a database or on +/// a database error. +pub async fn fortunes(pool: &Option) -> Option> { + query(pool, FORTUNES, &[]).await +} + +/// Items in the requested price range. Without a database or on a database +/// error the answer is `500`, so a failed query is counted as one instead of +/// passing for an empty result. +pub async fn async_db( + params: web::Query, + pool: web::Data>, +) -> HttpResponse { + let min = params.min.unwrap_or(10); + let max = params.max.unwrap_or(50); + let limit = i64::from(params.limit.unwrap_or(50).clamp(1, 50)); + + let Some(rows) = query(&pool, QUERY, &[&min, &max, &limit]).await else { + return HttpResponse::InternalServerError().finish(); + }; + let items: Vec<_> = rows.iter().map(item).collect(); + HttpResponse::Ok().json(&DbList { + count: items.len(), + items, + }) +} diff --git a/frameworks/actix/src/fortunes.rs b/frameworks/actix/src/fortunes.rs new file mode 100644 index 0000000000..e109d7e916 --- /dev/null +++ b/frameworks/actix/src/fortunes.rs @@ -0,0 +1,90 @@ +//! `/fortunes`: rows from Postgres plus one added at request time, sorted by +//! message and rendered through the Askama template `templates/fortunes.html`. + +use std::fmt; + +use actix_web::{web, HttpResponse}; +use askama::{filters::Escaper, Template}; +use deadpool_postgres::Pool; + +use crate::db; + +/// The row every request appends to the database rows before sorting. +const RUNTIME_MESSAGE: &str = "Additional fortune added at request time."; +/// Room for the rendered 201-row page, so rendering never reallocates. +const PAGE_CAPACITY: usize = 32 * 1024; + +/// HTML escaper for `.html` templates, registered in `askama.toml`. +/// +/// Askama's built-in escaper writes numeric entities (`<`), while the +/// validator looks for the named `<script>`. +#[derive(Copy, Clone)] +pub struct NamedHtml; + +impl Escaper for NamedHtml { + fn write_escaped_str(&self, mut dest: W, s: &str) -> fmt::Result { + let mut last = 0; + for (i, b) in s.bytes().enumerate() { + let entity = match b { + b'<' => "<", + b'>' => ">", + b'&' => "&", + b'"' => """, + b'\'' => "'", + _ => continue, + }; + dest.write_str(&s[last..i])?; + dest.write_str(entity)?; + last = i + 1; + } + dest.write_str(&s[last..]) + } +} + +pub struct Fortune<'a> { + pub id: i32, + pub message: &'a str, +} + +#[derive(Template)] +#[template(path = "fortunes.html")] +struct FortunesTemplate<'a> { + fortunes: &'a [Fortune<'a>], +} + +/// Appends the runtime row, sorts by message in byte order and renders the +/// page; messages are HTML-escaped by the template. +fn render(mut fortunes: Vec>) -> HttpResponse { + fortunes.push(Fortune { + id: 0, + message: RUNTIME_MESSAGE, + }); + fortunes.sort_unstable_by(|a, b| a.message.cmp(b.message)); + + let mut page = String::with_capacity(PAGE_CAPACITY); + match (FortunesTemplate { + fortunes: &fortunes, + }) + .render_into(&mut page) + { + Ok(()) => HttpResponse::Ok() + .content_type("text/html; charset=utf-8") + .body(page), + Err(_) => HttpResponse::InternalServerError().finish(), + } +} + +/// The rendered page, or `500` without a database or on a database error. +pub async fn fortunes(pool: web::Data>) -> HttpResponse { + let Some(rows) = db::fortunes(&pool).await else { + return HttpResponse::InternalServerError().finish(); + }; + render( + rows.iter() + .map(|row| Fortune { + id: row.get(0), + message: row.get(1), + }) + .collect(), + ) +} diff --git a/frameworks/actix/src/main.rs b/frameworks/actix/src/main.rs index fe51bc8915..b4a352c1b4 100644 --- a/frameworks/actix/src/main.rs +++ b/frameworks/actix/src/main.rs @@ -1,35 +1,20 @@ -fn cgroup_cpus() -> usize { - std::fs::read_to_string("/sys/fs/cgroup/cpu.max") - .ok() - .and_then(|s| { - let mut parts = s.trim().split(' '); - let quota = parts.next()?; - if quota == "max" { return None; } - let period: usize = parts.next()?.parse().ok()?; - let q: usize = quota.parse().ok()?; - let cpus = q / period; - if cpus >= 1 { Some(cpus) } else { None } - }) - .unwrap_or_else(num_cpus::get) -} - use actix_files::Files; -use actix_web::http::header; -use actix_web::http::header::{ContentType, HeaderValue, SERVER}; +use actix_web::http::header::{self, ContentType}; use actix_web::middleware::Compress; use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer}; -use dashmap::DashMap; -use deadpool_postgres::{Manager, ManagerConfig, Pool as PgPool, RecyclingMethod}; use futures_util::StreamExt; use rustls::ServerConfig; use serde::{Deserialize, Serialize}; use std::io; -static SERVER_HDR: HeaderValue = HeaderValue::from_static("actix"); +mod db; +mod fortunes; -// In-memory cache-aside store for the crud read path: item id -> rendered JSON -// body. Populated on GET miss, invalidated on update. No Redis required. -type CrudCache = DashMap>; +#[global_allocator] +static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; + +/// The dataset, loaded once and leaked, so every worker borrows the same items. +type Dataset = web::ThinData<&'static [DatasetItem]>; #[derive(Deserialize)] struct BaselineQuery { @@ -37,26 +22,18 @@ struct BaselineQuery { b: Option, } -// Shared query struct for both DB endpoints — replaces manual query string parsing -#[derive(Deserialize)] -struct PriceQuery { - min: Option, - max: Option, - limit: Option, -} - #[derive(Deserialize)] struct JsonQuery { m: Option, } -#[derive(Deserialize, Clone)] +#[derive(Deserialize)] struct Rating { score: i64, count: i64, } -#[derive(Deserialize, Clone)] +#[derive(Deserialize)] struct DatasetItem { id: i64, name: String, @@ -68,72 +45,47 @@ struct DatasetItem { rating: Rating, } -#[derive(Serialize, Clone)] +#[derive(Serialize)] struct RatingOut { score: i64, count: i64, } -#[derive(Serialize, Clone)] -struct ProcessedItem { +// Field order is the wire order: id..rating, then the computed total. +#[derive(Serialize)] +struct ProcessedItem<'a> { id: i64, - name: String, - category: String, + name: &'a str, + category: &'a str, price: i64, quantity: i64, active: bool, - tags: Vec, + tags: &'a [String], rating: RatingOut, total: i64, } #[derive(Serialize)] -struct JsonResponse { - items: Vec, +struct JsonResponse<'a> { + items: Vec>, count: usize, } -// CRUD request bodies / query. -#[derive(Deserialize)] -struct CrudListQuery { - category: Option, - page: Option, - limit: Option, -} - -#[derive(Deserialize)] -struct CrudCreate { - id: i64, - name: String, - category: String, - price: i32, - quantity: i32, -} - -#[derive(Deserialize)] -struct CrudUpdate { - name: String, - category: String, - price: i32, - quantity: i32, -} - -struct AppState { - dataset: Vec, -} - -fn build_json_body(dataset: &[DatasetItem], count: usize, m: i64) -> Vec { +// The first `count` items with their totals. Strings and tags are borrowed from +// the dataset: the response is still built and serialized on every request, it +// just does not copy every name, category and tag into it first. +fn build_json(dataset: &[DatasetItem], count: usize, m: i64) -> JsonResponse<'_> { let count = count.min(dataset.len()); - let items: Vec = dataset[..count] + let items = dataset[..count] .iter() .map(|d| ProcessedItem { id: d.id, - name: d.name.clone(), - category: d.category.clone(), + name: &d.name, + category: &d.category, price: d.price, quantity: d.quantity, active: d.active, - tags: d.tags.clone(), + tags: &d.tags, rating: RatingOut { score: d.rating.score, count: d.rating.count, @@ -141,8 +93,7 @@ fn build_json_body(dataset: &[DatasetItem], count: usize, m: i64) -> Vec { total: d.price * d.quantity * m, }) .collect(); - let resp = JsonResponse { count, items }; - serde_json::to_vec(&resp).unwrap_or_default() + JsonResponse { items, count } } fn load_dataset() -> Vec { @@ -162,23 +113,18 @@ async fn delay(path: web::Path) -> HttpResponse { actix_web::rt::time::sleep(std::time::Duration::from_millis(ms)).await; } HttpResponse::Ok() - .insert_header((SERVER, SERVER_HDR.clone())) - .content_type(ContentType::plaintext()) + .content_type("text/plain") .body(ms.to_string()) } async fn pipeline() -> HttpResponse { - HttpResponse::Ok() - .insert_header((SERVER, SERVER_HDR.clone())) - .content_type(ContentType::plaintext()) - .body("ok") + HttpResponse::Ok().content_type("text/plain").body("ok") } async fn baseline11_get(query: web::Query) -> HttpResponse { let sum = query.a.unwrap_or(0) + query.b.unwrap_or(0); HttpResponse::Ok() - .insert_header((SERVER, SERVER_HDR.clone())) - .content_type(ContentType::plaintext()) + .content_type("text/plain") .body(sum.to_string()) } @@ -190,16 +136,14 @@ async fn baseline11_post(query: web::Query, body: web::Bytes) -> } } HttpResponse::Ok() - .insert_header((SERVER, SERVER_HDR.clone())) - .content_type(ContentType::plaintext()) + .content_type("text/plain") .body(sum.to_string()) } async fn baseline2(query: web::Query) -> HttpResponse { let sum = query.a.unwrap_or(0) + query.b.unwrap_or(0); HttpResponse::Ok() - .insert_header((SERVER, SERVER_HDR.clone())) - .content_type(ContentType::plaintext()) + .content_type("text/plain") .body(sum.to_string()) } @@ -216,7 +160,6 @@ async fn echo_body(mut payload: web::Payload) -> HttpResponse { } } HttpResponse::Ok() - .insert_header((SERVER, SERVER_HDR.clone())) .content_type(ContentType::octet_stream()) .body(body.freeze()) } @@ -234,19 +177,17 @@ async fn echo_body(mut payload: web::Payload) -> HttpResponse { // (`flate2::Compression::fast()`), so the bytes on the wire are unchanged; only // the thread they are produced on is. // -// The Compress middleware stays wrapped on the App and skips this response, -// because it already carries a Content-Encoding. +// The Compress middleware stays wrapped on this resource and skips the gzip +// response, because it already carries a Content-Encoding. async fn json_endpoint( - state: web::Data, + web::ThinData(dataset): Dataset, req: HttpRequest, path: web::Path, query: web::Query, ) -> HttpResponse { use std::io::Write as _; - let count = path.into_inner().min(state.dataset.len()); - let m = query.m.unwrap_or(1); - let body = build_json_body(&state.dataset, count, m); + let list = build_json(dataset, path.into_inner(), query.m.unwrap_or(1)); let accepts_gzip = req .headers() @@ -255,280 +196,21 @@ async fn json_endpoint( .is_some_and(|v| v.contains("gzip")); if accepts_gzip { - let mut enc = flate2::write::GzEncoder::new(Vec::new(), flate2::Compression::new(1)); - if enc.write_all(&body).is_ok() { - if let Ok(compressed) = enc.finish() { - return HttpResponse::Ok() - .insert_header((SERVER, SERVER_HDR.clone())) - .insert_header((header::CONTENT_ENCODING, "gzip")) - .insert_header((header::VARY, "Accept-Encoding")) - .content_type(ContentType::json()) - .body(compressed); + if let Ok(body) = serde_json::to_vec(&list) { + let mut enc = flate2::write::GzEncoder::new(Vec::new(), flate2::Compression::new(1)); + if enc.write_all(&body).is_ok() { + if let Ok(compressed) = enc.finish() { + return HttpResponse::Ok() + .insert_header((header::CONTENT_ENCODING, "gzip")) + .insert_header((header::VARY, "Accept-Encoding")) + .content_type(ContentType::json()) + .body(compressed); + } } } } - HttpResponse::Ok() - .insert_header((SERVER, SERVER_HDR.clone())) - .content_type(ContentType::json()) - .body(body) -} - -async fn pgdb_endpoint( - query: web::Query, - pool: web::Data>, -) -> HttpResponse { - let pool = match pool.as_ref() { - Some(p) => p, - None => { - return HttpResponse::Ok() - .insert_header((SERVER, SERVER_HDR.clone())) - .content_type(ContentType::json()) - .body(r#"{"items":[],"count":0}"#); - } - }; - let min: i32 = query.min.unwrap_or(10); - let max: i32 = query.max.unwrap_or(50); - let limit: i64 = query.limit.unwrap_or(50).clamp(1, 50) as i64; - - let client = match pool.get().await { - Ok(c) => c, - Err(_) => { - return HttpResponse::Ok() - .insert_header((SERVER, SERVER_HDR.clone())) - .content_type(ContentType::json()) - .body(r#"{"items":[],"count":0}"#); - } - }; - let stmt = client - .prepare_cached( - "SELECT id, name, category, price, quantity, active, tags, rating_score, rating_count \ - FROM items WHERE price BETWEEN $1 AND $2 LIMIT $3", - ) - .await - .unwrap(); - let rows = match client.query(&stmt, &[&min, &max, &limit]).await { - Ok(r) => r, - Err(_) => { - return HttpResponse::Ok() - .insert_header((SERVER, SERVER_HDR.clone())) - .content_type(ContentType::json()) - .body(r#"{"items":[],"count":0}"#); - } - }; - let items: Vec = rows.iter().map(row_to_item).collect(); - let result = serde_json::json!({"items": items, "count": items.len()}); - HttpResponse::Ok() - .insert_header((SERVER, SERVER_HDR.clone())) - .content_type(ContentType::json()) - .body(result.to_string()) -} - -// ───── CRUD (/crud/items) ───── -// -// List + read + create + update over the same `items` table the async-db -// endpoint uses. Reads go through an in-memory cache-aside (X-Cache MISS/HIT), -// invalidated on update — no Redis required. - -const CRUD_COLS: &str = - "id, name, category, price, quantity, active, tags, rating_score, rating_count"; - -fn row_to_item(row: &tokio_postgres::Row) -> serde_json::Value { - serde_json::json!({ - "id": row.get::<_, i32>(0) as i64, - "name": row.get::<_, &str>(1), - "category": row.get::<_, &str>(2), - "price": row.get::<_, i32>(3), - "quantity": row.get::<_, i32>(4), - "active": row.get::<_, bool>(5), - "tags": row.get::<_, serde_json::Value>(6), - "rating": { - "score": row.get::<_, i32>(7), - "count": row.get::<_, i32>(8) as i64, - } - }) -} - -fn json_body(body: Vec) -> HttpResponse { - HttpResponse::Ok() - .insert_header((SERVER, SERVER_HDR.clone())) - .content_type(ContentType::json()) - .body(body) -} - -async fn crud_list( - query: web::Query, - pool: web::Data>, -) -> HttpResponse { - let pool = match pool.as_ref() { - Some(p) => p, - None => return json_body(br#"{"items":[],"total":0,"page":1}"#.to_vec()), - }; - let category = query.category.clone().unwrap_or_default(); - let page = query.page.unwrap_or(1).max(1); - let limit = query.limit.unwrap_or(20).clamp(1, 100); - let offset = (page - 1) * limit; - - let client = match pool.get().await { - Ok(c) => c, - Err(_) => return HttpResponse::ServiceUnavailable().finish(), - }; - let list_sql = - format!("SELECT {CRUD_COLS} FROM items WHERE category = $1 ORDER BY id LIMIT $2 OFFSET $3"); - let stmt = match client.prepare_cached(&list_sql).await { - Ok(s) => s, - Err(_) => return HttpResponse::InternalServerError().finish(), - }; - let rows = match client.query(&stmt, &[&category, &limit, &offset]).await { - Ok(r) => r, - Err(_) => return HttpResponse::InternalServerError().finish(), - }; - let items: Vec = rows.iter().map(row_to_item).collect(); - - let count_stmt = match client - .prepare_cached("SELECT COUNT(*) FROM items WHERE category = $1") - .await - { - Ok(s) => s, - Err(_) => return HttpResponse::InternalServerError().finish(), - }; - let total: i64 = client - .query_one(&count_stmt, &[&category]) - .await - .map(|r| r.get::<_, i64>(0)) - .unwrap_or(0); - - let body = serde_json::json!({ "items": items, "total": total, "page": page }); - json_body(body.to_string().into_bytes()) -} - -async fn crud_get( - id: web::Path, - pool: web::Data>, - cache: web::Data, -) -> HttpResponse { - let id = id.into_inner(); - if let Some(cached) = cache.get(&id) { - return HttpResponse::Ok() - .insert_header((SERVER, SERVER_HDR.clone())) - .insert_header(("X-Cache", "HIT")) - .content_type(ContentType::json()) - .body(cached.value().clone()); - } - let pool = match pool.as_ref() { - Some(p) => p, - None => return HttpResponse::ServiceUnavailable().finish(), - }; - let client = match pool.get().await { - Ok(c) => c, - Err(_) => return HttpResponse::ServiceUnavailable().finish(), - }; - let sql = format!("SELECT {CRUD_COLS} FROM items WHERE id = $1"); - let stmt = match client.prepare_cached(&sql).await { - Ok(s) => s, - Err(_) => return HttpResponse::InternalServerError().finish(), - }; - match client.query_opt(&stmt, &[&(id as i32)]).await { - Ok(Some(row)) => { - let body = row_to_item(&row).to_string().into_bytes(); - cache.insert(id, body.clone()); - HttpResponse::Ok() - .insert_header((SERVER, SERVER_HDR.clone())) - .insert_header(("X-Cache", "MISS")) - .content_type(ContentType::json()) - .body(body) - } - Ok(None) => HttpResponse::NotFound() - .insert_header((SERVER, SERVER_HDR.clone())) - .finish(), - Err(_) => HttpResponse::InternalServerError().finish(), - } -} - -async fn crud_create( - item: web::Json, - pool: web::Data>, - cache: web::Data, -) -> HttpResponse { - let pool = match pool.as_ref() { - Some(p) => p, - None => return HttpResponse::ServiceUnavailable().finish(), - }; - let client = match pool.get().await { - Ok(c) => c, - Err(_) => return HttpResponse::ServiceUnavailable().finish(), - }; - let stmt = match client - .prepare_cached( - "INSERT INTO items (id, name, category, price, quantity, active, tags, rating_score, rating_count) \ - VALUES ($1, $2, $3, $4, $5, false, '[]'::jsonb, 0, 0) \ - ON CONFLICT (id) DO UPDATE SET name = EXCLUDED.name, category = EXCLUDED.category, \ - price = EXCLUDED.price, quantity = EXCLUDED.quantity", - ) - .await - { - Ok(s) => s, - Err(_) => return HttpResponse::InternalServerError().finish(), - }; - match client - .execute( - &stmt, - &[&(item.id as i32), &item.name, &item.category, &item.price, &item.quantity], - ) - .await - { - Ok(_) => { - cache.remove(&item.id); - HttpResponse::Created() - .insert_header((SERVER, SERVER_HDR.clone())) - .finish() - } - Err(_) => HttpResponse::InternalServerError().finish(), - } -} - -async fn crud_update( - id: web::Path, - item: web::Json, - pool: web::Data>, - cache: web::Data, -) -> HttpResponse { - let id = id.into_inner(); - let pool = match pool.as_ref() { - Some(p) => p, - None => return HttpResponse::ServiceUnavailable().finish(), - }; - let client = match pool.get().await { - Ok(c) => c, - Err(_) => return HttpResponse::ServiceUnavailable().finish(), - }; - let stmt = match client - .prepare_cached( - "UPDATE items SET name = $2, category = $3, price = $4, quantity = $5 WHERE id = $1", - ) - .await - { - Ok(s) => s, - Err(_) => return HttpResponse::InternalServerError().finish(), - }; - let updated = client - .execute( - &stmt, - &[&(id as i32), &item.name, &item.category, &item.price, &item.quantity], - ) - .await - .unwrap_or(0); - // Invalidate the cached read so the next GET re-fetches from the DB (X-Cache: MISS). - cache.remove(&id); - if updated > 0 { - HttpResponse::Ok() - .insert_header((SERVER, SERVER_HDR.clone())) - .finish() - } else { - HttpResponse::NotFound() - .insert_header((SERVER, SERVER_HDR.clone())) - .finish() - } + HttpResponse::Ok().json(&list) } fn load_tls_config() -> Option { @@ -552,64 +234,47 @@ fn load_tls_config() -> Option { #[actix_web::main] async fn main() -> io::Result<()> { - let dataset = load_dataset(); - let state = web::Data::new(AppState { dataset }); - let crud_cache: web::Data = web::Data::new(DashMap::new()); - - let pg_pool: Option = std::env::var("DATABASE_URL").ok().and_then(|url| { - let pg_config: tokio_postgres::Config = url.parse().ok()?; - let mgr = Manager::from_config( - pg_config, - deadpool_postgres::tokio_postgres::NoTls, - ManagerConfig { - recycling_method: RecyclingMethod::Fast, - }, - ); - let pool_size: usize = std::env::var("DATABASE_MAX_CONN") - .ok() - .and_then(|s| s.parse().ok()) - .unwrap_or(256); - PgPool::builder(mgr).max_size(pool_size).build().ok() - }); - - let workers = cgroup_cpus(); - - let mut server = HttpServer::new({ - let state = state.clone(); - let pg_pool = pg_pool.clone(); - let crud_cache = crud_cache.clone(); - move || { - App::new() - // Compress middleware performs on-the-fly response compression - // based on the request's Accept-Encoding. Framework-standard — - // no handmade gzip/brotli. It skips responses that already carry - // a Content-Encoding (i.e. the pre-compressed static files below). - .wrap(Compress::default()) - .app_data(state.clone()) - .app_data(web::PayloadConfig::new(25 * 1024 * 1024)) - .app_data(web::Data::new(pg_pool.clone())) - .app_data(crud_cache.clone()) - .route("/pipeline", web::get().to(pipeline)) - .route("/delay/{ms}", web::get().to(delay)) - .route("/baseline11", web::get().to(baseline11_get)) - .route("/baseline11", web::post().to(baseline11_post)) - .route("/baseline2", web::get().to(baseline2)) - .route("/echo", web::post().to(echo_body)) - .route("/async-db", web::get().to(pgdb_endpoint)) - .route("/json/{count}", web::get().to(json_endpoint)) - .route("/crud/items", web::get().to(crud_list)) - .route("/crud/items", web::post().to(crud_create)) - .route("/crud/items/{id}", web::get().to(crud_get)) - .route("/crud/items/{id}", web::put().to(crud_update)) - // actix-files serves from disk per request. `try_compressed()` - // selects a pre-compressed .br/.gz sibling by Accept-Encoding - // (framework API — no hand-rolled suffix lookup), falling back to - // the identity file when no variant exists. Reading per request - // keeps it freshness-compliant (no permanent in-memory cache). - .service( - Files::new("/static", "/data/static").try_compressed(), - ) - } + // Leaked once at startup so handlers borrow the items instead of cloning + // every string into each response. + let dataset: &'static [DatasetItem] = Box::leak(load_dataset().into_boxed_slice()); + + // One worker per CPU the container may use, which is also actix-web's + // default. Taken here so the workers can split DATABASE_MAX_CONN evenly. + let workers = std::thread::available_parallelism().map_or(1, |n| n.get()); + db::set_workers(workers); + + let mut server = HttpServer::new(move || { + App::new() + .app_data(web::ThinData(dataset)) + .app_data(web::PayloadConfig::new(25 * 1024 * 1024)) + // This worker's own pool: see db.rs. + .app_data(web::Data::new(db::worker_pool())) + .service( + web::resource("/baseline11") + .route(web::get().to(baseline11_get)) + .route(web::post().to(baseline11_post)), + ) + .route("/baseline2", web::get().to(baseline2)) + .route("/pipeline", web::get().to(pipeline)) + .route("/echo", web::post().to(echo_body)) + .route("/async-db", web::get().to(db::async_db)) + .route("/fortunes", web::get().to(fortunes::fortunes)) + .route("/delay/{ms}", web::get().to(delay)) + // The Compress middleware wraps only the route whose profile asks + // for on-the-fly compression (json-comp). Around the whole app it + // also compressed every static file that has no pre-compressed + // sibling: the two .woff2 fonts went through brotli on each request. + .service( + web::resource("/json/{count}") + .wrap(Compress::default()) + .route(web::get().to(json_endpoint)), + ) + // actix-files serves from disk per request. `try_compressed()` + // selects a pre-compressed .br/.gz sibling by Accept-Encoding + // (framework API — no hand-rolled suffix lookup), falling back to + // the identity file when no variant exists. Reading per request + // keeps it freshness-compliant (no permanent in-memory cache). + .service(Files::new("/static", "/data/static").try_compressed()) }) .workers(workers) .tcp_nodelay(true) diff --git a/frameworks/actix/templates/fortunes.html b/frameworks/actix/templates/fortunes.html new file mode 100644 index 0000000000..8e04416d1a --- /dev/null +++ b/frameworks/actix/templates/fortunes.html @@ -0,0 +1,10 @@ + + +Fortunes + + + +{% for fortune in fortunes %} +{% endfor %}
idmessage
{{ fortune.id }}{{ fortune.message }}
+ + diff --git a/site/data/frameworks.json b/site/data/frameworks.json index dd0f472d8d..5d5e36df54 100644 --- a/site/data/frameworks.json +++ b/site/data/frameworks.json @@ -1,7 +1,7 @@ { "actix": { "dir": "actix", - "description": "Actix-web 4 with rustls for TLS. Standard configuration with TCP_NODELAY enabled: actix-files serves static content from disk per request via try_compressed(), which selects a pre-compressed .br/.gz sibling by Accept-Encoding through the framework API (no hand-rolled suffix lookup); the Compress middleware compresses dynamic responses (json-comp) on-the-fly. deadpool-postgres for async DB pooling (sized from DATABASE_MAX_CONN); crud reads go through an in-memory cache-aside (X-Cache MISS/HIT, invalidated on update \u2014 no Redis required). json-tls is served over HTTP/1.1-with-TLS on :8081; baseline-h2/static-h2 over h2 on :8443. serde_json per request. Compiled with -O3 and thin LTO.", + "description": "Actix-web 4 with rustls for TLS and mimalloc as the allocator. Default worker count, TCP_NODELAY enabled. actix-files serves static content from disk per request via try_compressed(), which selects a pre-compressed .br/.gz sibling by Accept-Encoding through the framework API (no hand-rolled suffix lookup). JSON is serialized per request with serde_json; on json-comp gzip (level 1) is driven in the handler, because actix-web's encoder sends every body over 1 KiB through the blocking pool, and the Compress middleware on that route serves any other encoding. async-db through a deadpool-postgres pool per worker (DATABASE_MAX_CONN split between the workers). fortunes rendered through an Askama template. json-tls and static-tls are served over HTTP/1.1-with-TLS on :8081; baseline-h2/static-h2 over h2 on :8443. Compiled with -O3 and thin LTO.", "repo": "https://github.com/actix/actix-web", "type": "flagship", "engine": "actix", @@ -15,7 +15,7 @@ "variants": [ { "dir": "actix-h2c", - "description": "Actix-web 4 h2c-only listener with TCP_NODELAY enabled on port 8082 using bind_auto_h2c. A middleware rejects HTTP/1.1 requests so the port serves HTTP/2 cleartext prior-knowledge exclusively. Handlers share the same shape as the main actix entry (serde_json per request).", + "description": "Actix-web 4 h2c-only listener with TCP_NODELAY enabled on port 8082 using bind_auto_h2c. A middleware rejects HTTP/1.1 requests so the port serves HTTP/2 cleartext prior-knowledge exclusively. Handlers share the same shape as the main actix entry (serde_json per request). mimalloc as the allocator.", "repo": "https://github.com/actix/actix-web", "type": "flagship", "engine": "actix", @@ -29,7 +29,7 @@ }, { "dir": "actix-websocket", - "description": "Actix-web WebSocket echo server with TCP_NODELAY enabled", + "description": "Actix-web WebSocket echo server with TCP_NODELAY enabled and mimalloc as the allocator", "repo": "https://github.com/actix/actix-web", "type": "flagship", "engine": "actix", diff --git a/site/data/results/actix.json b/site/data/results/actix.json index ec54d1a051..4ea579baf4 100644 --- a/site/data/results/actix.json +++ b/site/data/results/actix.json @@ -4,44 +4,44 @@ "8gbit-512": { "framework": "actix", "language": "Rust", - "rps": 49408, - "avg_latency": "90.6us", - "p99_latency": "117.0us", - "cpu": "221.6%", - "memory": "89MiB", + "rps": 49392, + "avg_latency": "94.8us", + "p99_latency": "125.0us", + "cpu": "218.8%", + "memory": "336MiB", "connections": 512, "threads": 64, "duration": "5s", "pipeline": 1, - "bandwidth": "512.56MB/s", - "input_bw": "482.50MB/s", + "bandwidth": "511.65MB/s", + "input_bw": "482.34MB/s", "reconnects": 0, - "status_2xx": 247105, + "status_2xx": 247036, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0, - "cpu_usec": 12204707, - "cpu_per_req_us": 49.3908, + "cpu_usec": 12024000, + "cpu_per_req_us": 48.6731, "target_rate": 50000, - "rate_ratio": 0.9882, - "p99_9_latency": "2859.0us" + "rate_ratio": 0.9878, + "p99_9_latency": "4095.0us" }, "async-32000": { "framework": "actix", "language": "Rust", - "rps": 1747295, - "avg_latency": "14.88ms", - "p99_latency": "17.50ms", - "cpu": "4389.6%", - "memory": "922MiB", + "rps": 1998958, + "avg_latency": "14.42ms", + "p99_latency": "17.00ms", + "cpu": "4807.0%", + "memory": "1.3GiB", "connections": 32000, "threads": 64, "duration": "5s", "pipeline": 1, - "bandwidth": "221.59MB/s", - "input_bw": "79.98MB/s", + "bandwidth": "196.32MB/s", + "input_bw": "91.51MB/s", "reconnects": 0, - "status_2xx": 17472951, + "status_2xx": 19989582, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0 @@ -49,19 +49,19 @@ "async-db-1024": { "framework": "actix", "language": "Rust", - "rps": 150455, - "avg_latency": "6.42ms", - "p99_latency": "10.90ms", - "cpu": "3884.2%", - "memory": "139MiB", + "rps": 320231, + "avg_latency": "2.73ms", + "p99_latency": "19.30ms", + "cpu": "3602.7%", + "memory": "418MiB", "connections": 1024, "threads": 64, "duration": "5s", "pipeline": 1, - "bandwidth": "576.13MB/s", - "input_bw": "10.04MB/s", - "reconnects": 59942, - "status_2xx": 1504551, + "bandwidth": "1.19GB/s", + "input_bw": "21.38MB/s", + "reconnects": 127870, + "status_2xx": 3202317, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0 @@ -69,19 +69,19 @@ "baseline-4096": { "framework": "actix", "language": "Rust", - "rps": 2543260, - "avg_latency": "1.43ms", - "p99_latency": "2.78ms", - "cpu": "6670.6%", - "memory": "163MiB", + "rps": 2955902, + "avg_latency": "1.20ms", + "p99_latency": "2.39ms", + "cpu": "6311.4%", + "memory": "371MiB", "connections": 4096, "threads": 64, "duration": "5s", "pipeline": 1, - "bandwidth": "322.50MB/s", - "input_bw": "196.46MB/s", + "bandwidth": "290.28MB/s", + "input_bw": "228.34MB/s", "reconnects": 0, - "status_2xx": 12716304, + "status_2xx": 14779511, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0 @@ -89,18 +89,18 @@ "baseline-h2-1024": { "framework": "actix", "language": "Rust", - "rps": 3761758, - "avg_latency": "25.27ms", - "p99_latency": "91.73ms", - "cpu": "6257.7%", - "memory": "610MiB", + "rps": 4836173, + "avg_latency": "19.84ms", + "p99_latency": "87.47ms", + "cpu": "6233.4%", + "memory": "829MiB", "connections": 1024, "threads": 64, "duration": "5s", "pipeline": 1, - "bandwidth": "130.74MB/s", + "bandwidth": "163.72MB/s", "reconnects": 0, - "status_2xx": 19034500, + "status_2xx": 24519400, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0 @@ -108,18 +108,18 @@ "baseline-h2-256": { "framework": "actix", "language": "Rust", - "rps": 5153439, - "avg_latency": "4.81ms", - "p99_latency": "18.71ms", - "cpu": "6279.9%", - "memory": "187MiB", + "rps": 6427519, + "avg_latency": "3.82ms", + "p99_latency": "25.31ms", + "cpu": "6262.7%", + "memory": "513MiB", "connections": 256, "threads": 64, "duration": "5s", "pipeline": 1, - "bandwidth": "178.00MB/s", + "bandwidth": "216.27MB/s", "reconnects": 0, - "status_2xx": 25921800, + "status_2xx": 32394700, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0 @@ -127,18 +127,18 @@ "baseline-h2c-1024": { "framework": "actix", "language": "Rust", - "rps": 4419702, - "avg_latency": "22.18ms", - "p99_latency": "59.97ms", - "cpu": "6358.9%", - "memory": "519MiB", + "rps": 4961422, + "avg_latency": "20.15ms", + "p99_latency": "77.59ms", + "cpu": "6340.3%", + "memory": "829MiB", "connections": 1024, "threads": 64, "duration": "5s", "pipeline": 1, - "bandwidth": "153.30MB/s", + "bandwidth": "167.63MB/s", "reconnects": 0, - "status_2xx": 22319500, + "status_2xx": 25104800, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0 @@ -146,18 +146,18 @@ "baseline-h2c-256": { "framework": "actix", "language": "Rust", - "rps": 6096819, - "avg_latency": "4.02ms", - "p99_latency": "8.46ms", - "cpu": "6420.5%", - "memory": "146MiB", + "rps": 6671590, + "avg_latency": "3.67ms", + "p99_latency": "16.15ms", + "cpu": "6418.6%", + "memory": "578MiB", "connections": 256, "threads": 64, "duration": "5s", "pipeline": 1, - "bandwidth": "210.58MB/s", + "bandwidth": "224.03MB/s", "reconnects": 0, - "status_2xx": 30667000, + "status_2xx": 33558100, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0 @@ -165,18 +165,18 @@ "baseline-h2c-4096": { "framework": "actix", "language": "Rust", - "rps": 3621001, - "avg_latency": "100.31ms", - "p99_latency": "234.88ms", - "cpu": "6424.1%", - "memory": "1.9GiB", + "rps": 4500687, + "avg_latency": "83.98ms", + "p99_latency": "210.21ms", + "cpu": "6176.9%", + "memory": "2.6GiB", "connections": 4096, "threads": 64, "duration": "5s", "pipeline": 1, - "bandwidth": "126.71MB/s", + "bandwidth": "153.07MB/s", "reconnects": 0, - "status_2xx": 18430900, + "status_2xx": 22908500, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0 @@ -184,18 +184,18 @@ "echo-ws-16384": { "framework": "actix", "language": "Rust", - "rps": 3310452, - "avg_latency": "2.58ms", - "p99_latency": "5.31ms", - "cpu": "6378.4%", - "memory": "330MiB", + "rps": 3473363, + "avg_latency": "1.94ms", + "p99_latency": "6.13ms", + "cpu": "5920.3%", + "memory": "449MiB", "connections": 16384, "threads": 64, "duration": "5s", "pipeline": 1, - "bandwidth": "22.45MB/s", + "bandwidth": "23.51MB/s", "reconnects": 0, - "status_2xx": 16552263, + "status_2xx": 17366817, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0 @@ -203,18 +203,18 @@ "echo-ws-4096": { "framework": "actix", "language": "Rust", - "rps": 3474308, - "avg_latency": "1.03ms", - "p99_latency": "1.83ms", - "cpu": "6445.9%", - "memory": "147MiB", + "rps": 3660925, + "avg_latency": "957us", + "p99_latency": "1.78ms", + "cpu": "6188.0%", + "memory": "275MiB", "connections": 4096, "threads": 64, "duration": "5s", "pipeline": 1, - "bandwidth": "23.27MB/s", + "bandwidth": "24.54MB/s", "reconnects": 0, - "status_2xx": 17371544, + "status_2xx": 18304628, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0 @@ -222,18 +222,56 @@ "echo-ws-512": { "framework": "actix", "language": "Rust", - "rps": 3540496, - "avg_latency": "144us", - "p99_latency": "260us", - "cpu": "6562.7%", - "memory": "51MiB", + "rps": 3646407, + "avg_latency": "139us", + "p99_latency": "249us", + "cpu": "6495.2%", + "memory": "179MiB", "connections": 512, "threads": 64, "duration": "5s", "pipeline": 1, - "bandwidth": "23.63MB/s", + "bandwidth": "24.34MB/s", "reconnects": 0, - "status_2xx": 17702480, + "status_2xx": 18232035, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0 + }, + "echo-ws-limited-4096": { + "framework": "actix", + "language": "Rust", + "rps": 1145177, + "avg_latency": "68us", + "p99_latency": "214us", + "cpu": "4314.1%", + "memory": "178MiB", + "connections": 4096, + "threads": 64, + "duration": "5s", + "pipeline": 1, + "bandwidth": "25.77MB/s", + "reconnects": 572558, + "status_2xx": 5725887, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0 + }, + "echo-ws-limited-512": { + "framework": "actix", + "language": "Rust", + "rps": 1170845, + "avg_latency": "64us", + "p99_latency": "177us", + "cpu": "4419.1%", + "memory": "173MiB", + "connections": 512, + "threads": 64, + "duration": "5s", + "pipeline": 1, + "bandwidth": "26.35MB/s", + "reconnects": 585420, + "status_2xx": 5854227, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0 @@ -241,18 +279,18 @@ "echo-ws-pipeline-16384": { "framework": "actix", "language": "Rust", - "rps": 41635398, - "avg_latency": "2.22ms", - "p99_latency": "3.94ms", - "cpu": "6438.0%", - "memory": "312MiB", + "rps": 44938672, + "avg_latency": "1.73ms", + "p99_latency": "4.65ms", + "cpu": "6151.7%", + "memory": "341MiB", "connections": 16384, "threads": 64, "duration": "5s", "pipeline": 16, - "bandwidth": "278.11MB/s", + "bandwidth": "300.12MB/s", "reconnects": 0, - "status_2xx": 208176994, + "status_2xx": 224693361, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0 @@ -260,18 +298,18 @@ "echo-ws-pipeline-4096": { "framework": "actix", "language": "Rust", - "rps": 42631209, - "avg_latency": "1.46ms", - "p99_latency": "4.09ms", - "cpu": "6491.4%", - "memory": "152MiB", + "rps": 46405884, + "avg_latency": "1.19ms", + "p99_latency": "4.05ms", + "cpu": "6235.8%", + "memory": "283MiB", "connections": 4096, "threads": 64, "duration": "5s", "pipeline": 16, - "bandwidth": "284.58MB/s", + "bandwidth": "309.81MB/s", "reconnects": 0, - "status_2xx": 213156048, + "status_2xx": 232029424, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0 @@ -279,18 +317,37 @@ "echo-ws-pipeline-512": { "framework": "actix", "language": "Rust", - "rps": 43724995, - "avg_latency": "186us", - "p99_latency": "293us", - "cpu": "6506.5%", - "memory": "48MiB", + "rps": 47190006, + "avg_latency": "172us", + "p99_latency": "278us", + "cpu": "6715.6%", + "memory": "184MiB", "connections": 512, "threads": 64, "duration": "5s", "pipeline": 16, - "bandwidth": "291.70MB/s", + "bandwidth": "315.04MB/s", "reconnects": 0, - "status_2xx": 218624975, + "status_2xx": 235950032, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0 + }, + "fortunes-1024": { + "framework": "actix", + "language": "Rust", + "rps": 267328, + "avg_latency": "2.31ms", + "p99_latency": "7.00ms", + "cpu": "5072.5%", + "memory": "430MiB", + "connections": 1024, + "threads": 64, + "duration": "5s", + "pipeline": 1, + "bandwidth": "6.22GB/s", + "reconnects": 7, + "status_2xx": 1336640, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0 @@ -298,19 +355,19 @@ "json-comp-16384": { "framework": "actix", "language": "Rust", - "rps": 535359, - "avg_latency": "20.64ms", - "p99_latency": "49.30ms", - "cpu": "6596.7%", - "memory": "446MiB", + "rps": 594198, + "avg_latency": "17.56ms", + "p99_latency": "35.10ms", + "cpu": "6562.2%", + "memory": "910MiB", "connections": 16384, "threads": 64, "duration": "5s", "pipeline": 1, - "bandwidth": "927.19MB/s", - "input_bw": "39.82MB/s", - "reconnects": 100990, - "status_2xx": 2676795, + "bandwidth": "1020.68MB/s", + "input_bw": "44.20MB/s", + "reconnects": 112813, + "status_2xx": 2970991, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0 @@ -318,19 +375,19 @@ "json-comp-4096": { "framework": "actix", "language": "Rust", - "rps": 529421, - "avg_latency": "6.50ms", - "p99_latency": "25.60ms", - "cpu": "6248.3%", - "memory": "218MiB", + "rps": 613630, + "avg_latency": "5.84ms", + "p99_latency": "24.60ms", + "cpu": "6341.9%", + "memory": "609MiB", "connections": 4096, "threads": 64, "duration": "5s", "pipeline": 1, - "bandwidth": "916.95MB/s", - "input_bw": "39.38MB/s", - "reconnects": 103922, - "status_2xx": 2647107, + "bandwidth": "1.03GB/s", + "input_bw": "45.65MB/s", + "reconnects": 120997, + "status_2xx": 3068151, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0 @@ -338,18 +395,18 @@ "json-h2c-1024": { "framework": "actix", "language": "Rust", - "rps": 1439298, - "avg_latency": "22.15ms", - "p99_latency": "48.54ms", - "cpu": "6490.5%", - "memory": "365MiB", + "rps": 1764965, + "avg_latency": "17.79ms", + "p99_latency": "48.72ms", + "cpu": "6566.7%", + "memory": "584MiB", "connections": 1024, "threads": 64, "duration": "5s", "pipeline": 1, - "bandwidth": "4.82GB/s", + "bandwidth": "5.94GB/s", "reconnects": 0, - "status_2xx": 7282848, + "status_2xx": 8966023, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0 @@ -357,18 +414,18 @@ "json-h2c-4096": { "framework": "actix", "language": "Rust", - "rps": 1314904, - "avg_latency": "91.19ms", - "p99_latency": "223.88ms", - "cpu": "6301.1%", - "memory": "1.2GiB", + "rps": 1616163, + "avg_latency": "69.10ms", + "p99_latency": "320.17ms", + "cpu": "6244.4%", + "memory": "1.3GiB", "connections": 4096, "threads": 64, "duration": "5s", "pipeline": 1, - "bandwidth": "4.43GB/s", + "bandwidth": "5.45GB/s", "reconnects": 0, - "status_2xx": 6692864, + "status_2xx": 8242432, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0 @@ -376,18 +433,18 @@ "json-tls-4096": { "framework": "actix", "language": "Rust", - "rps": 1137387, - "avg_latency": "3.59ms", - "p99_latency": "38.52ms", - "cpu": "6599.2%", - "memory": "239MiB", + "rps": 1401777, + "avg_latency": "2.87ms", + "p99_latency": "58.23ms", + "cpu": "6274.9%", + "memory": "429MiB", "connections": 4096, "threads": 64, "duration": "5s", "pipeline": 1, - "bandwidth": "3.86GB", + "bandwidth": "4.74GB", "reconnects": 0, - "status_2xx": 5801565, + "status_2xx": 7144916, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0 @@ -396,49 +453,49 @@ "framework": "actix", "language": "Rust", "rps": 9983, - "avg_latency": "72.7us", - "p99_latency": "108.0us", - "cpu": "26.8%", - "memory": "71MiB", + "avg_latency": "69.5us", + "p99_latency": "105.0us", + "cpu": "25.4%", + "memory": "360MiB", "connections": 1024, "threads": 64, "duration": "20s", "pipeline": 1, - "bandwidth": "1.32MB/s", + "bandwidth": "1.02MB/s", "reconnects": 0, - "status_2xx": 199684, + "status_2xx": 199686, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0, - "cpu_usec": 5633694, - "cpu_per_req_us": 28.213, + "cpu_usec": 5316686, + "cpu_per_req_us": 26.6252, "target_rate": 10000, "rate_ratio": 0.9983, - "p99_9_latency": "550.0us" + "p99_9_latency": "149.0us" }, "latency-1m-1024": { "framework": "actix", "language": "Rust", - "rps": 998031, - "avg_latency": "103.5us", - "p99_latency": "182.0us", - "cpu": "2878.6%", - "memory": "79MiB", + "rps": 998533, + "avg_latency": "100.9us", + "p99_latency": "185.0us", + "cpu": "2731.9%", + "memory": "294MiB", "connections": 1024, "threads": 64, "duration": "20s", "pipeline": 1, - "bandwidth": "131.74MB/s", + "bandwidth": "101.85MB/s", "reconnects": 0, - "status_2xx": 19964095, + "status_2xx": 19974148, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0, - "cpu_usec": 537058993, - "cpu_per_req_us": 26.9012, + "cpu_usec": 498944041, + "cpu_per_req_us": 24.9795, "target_rate": 1000000, - "rate_ratio": 0.998, - "p99_9_latency": "3287.0us" + "rate_ratio": 0.9985, + "p99_9_latency": "2261.0us" }, "latency-500k-4cpu-1024": { "framework": "actix", @@ -467,43 +524,43 @@ "latency-500k-8cpu-1024": { "framework": "actix", "language": "Rust", - "rps": 399603, - "avg_latency": "1992261.1us", - "p99_latency": "3927040.0us", - "cpu": "786.4%", - "memory": "40MiB", + "rps": 445089, + "avg_latency": "1075424.1us", + "p99_latency": "2126848.0us", + "cpu": "793.9%", + "memory": "83MiB", "connections": 1024, "threads": 64, "duration": "20s", "pipeline": 1, - "bandwidth": "52.75MB/s", + "bandwidth": "45.40MB/s", "reconnects": 0, - "status_2xx": 7994858, + "status_2xx": 8904704, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0, - "cpu_usec": 159446408, - "cpu_per_req_us": 19.9436, + "cpu_usec": 159558863, + "cpu_per_req_us": 17.9185, "target_rate": 500000, - "rate_ratio": 0.7992, - "p99_9_latency": "3984384.0us" + "rate_ratio": 0.8902, + "p99_9_latency": "2163712.0us" }, "limited-conn-4096": { "framework": "actix", "language": "Rust", - "rps": 1127447, - "avg_latency": "1.22ms", - "p99_latency": "9.40ms", - "cpu": "4587.7%", - "memory": "78MiB", + "rps": 1139262, + "avg_latency": "1.15ms", + "p99_latency": "9.27ms", + "cpu": "4400.5%", + "memory": "278MiB", "connections": 4096, "threads": 64, "duration": "5s", "pipeline": 1, - "bandwidth": "142.96MB/s", - "input_bw": "87.09MB/s", - "reconnects": 563839, - "status_2xx": 5637238, + "bandwidth": "111.87MB/s", + "input_bw": "88.01MB/s", + "reconnects": 569642, + "status_2xx": 5696310, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0 @@ -511,18 +568,18 @@ "pipelined-4096": { "framework": "actix", "language": "Rust", - "rps": 15811353, - "avg_latency": "3.65ms", - "p99_latency": "4.23ms", - "cpu": "6391.4%", - "memory": "209MiB", + "rps": 18907788, + "avg_latency": "3.08ms", + "p99_latency": "3.55ms", + "cpu": "6756.4%", + "memory": "428MiB", "connections": 4096, "threads": 64, "duration": "5s", "pipeline": 16, - "bandwidth": "1.96GB/s", + "bandwidth": "1.81GB/s", "reconnects": 0, - "status_2xx": 79056768, + "status_2xx": 94538944, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0 @@ -530,18 +587,18 @@ "static-h2-1024": { "framework": "actix", "language": "Rust", - "rps": 63793, - "avg_latency": "515.43ms", - "p99_latency": "2.18s", - "cpu": "6106.8%", - "memory": "35.9GiB", + "rps": 404445, + "avg_latency": "77.57ms", + "p99_latency": "228.28ms", + "cpu": "6246.2%", + "memory": "2.8GiB", "connections": 1024, "threads": 64, "duration": "5s", "pipeline": 1, - "bandwidth": "907.73MB/s", + "bandwidth": "6.17GB/s", "reconnects": 0, - "status_2xx": 322795, + "status_2xx": 2054585, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0 @@ -549,18 +606,18 @@ "static-h2-256": { "framework": "actix", "language": "Rust", - "rps": 51027, - "avg_latency": "158.83ms", - "p99_latency": "2.53s", - "cpu": "5714.3%", - "memory": "10.9GiB", + "rps": 419801, + "avg_latency": "19.31ms", + "p99_latency": "61.96ms", + "cpu": "6239.4%", + "memory": "2.3GiB", "connections": 256, "threads": 64, "duration": "5s", "pipeline": 1, - "bandwidth": "777.28MB/s", + "bandwidth": "6.41GB/s", "reconnects": 0, - "status_2xx": 256669, + "status_2xx": 2111603, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0 @@ -568,18 +625,18 @@ "static-tls-1024": { "framework": "actix", "language": "Rust", - "rps": 55457, - "avg_latency": "25.89ms", - "p99_latency": "784.21ms", - "cpu": "6036.6%", - "memory": "4.7GiB", + "rps": 414570, + "avg_latency": "2.51ms", + "p99_latency": "31.64ms", + "cpu": "6303.9%", + "memory": "2.6GiB", "connections": 1024, "threads": 64, "duration": "5s", "pipeline": 1, - "bandwidth": "0.86GB", + "bandwidth": "6.40GB", "reconnects": 0, - "status_2xx": 282818, + "status_2xx": 2114115, "status_3xx": 0, "status_4xx": 0, "status_5xx": 0 diff --git a/site/static/logs/echo-ws-limited/4096/actix-websocket.log b/site/static/logs/echo-ws-limited/4096/actix-websocket.log new file mode 100644 index 0000000000..c3dd1a67ce --- /dev/null +++ b/site/static/logs/echo-ws-limited/4096/actix-websocket.log @@ -0,0 +1 @@ +Application started. diff --git a/site/static/logs/echo-ws-limited/512/actix-websocket.log b/site/static/logs/echo-ws-limited/512/actix-websocket.log new file mode 100644 index 0000000000..c3dd1a67ce --- /dev/null +++ b/site/static/logs/echo-ws-limited/512/actix-websocket.log @@ -0,0 +1 @@ +Application started. diff --git a/site/static/logs/fortunes/1024/actix.log b/site/static/logs/fortunes/1024/actix.log new file mode 100644 index 0000000000..e69de29bb2