You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Apache Bench对HTTP/3 QUIC服务器执行基准测试?

问题描述

我配置了Nginx 1.25.3服务器,使其在443端口接受HTTP/3 QUIC连接。使用Apache Bench(ab)执行基准测试命令:

ab -n 100 -c 10 https://localhost/

得到如下输出:

hari@hari-virtual-machine:~$ ab -n 100 -c 10 https://localhost/
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)...SSL read failed (5) - closing connection
SSL read failed (5) - closing connection
...(省略重复错误行)
..done


Server Software:        
Server Hostname:        localhost
Server Port:            443
TLS Server Name:        localhost

Document Path:          /
Document Length:        0 bytes

Concurrency Level:      10
Time taken for tests:   0.036 seconds
Complete requests:      100
Failed requests:        50
   (Connect: 0, Receive: 0, Length: 0, Exceptions: 50)
Total transferred:      0 bytes
HTML transferred:       0 bytes
Requests per second:    2743.94 [#/sec] (mean)
Time per request:       3.644 [ms] (mean)
Time per request:       0.364 [ms] (mean, across all concurrent requests)
Transfer rate:          0.00 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     0    0   0.3      0       2
Waiting:        0    0   0.0      0       0
Total:          0    0   0.3      0       2

Percentage of the requests served within a certain time (ms)
  50%      0
  66%      0
  75%      0
  80%      0
  90%      1
  95%      1
  98%      1
  99%      2
 100%      2 (longest request)

测试结果显示有50个请求失败,但同时启用HTTP/2(TCP)时,相同测试可成功完成。请问如何使用Apache Bench对QUIC服务器进行基准测试?

解决方案

核心原因

Apache Bench(ab)原生不支持HTTP/3 QUIC协议,它仅支持HTTP/1.1和HTTP/2(部分版本需编译时开启HTTP/2支持)。当你用ab访问仅开启QUIC的Nginx端口时,由于协议不兼容,会出现SSL read failed这类连接错误。

可行方案

1. 使用支持HTTP/3的替代工具

ab无法直接测试QUIC,推荐使用专门支持HTTP/3的基准测试工具:

  • h2load:属于nghttp2工具集,原生支持HTTP/3,示例命令:
    h2load -n 100 -c 10 https://localhost/ --quic
    
  • wrk + QUIC补丁:第三方补丁可让wrk支持HTTP/3,需自行编译带补丁的版本
  • curl(HTTP/3版本):可通过--http3参数发起单请求,若要批量测试需结合脚本封装

2. 验证Nginx QUIC配置正确性

确保你的Nginx配置满足HTTP/3运行要求:

  • 编译时添加--with-http_v3_module参数
  • 配置文件中开启QUIC监听:
    listen 443 quic reuseport;
    listen 443 ssl;
    http3 on;
    ssl_protocols TLSv1.3; # QUIC依赖TLS 1.3
    

3. 若坚持使用ab(仅用于HTTP/2对比测试)

如果只是需要对比HTTP/2和QUIC的性能,可通过Nginx配置强制ab走HTTP/2,但这无法测试QUIC本身:

  • 确保Nginx开启HTTP/2支持(listen 443 ssl http2;)
  • 支持HTTP/2的ab版本会自动尝试使用HTTP/2连接

内容的提问来源于stack exchange,提问作者hari19

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 23:00:35