actix / actix-web

Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust.
https://actix.rs
Apache License 2.0
21.32k stars 1.66k forks source link

Low performance of actix-files #3444

Open diviaki opened 1 month ago

diviaki commented 1 month ago

Static content is coming through really slow: I visually see a 128kB jpg arriving in multiple chunks to the browser. Server load is low during the static fie wrk tests.

Expected Behavior

The same server (details below) delivers it's dynamic main page with session handling, etc like this: Running 10s test @ https://localhost 2 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 405.29us 1.74ms 51.69ms 99.57% Req/Sec 16.17k 1.14k 21.88k 96.53% 325035 requests in 10.10s, 1.28GB read Requests/sec: 32181.51 Transfer/sec: 130.10MB server load 100%

Current Behavior

Running 10s test @ https://localhost:444/welcome_ph.jpg 2 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 41.74ms 10.80ms 49.76ms 93.37% Req/Sec 119.64 24.08 210.00 88.50% 2384 requests in 10.01s, 288.76MB read Requests/sec: 238.20 Transfer/sec: 28.85MB server load 1%

Without TLS it's getting better but also gets varying: Running 10s test @ http://localhost:8989/welcome_ph.jpg 2 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 11.16ms 14.25ms 51.32ms 78.67% Req/Sec 1.40k 1.90k 5.15k 74.50% 27768 requests in 10.02s, 3.28GB read Requests/sec: 2771.84 Transfer/sec: 335.04MB server load 60..20%

Rerunning it within a few seconds: Running 10s test @ http://localhost:8989/welcome_ph.jpg 2 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 17.03ms 17.06ms 56.31ms 79.89% Req/Sec 396.98 840.28 4.40k 95.00% 7910 requests in 10.02s, 0.93GB read Requests/sec: 789.67 Transfer/sec: 95.50MB server load 20..10%

Steps to Reproduce (for bugs)

src/main.rs

use actix_files;
use actix_web::{ App, HttpServer};

#[actix_web::main]
async fn main() -> std::io::Result<()> {

    let mut certs_file = std::io::BufReader::new(std::fs::File::open("cert.pem").unwrap());
    let mut key_file = std::io::BufReader::new(std::fs::File::open("key.pem").unwrap());

    let tls_certs = rustls_pemfile::certs(&mut certs_file)
    .collect::<Result<Vec<_>, _>>()
    .unwrap();
    let tls_key = rustls_pemfile::pkcs8_private_keys(&mut key_file)
    .next()
    .unwrap()
    .unwrap();

    let tls_config = rustls::ServerConfig::builder()
        .with_no_client_auth()
        .with_single_cert(tls_certs, rustls::pki_types::PrivateKeyDer::Pkcs8(tls_key))
        .unwrap();

    HttpServer::new(|| {
        App::new()
        .service(actix_files::Files::new("/w", "www"))
    })
    //.bind_rustls_0_22(("::", 444), tls_config)?
    .bind("localhost:8989")?
    .run()
    .await
}

Cargo.toml

[package]
name = "zendorka-teszt"
version = "0.1.1"
edition = "2024"

[dependencies]
actix-web = { version = "4", features = ["rustls-0_22"] }
rustls = "0.22"
rustls-pemfile = "2"
actix-files = "0"
cargo run --release
wrk

Your Environment

2 VCPU 4GB ARM server at Hetzner. (Not throttled during my test.) Debian 6.1.76-1 (2024-02-01) aarch64 GNU/Linux rustc 1.78.0 (9b00956e5 2024-04-29) I assume I use the latest crates cargo can delive, see Cargo.toml.

diviaki commented 1 week ago

Some more tests: