< 返回版块

1192724521 发表于 2022-07-12 16:06

Tags:axum,tokio

#[tokio::main(worker_threads = 1)]
async fn main() {
    let app = Router::new().route("/", get(root));
    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));

    axum::Server::bind(&addr)
        .serve(app.into_make_service())
        .await
        .unwrap();
}

async fn root() -> &'static str {
    tokio::spawn(async move {
        tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
        "success"
    })
    .await
    .unwrap()
}

Complete requests: 100000 Concurrency Level: 10000

work threads Time taken for tests Requests per second
1 28 3566
8 28 3545
16 28 3523

工作线程数量怎么没用呀emmm

怎么才能实现这个

work threads Time taken for tests Requests per second
1 28 3566
2 14 7000
4 10 10000
8 10 10000

评论区

写评论
苦瓜小仔 2022-07-14 21:55

那我就不知道了

作者 1192724521 2022-07-14 21:03

呀,大佬我试了一下,工作线程的数量对并发还是没影响啊

--
👇
苦瓜小仔:

async fn root() {
    tokio::task::spawn(tokio::time::sleep(tokio::time::Duration::from_secs(3)));
}

$ time curl 127.0.0.1:3000

________________________________________________________
Executed in   13.24 millis    fish           external
   usr time    0.31 millis  306.00 micros    0.00 millis
   sys time    8.60 millis  167.00 micros    8.44 millis
// 你的
async fn root() {
    tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
}

$ time curl 127.0.0.1:3000

________________________________________________________
Executed in    3.01 secs      fish           external
   usr time    9.11 millis  318.00 micros    8.79 millis
   sys time    0.17 millis  175.00 micros    0.00 millis
苦瓜小仔 2022-07-13 22:45
async fn root() {
    tokio::task::spawn(tokio::time::sleep(tokio::time::Duration::from_secs(3)));
}

$ time curl 127.0.0.1:3000

________________________________________________________
Executed in   13.24 millis    fish           external
   usr time    0.31 millis  306.00 micros    0.00 millis
   sys time    8.60 millis  167.00 micros    8.44 millis
// 你的
async fn root() {
    tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
}

$ time curl 127.0.0.1:3000

________________________________________________________
Executed in    3.01 secs      fish           external
   usr time    9.11 millis  318.00 micros    8.79 millis
   sys time    0.17 millis  175.00 micros    0.00 millis
作者 1192724521 2022-07-13 22:13

Complete requests: 200000 Concurrency Level: 5000

work threads Time taken for tests Requests per second
1 43 4616
8 44 4484
16 41 4777

大佬们,为什么工作线程对并发没起作用呀emm搞不明白

1 共 4 条评论, 1 页