openssl s_time 是 OpenSSL 官方提供的 SSL/TLS 性能基准测试工具。它通过模拟大量握手连接来测量服务器的每秒处理能力,是评估 TLS 性能的重要工具。

基本用法

1
openssl s_time -connect example.com:443 -new -time 10

参数说明:

  • -connect host:port — 目标服务器地址(默认端口 4433)
  • -new — 测试新建连接(完整握手)
  • -reuse — 测试连接重用(会话恢复)
  • -time seconds — 测试持续时间(默认 30 秒)

实际测试示例

测试 TLS 1.3 新建连接

1
2
3
4
5
6
$ openssl s_time -connect localhost:443 -new -time 3 -tls1_3
Collecting connection statistics for 3 seconds
**********************************************************************************************************************************************************************************************************************************

1243 connections in 1.85s; 671.89 connections/user sec, 0 bytes read per connection
1243 connections in 4 real seconds

测试 TLS 1.2 新建连接

1
2
3
4
5
6
$ openssl s_time -connect localhost:443 -new -time 3 -tls1_2
Collecting connection statistics for 3 seconds
**********************************************************************************************************************************************************************************************************************************

913 connections in 1.29s; 707.75 connections/user sec, 0 bytes read per connection
913 connections in 4 real seconds

指定密码套件测试

1
$ openssl s_time -connect localhost:443 -new -time 3 -cipher ECDHE-RSA-AES128-SHA

结果解读

s_time 输出包含以下关键指标:

指标 含义
connections 测试期间完成的连接数
connections/user sec 每秒处理连接数(核心指标)
bytes read 每次连接读取的字节数

数值越高越好,表示服务器处理 TLS 握手的效率越高。

测试场景选择

-new vs -reuse

模式 用途
-new 测试完整 TLS 握手性能(最常用)
-reuse 测试会话恢复性能(适用于优化过的服务器)
1
2
3
4
5
# 完整握手测试
openssl s_time -connect example.com:443 -new -time 10

# 会话恢复测试
openssl s_time -connect example.com:443 -reuse -time 10

指定 TLS 版本

1
2
3
4
5
6
7
8
9
# 仅测试 TLS 1.3
openssl s_time -connect example.com:443 -new -time 10 -tls1_3

# 仅测试 TLS 1.2
openssl s_time -connect example.com:443 -new -time 10 -tls1_2

# 仅测试 TLS 1.0/1.1(已不推荐)
openssl s_time -connect example.com:443 -new -time 10 -tls1
openssl s_time -connect example.com:443 -new -time 10 -tls1_1

指定密码套件

1
2
# 测试特定密码套件性能
openssl s_time -connect example.com:443 -new -time 10 -cipher ECDHE-RSA-AES256-GCM-SHA384

常用密码套件:

  • ECDHE-RSA-AES256-GCM-SHA384 — TLS 1.2 推荐
  • ECDHE-RSA-CHACHA20-POLY1305 — TLS 1.2 推荐(性能好)
  • TLS_AES_256_GCM_SHA384 — TLS 1.3 默认

抓取实际页面

1
openssl s_time -connect example.com:443 -new -time 10 -www /index.html

添加 -www 参数后,工具会请求指定页面(而非仅握手),可以测试完整 HTTPS 请求链路的性能。

注意事项

  1. 测试时间:生产环境中建议使用 30-60 秒以获得稳定数据
  2. 网络因素:本地测试比远程更准确,避免网络延迟干扰
  3. 服务器负载:测试可能对服务器造成压力,建议在低峰期进行
  4. TLS 版本差异:TLS 1.3 由于优化了握手流程,通常比 TLS 1.2 性能更好

快速对比命令

1
2
3
# 一行命令对比 TLS 1.2 vs TLS 1.3
echo "TLS 1.2:" && openssl s_time -connect localhost:443 -new -time 5 -tls1_2 2>&1 | grep "connections/user sec"
echo "TLS 1.3:" && openssl s_time -connect localhost:443 -new -time 5 -tls1_3 2>&1 | grep "connections/user sec"

测试结果会因服务器硬件、CPU 核心数、OpenSSL 版本等因素差异较大,建议在相同环境下进行对比。