cloudflare / pingora

A library for building fast, reliable and evolvable network services.
Apache License 2.0
20.25k stars 1.1k forks source link

How to achieve high performance pingora? #227

Closed caihonghaoCYF closed 1 month ago

caihonghaoCYF commented 2 months ago

Describe the bug

When I pressure tested pingora with wrk, I found that qps was low, general-purpose machines, and nginx was normal。

Pingora info

pub struct HttpEchoApp;

[async_trait]

impl ServeHttp for HttpEchoApp { async fn response(&self, http_stream: &mut ServerSession) -> Response<Vec> { // read timeout of 2s let read_timeout = 2000; let body = match timeout( Duration::from_millis(read_timeout), http_stream.read_requestbody(), ) .await { Ok(res) => match res.unwrap() { Some(bytes) => bytes, None => Bytes::from("no body!"), }, Err() => { panic!("Timed out after {:?}ms", read_timeout); } };

    Response::builder()
        .status(StatusCode::OK)
        .header(http::header::CONTENT_TYPE, "text/html")
        .header(http::header::CONTENT_LENGTH, body.len())
        .body(body.to_vec())
        .unwrap()
}

}

pub fn new_http_echo_app() -> Arc { Arc::new(HttpEchoApp {}) }

pub fn echo_service_http() -> Service { Service::new("Echo Service HTTP".to_string(), new_http_echo_app()) }

fn main() { println!("ready to start server!!!!");

let mut my_server = Server::new(None).unwrap();
let mut sc = ServerConf{..Default::default()};
sc.threads = 4;
my_server.configuration = Arc::new(sc);
my_server.bootstrap();

let mut echo_service_http = echo_service_http();
echo_service_http.add_tcp("0.0.0.0:6145");
echo_service_http.add_uds("/tmp/echo.sock", None);

my_server.add_service(echo_service_http);
my_server.run_forever();

}

caihonghaoCYF commented 2 months ago

--------------------------pingora------------------------------- [root@10 demo01]# wrk -t 4 -c 50 -d 30s http://127.0.0.1:6188 Running 30s test @ http://127.0.0.1:6188 4 threads and 50 connections Thread Stats Avg Stdev Max +/- Stdev Latency 63.57ms 249.95ms 1.94s 95.57% Req/Sec 1.09k 370.03 2.56k 71.35% 121194 requests in 30.11s, 225.26MB read Non-2xx or 3xx responses: 121194 Requests/sec: 4025.48

--------------------------nginx------------------------------- [root@10 demo01]# wrk -t 4 -c 50 -d 30s http://127.0.0.1:9080 Running 30s test @ http://127.0.0.1:9080 4 threads and 50 connections Thread Stats Avg Stdev Max +/- Stdev Latency 18.12ms 93.98ms 1.00s 96.49% Req/Sec 24.53k 15.85k 70.03k 68.82% 2768119 requests in 30.09s, 435.58MB read Requests/sec: 92006.88 Transfer/sec: 14.48MB

vicanso commented 2 months ago

Non-2xx or 3xx responses: 121194

Pingora will close the connection if fail_to_proxy, please refer to #190

caihonghaoCYF commented 2 months ago

I get it. Thx~