feat(transport): 完成安全架构拆分并收口 stream/bulk 传输优化
- 新增 managed/external/nested 三种传输保护模式 - 新增 peer attach 显式认证、抗重放、channel binding 和可选前向保密协商 - 明确单连接注入与可重拨连接源的语义边界 - 禁止 ConnectByConn 场景下 dedicated bulk 走 sidecar,auto 模式自动回退 shared - 修正 dedicated attach 在 bootstrap/steady profile 切换下的处理逻辑 - 优化 shared bulk super-batch 与批量 framed write 路径 - 降低 stream/bulk fast path 的复制和分发损耗 - 补齐 benchmark、回归测试、运行时快照和 README 文档
This commit is contained in:
+112
-16
@@ -56,7 +56,59 @@ func BenchmarkStreamTCPThroughput(b *testing.B) {
|
||||
|
||||
for _, tc := range cases {
|
||||
b.Run(tc.name, func(b *testing.B) {
|
||||
benchmarkStreamTCPThroughput(b, tc.payloadSize, tc.cfg)
|
||||
benchmarkStreamTCPThroughput(b, tc.payloadSize, tc.cfg, benchmarkTransportSecurityModernPSK)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkStreamTCPThroughputTrustedRaw(b *testing.B) {
|
||||
cases := []struct {
|
||||
name string
|
||||
payloadSize int
|
||||
cfg StreamConfig
|
||||
}{
|
||||
{
|
||||
name: "default_64KiB",
|
||||
payloadSize: 64 * 1024,
|
||||
},
|
||||
{
|
||||
name: "tuned_256KiB",
|
||||
payloadSize: 256 * 1024,
|
||||
cfg: StreamConfig{
|
||||
ChunkSize: 256 * 1024,
|
||||
InboundQueueLimit: 256,
|
||||
InboundBufferedBytesLimit: 32 * 1024 * 1024,
|
||||
OutboundWindowBytes: 8 * 1024 * 1024,
|
||||
OutboundMaxInFlightChunks: 32,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "tuned_512KiB",
|
||||
payloadSize: 512 * 1024,
|
||||
cfg: StreamConfig{
|
||||
ChunkSize: 512 * 1024,
|
||||
InboundQueueLimit: 256,
|
||||
InboundBufferedBytesLimit: 64 * 1024 * 1024,
|
||||
OutboundWindowBytes: 16 * 1024 * 1024,
|
||||
OutboundMaxInFlightChunks: 32,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "tuned_1MiB",
|
||||
payloadSize: 1024 * 1024,
|
||||
cfg: StreamConfig{
|
||||
ChunkSize: 1024 * 1024,
|
||||
InboundQueueLimit: 256,
|
||||
InboundBufferedBytesLimit: 64 * 1024 * 1024,
|
||||
OutboundWindowBytes: 16 * 1024 * 1024,
|
||||
OutboundMaxInFlightChunks: 32,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
b.Run(tc.name, func(b *testing.B) {
|
||||
benchmarkStreamTCPThroughput(b, tc.payloadSize, tc.cfg, benchmarkTransportSecurityTrustedRaw)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -108,19 +160,69 @@ func BenchmarkStreamTCPThroughputConcurrent(b *testing.B) {
|
||||
|
||||
for _, tc := range cases {
|
||||
b.Run(tc.name, func(b *testing.B) {
|
||||
benchmarkStreamTCPThroughputConcurrent(b, tc.payloadSize, tc.concurrency, tc.cfg)
|
||||
benchmarkStreamTCPThroughputConcurrent(b, tc.payloadSize, tc.concurrency, tc.cfg, benchmarkTransportSecurityModernPSK)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func benchmarkStreamTCPThroughput(b *testing.B, payloadSize int, cfg StreamConfig) {
|
||||
func BenchmarkStreamTCPThroughputConcurrentTrustedRaw(b *testing.B) {
|
||||
cases := []struct {
|
||||
name string
|
||||
payloadSize int
|
||||
concurrency int
|
||||
cfg StreamConfig
|
||||
}{
|
||||
{
|
||||
name: "streams_2_512KiB",
|
||||
payloadSize: 512 * 1024,
|
||||
concurrency: 2,
|
||||
cfg: StreamConfig{
|
||||
ChunkSize: 512 * 1024,
|
||||
InboundQueueLimit: 512,
|
||||
InboundBufferedBytesLimit: 128 * 1024 * 1024,
|
||||
OutboundWindowBytes: 32 * 1024 * 1024,
|
||||
OutboundMaxInFlightChunks: 64,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "streams_4_512KiB",
|
||||
payloadSize: 512 * 1024,
|
||||
concurrency: 4,
|
||||
cfg: StreamConfig{
|
||||
ChunkSize: 512 * 1024,
|
||||
InboundQueueLimit: 1024,
|
||||
InboundBufferedBytesLimit: 256 * 1024 * 1024,
|
||||
OutboundWindowBytes: 64 * 1024 * 1024,
|
||||
OutboundMaxInFlightChunks: 128,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "streams_8_512KiB",
|
||||
payloadSize: 512 * 1024,
|
||||
concurrency: 8,
|
||||
cfg: StreamConfig{
|
||||
ChunkSize: 512 * 1024,
|
||||
InboundQueueLimit: 2048,
|
||||
InboundBufferedBytesLimit: 512 * 1024 * 1024,
|
||||
OutboundWindowBytes: 128 * 1024 * 1024,
|
||||
OutboundMaxInFlightChunks: 256,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
b.Run(tc.name, func(b *testing.B) {
|
||||
benchmarkStreamTCPThroughputConcurrent(b, tc.payloadSize, tc.concurrency, tc.cfg, benchmarkTransportSecurityTrustedRaw)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func benchmarkStreamTCPThroughput(b *testing.B, payloadSize int, cfg StreamConfig, securityMode benchmarkTransportSecurityMode) {
|
||||
b.Helper()
|
||||
|
||||
server := NewServer().(*ServerCommon)
|
||||
server.SetStreamConfig(cfg)
|
||||
if err := UseModernPSKServer(server, integrationSharedSecret, integrationModernPSKOptions()); err != nil {
|
||||
b.Fatalf("UseModernPSKServer failed: %v", err)
|
||||
}
|
||||
benchmarkApplyServerTransportSecurity(b, server, securityMode)
|
||||
|
||||
acceptCh := make(chan StreamAcceptInfo, 1)
|
||||
server.SetStreamHandler(func(info StreamAcceptInfo) error {
|
||||
@@ -137,9 +239,7 @@ func benchmarkStreamTCPThroughput(b *testing.B, payloadSize int, cfg StreamConfi
|
||||
|
||||
client := NewClient().(*ClientCommon)
|
||||
client.SetStreamConfig(cfg)
|
||||
if err := UseModernPSKClient(client, integrationSharedSecret, integrationModernPSKOptions()); err != nil {
|
||||
b.Fatalf("UseModernPSKClient failed: %v", err)
|
||||
}
|
||||
benchmarkApplyClientTransportSecurity(b, client, securityMode)
|
||||
if err := client.Connect("tcp", benchmarkTCPDialAddr(b, server.listener.Addr().String())); err != nil {
|
||||
b.Fatalf("client Connect failed: %v", err)
|
||||
}
|
||||
@@ -198,7 +298,7 @@ func benchmarkStreamTCPThroughput(b *testing.B, payloadSize int, cfg StreamConfi
|
||||
_ = stream.Close()
|
||||
}
|
||||
|
||||
func benchmarkStreamTCPThroughputConcurrent(b *testing.B, payloadSize int, concurrency int, cfg StreamConfig) {
|
||||
func benchmarkStreamTCPThroughputConcurrent(b *testing.B, payloadSize int, concurrency int, cfg StreamConfig, securityMode benchmarkTransportSecurityMode) {
|
||||
b.Helper()
|
||||
if concurrency <= 0 {
|
||||
b.Fatal("concurrency must be > 0")
|
||||
@@ -206,9 +306,7 @@ func benchmarkStreamTCPThroughputConcurrent(b *testing.B, payloadSize int, concu
|
||||
|
||||
server := NewServer().(*ServerCommon)
|
||||
server.SetStreamConfig(cfg)
|
||||
if err := UseModernPSKServer(server, integrationSharedSecret, integrationModernPSKOptions()); err != nil {
|
||||
b.Fatalf("UseModernPSKServer failed: %v", err)
|
||||
}
|
||||
benchmarkApplyServerTransportSecurity(b, server, securityMode)
|
||||
|
||||
acceptCh := make(chan StreamAcceptInfo, concurrency*2)
|
||||
server.SetStreamHandler(func(info StreamAcceptInfo) error {
|
||||
@@ -225,9 +323,7 @@ func benchmarkStreamTCPThroughputConcurrent(b *testing.B, payloadSize int, concu
|
||||
|
||||
client := NewClient().(*ClientCommon)
|
||||
client.SetStreamConfig(cfg)
|
||||
if err := UseModernPSKClient(client, integrationSharedSecret, integrationModernPSKOptions()); err != nil {
|
||||
b.Fatalf("UseModernPSKClient failed: %v", err)
|
||||
}
|
||||
benchmarkApplyClientTransportSecurity(b, client, securityMode)
|
||||
if err := client.Connect("tcp", benchmarkTCPDialAddr(b, server.listener.Addr().String())); err != nil {
|
||||
b.Fatalf("client Connect failed: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user