Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Low performance of actix-files #3444

Open
diviaki opened this issue Aug 9, 2024 · 1 comment
Open

Low performance of actix-files #3444

diviaki opened this issue Aug 9, 2024 · 1 comment

Comments

@diviaki
Copy link

diviaki commented Aug 9, 2024

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
Copy link
Author

diviaki commented Sep 9, 2024

Some more tests:

  • also affects intel arch
  • does not affects ntex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant