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

Extremely slow StaticFiles peformance #560

Closed
transkatgirl opened this issue Oct 24, 2018 · 8 comments
Closed

Extremely slow StaticFiles peformance #560

transkatgirl opened this issue Oct 24, 2018 · 8 comments

Comments

@transkatgirl
Copy link

transkatgirl commented Oct 24, 2018

When connecting to a HTTP server built with actix-web, if the server uses the builtin fs::StaticFiles method for serving content, there is a severe performance impact in newer versions of actix-web (> 0.7.8).

Here's a simple example server to show the issue:

extern crate actix_web;
use actix_web::{fs::StaticFiles, server, App};

fn main() {
    server::new(|| {
        App::new()
	        .handler("/",StaticFiles::new("./static/").unwrap().index_file("index.html"))
    }).bind("[::]:8080")
        .unwrap()
        .run();
}

(Note that the "index.html" file used for testing is 1024 bytes. When serving large files, the performance impact is much lower.)

Performance on actix-web v0.7.13:

Running 10s test @ http://localhost:8080/index.html
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    41.77ms    8.92ms  47.70ms   95.54%
    Req/Sec   383.49     41.16   540.00     69.00%
  7643 requests in 10.01s, 9.37MB read
Requests/sec:    763.67
Transfer/sec:      0.94MB

Performance on actix-web v0.7.8:

Running 10s test @ http://localhost:8080/index.html
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     0.92ms    0.89ms  28.22ms   91.59%
    Req/Sec    19.48k     1.13k   22.51k    71.50%
  387887 requests in 10.01s, 474.98MB read
Requests/sec:  38765.56
Transfer/sec:     47.47MB
@DoumanAsh
Copy link
Contributor

Hm... interesting, I don't think there should such serious change to StaticFiles.
Thanks for noticing it

@fafhrd91
Copy link
Member

I enabled timeouts by default in latest versions of actix-web. that might affect default performance, but it should not be that dramatic

@transkatgirl
Copy link
Author

After a bit of testing, it looks like ChunkedReadFile is what's slowing down StaticFiles so much.

Also, something completely unrelated I noticed: Why is ChunkedReadFile public, but all of it's fields are private? Making it's fields public too would probably be a good idea.

@DoumanAsh
Copy link
Contributor

Just a note: there are no significant changes to the way we read static files.

@kittyhacker101 So I'm curious do you see a similar problem with your regular handlers?

@transkatgirl
Copy link
Author

Well, I haven't had any issues with normal streamed handlers, just with handlers using ChunkedReadFile (like StaticFiles).

@DoumanAsh
Copy link
Contributor

DoumanAsh commented Oct 25, 2018

@fafhrd91 Do you remember were there any changes recently to the way actix-web sends out streaming/chunked bodies?

I heard from another fellow that there was some problems with timing when responding with chunked responses

@transkatgirl
Copy link
Author

transkatgirl commented Oct 30, 2018

@DoumanAsh It looks like commit c674ea9 is causing this problem.

Performance before the commit:

Running 10s test @ http://localhost:8080/index.html
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     0.85ms  675.10us  17.54ms   91.13%
    Req/Sec    19.95k     0.90k   22.48k    68.00%
  396994 requests in 10.00s, 486.51MB read
Requests/sec:  39687.22
Transfer/sec:     48.64MB

Performance after the commit:

Running 10s test @ http://localhost:8080/index.html
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    41.31ms    9.71ms  46.80ms   94.67%
    Req/Sec   387.95     44.02   535.00     64.00%
  7726 requests in 10.00s, 9.48MB read
Requests/sec:    772.43
Transfer/sec:      0.95MB

@fafhrd91
Copy link
Member

fafhrd91 commented Nov 9, 2018

added nodelay in master, could you test again.

@fafhrd91 fafhrd91 closed this as completed Nov 9, 2018
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

3 participants