actix-web: keepalives not working

I’m testing keepalive requests with the following code but when using Apache bench but I don’t get keepalives.

extern crate actix_web;
use actix_web::{server, App, HttpRequest};

fn hello_world(_req: &HttpRequest) -> &'static str {
    "Hello World!"
}

fn main() {
    server::new(|| App::new().resource("/", |r| r.f(hello_world)))
        .keep_alive(server::KeepAlive::Tcp(75))
        .bind("0.0.0.0:8080")
        .expect("Can not bind to port 8080")
        .run();
}
ab -k -n 300000 -c 10 http://10.1.11.206:8080/
...
Concurrency Level:      10
Time taken for tests:   17.192 seconds
Complete requests:      62671
Failed requests:        0
Write errors:           0
Keep-Alive requests:    0
Total transferred:      8084817 bytes
HTML transferred:       752076 bytes
Requests per second:    3645.36 [#/sec] (mean)
Time per request:       2.743 [ms] (mean)
Time per request:       0.274 [ms] (mean, across all concurrent requests)
Transfer rate:          459.24 [Kbytes/sec] received

This is showing no requests where Keep-Alive and the performance is pretty bad. This is on Centos 7.6, rustc 1.31.0 and setting actix-web = “0.7”. Am I missing something in the docs that i need to set ?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 20 (11 by maintainers)

Most upvoted comments

@jeffsmith82 ~Keep-Alive is available only in HTTP 1.1, 1.0 cannot be used with keep-alive so we only send this header in 1.1~

Actually I may be mistaken, I need to re-check kit

It seems we should set keep-alive only in 1.0 case because 1.1. makes it default