uWebSockets http 服务太慢

uWebSockets http serves too slow

我克隆了 uWebSockets,写了以下文件。

#include <App.h>
#include <iostream>

int main() {
    uWS::App()
            .get("/*", [](auto *res, auto *req) {
                res->end("Hello world!");
            })
            .listen(3000, [](auto *token) {
                if (token) {
                    std::cout << "Listening on port " << 3000 << std::endl;
                }
            })
            .run();

    std::cout << "Failed to listen on port 3000" << std::endl;
    return 0;
}

构建
make -C uWebSockets/uSockets
g++ -flto -O3 -Wconversion -std=c++17 -IuWebSockets/src -IuWebSockets/uSockets/src main.cpp -o main uWebSockets/uSockets/*.o -lz -lssl -lcrypto -luv

当我做基准测试时,这就是我得到的结果。

Concurrency Level:      100
Time taken for tests:   116.928 seconds
Complete requests:      1000
Failed requests:        0
Total transferred:      68000 bytes
HTML transferred:       12000 bytes
Requests per second:    8.55 [#/sec] (mean)
Time per request:       11692.844 [ms] (mean)
Time per request:       116.928 [ms] (mean, across all concurrent requests)
Transfer rate:          0.57 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    3   2.6      2      10
Processing:  8923 11690 921.2  11995   12012
Waiting:        0    1   1.3      0      10
Total:       8923 11693 921.7  11999   12012

Percentage of the requests served within a certain time (ms)
  50%  11999
  66%  12001
  75%  12002
  80%  12003
  90%  12006
  95%  12008
  98%  12010
  99%  12011
 100%  12012 (longest request)

如果我将并发设置为 1,就会发生这种情况

Concurrency Level:      1
Time taken for tests:   61.655 seconds
Complete requests:      5
Failed requests:        0
Total transferred:      408 bytes
HTML transferred:       72 bytes
Requests per second:    0.08 [#/sec] (mean)
Time per request:       12330.911 [ms] (mean)
Time per request:       12330.911 [ms] (mean, across all concurrent requests)
Transfer rate:          0.01 [Kbytes/sec] received

我是不是做错了什么?我错过了什么?不是应该更快吗?

PS。我是 运行 它在单线程上。

我正在使用 apache 基准测试工具 (ab),它很慢,而不是程序。使用 bomberdier 得到这个结果

Bombarding http://127.0.0.1:3000/ with 1000000 request(s) using 5000 connection(s)
 1000000 / 1000000 [===============================================================================================================================================================================================] 100.00% 316582/s 3s
Done!
Statistics        Avg      Stdev        Max
  Reqs/sec    361230.80   54733.74  520938.19
  Latency       14.06ms     8.81ms   358.62ms
  HTTP codes:
    1xx - 0, 2xx - 1000000, 3xx - 0, 4xx - 0, 5xx - 0
    others - 0
  Throughput:    40.48MB/s