mirror of
https://github.com/nxtrace/NTrace-core.git
synced 2026-12-01 08:51:30 +00:00
fix(bench): 覆盖 Geo 缓存并校验 profile 摘要
- 在复合 workload 中同时训练直接、缓存命中与受控未命中路径 - SHA-256 计算失败时中止 profile manifest 生成
This commit is contained in:
1 parent
8cb5929ede
commit
954267663d
5 files changed
+49
-10
No files matched your search
@@ -18,8 +18,8 @@ benchmark 均不得显著回退超过 1%。
|
||||
## 决策
|
||||
|
||||
1. 不向仓库加入 `default.pgo`,发布构建继续不启用 PGO。
|
||||
2. 保留固定 fake prober/provider、协议 decoder、MTR/Geo JSON 与 WebSocket JSON
|
||||
组成的复合 workload,以及 profile、benchmark、大小和启动测量脚本。
|
||||
2. 保留固定 fake prober/provider(含直接和缓存路径)、协议 decoder、MTR/Geo JSON
|
||||
与 WebSocket JSON 组成的复合 workload,以及 profile、benchmark、大小和启动测量脚本。
|
||||
3. 候选 CPU profile、原始 benchmark 和二进制只作为测量产物保存,不进入 Git。
|
||||
|
||||
## 证据
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
单一复合 workload 由三个等长阶段组成,每段采集 10 秒 CPU profile:
|
||||
|
||||
1. IPv4/IPv6 ICMP、TCP、UDP 纯 decoder。
|
||||
2. fake prober 生成 64 TTL × 4 path,经过 MTR 聚合、fake Geo provider 与
|
||||
`encoding/json` 输出。
|
||||
2. fake prober 生成 64 TTL × 4 path,经过 MTR 聚合、fake Geo provider
|
||||
直接/缓存路径与 `encoding/json` 输出。
|
||||
3. WebSocket envelope 编码和请求解码。
|
||||
|
||||
三段 profile 使用 `go tool pprof -proto` 合并。候选 profile SHA-256 为
|
||||
|
||||
@@ -55,8 +55,8 @@ scripts/perf/measure_help_startup.sh go127 \
|
||||
|
||||
Generate a 30-second candidate profile from one deterministic composite
|
||||
workload with three equally timed phases. It covers the protocol decoders,
|
||||
fake-prober MTR aggregation with a fake Geo provider and JSON output, and
|
||||
WebSocket JSON encode/decode:
|
||||
fake-prober MTR aggregation with direct and cached fake Geo provider paths and
|
||||
JSON output, and WebSocket JSON encode/decode:
|
||||
|
||||
```sh
|
||||
scripts/perf/generate_pgo_profile.sh candidate
|
||||
|
||||
@@ -84,6 +84,11 @@ profile_component ./server BenchmarkPGOWebSocketJSONWorkload websocket-json
|
||||
candidate="${RESULT_DIR}/${RESULT_NAME}.candidate.pgo"
|
||||
go tool pprof -proto -output "${candidate}" "${profiles[@]}"
|
||||
|
||||
candidate_sha256="$(sha256_file "${candidate}")" || {
|
||||
echo "error: failed to calculate SHA-256 for ${candidate}" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
manifest="${RESULT_DIR}/${RESULT_NAME}.profile.txt"
|
||||
{
|
||||
printf 'commit=%s\n' "$(git -C "${ROOT_DIR}" rev-parse HEAD)"
|
||||
@@ -97,7 +102,7 @@ manifest="${RESULT_DIR}/${RESULT_NAME}.profile.txt"
|
||||
printf 'profile_2=./trace:BenchmarkPGOTraceWorkload\n'
|
||||
printf 'profile_3=./server:BenchmarkPGOWebSocketJSONWorkload\n'
|
||||
printf 'candidate=%s\n' "${candidate}"
|
||||
printf 'candidate_sha256=%s\n' "$(sha256_file "${candidate}")"
|
||||
printf 'candidate_sha256=%s\n' "${candidate_sha256}"
|
||||
} >"${manifest}"
|
||||
|
||||
cat "${manifest}"
|
||||
|
||||
@@ -73,19 +73,40 @@ func BenchmarkPGOTraceWorkload(b *testing.B) {
|
||||
provider := ipgeo.Source(func(string, time.Duration, string, bool) (*ipgeo.IPGeoData, error) {
|
||||
return geo, nil
|
||||
})
|
||||
cachedProviderCalls := 0
|
||||
cachedProvider := CachedGeoSource(ipgeo.SourceDescriptor{
|
||||
Source: func(string, time.Duration, string, bool) (*ipgeo.IPGeoData, error) {
|
||||
cachedProviderCalls++
|
||||
return geo, nil
|
||||
},
|
||||
Namespace: ipgeo.SourceNamespaceIPSB,
|
||||
Backend: ipgeo.SourceNamespaceIPSB,
|
||||
})
|
||||
const hotQuery = "198.18.1.1"
|
||||
coldQueries := make([]string, 4095)
|
||||
for idx := range coldQueries {
|
||||
coldQueries[idx] = fmt.Sprintf("198.19.%d.%d", idx>>8, idx&0xff)
|
||||
}
|
||||
ClearCaches()
|
||||
b.Cleanup(ClearCaches)
|
||||
prober := newPGOBenchmarkProber(geo)
|
||||
agg := NewMTRAggregator()
|
||||
result := &Result{Hops: make([][]Hop, mtrBenchmarkTTLCount)}
|
||||
|
||||
if got, err := provider("198.18.1.1", time.Second, "en", false); err != nil || got != geo {
|
||||
if got, err := provider(hotQuery, time.Second, "en", false); err != nil || got != geo {
|
||||
b.Fatalf("fake geo provider = (%+v, %v), want fixture", got, err)
|
||||
}
|
||||
if got, err := cachedProvider(hotQuery, time.Second, "en", false); err != nil || got == nil {
|
||||
b.Fatalf("cached fake geo provider = (%+v, %v), want fixture", got, err)
|
||||
}
|
||||
if probe, err := prober.ProbeTTL(context.Background(), 1); err != nil || !probe.Success {
|
||||
b.Fatalf("fake prober = (%+v, %v), want success", probe, err)
|
||||
}
|
||||
_ = prober.Reset()
|
||||
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
iteration := 0
|
||||
for b.Loop() {
|
||||
agg.Reset()
|
||||
if err := prober.Reset(); err != nil {
|
||||
@@ -95,10 +116,20 @@ func BenchmarkPGOTraceWorkload(b *testing.B) {
|
||||
result.Hops[idx] = result.Hops[idx][:0]
|
||||
}
|
||||
|
||||
resolved, err := provider("198.18.1.1", time.Second, "en", false)
|
||||
if err != nil {
|
||||
if _, err := provider(hotQuery, time.Second, "en", false); err != nil {
|
||||
b.Fatalf("fake geo provider: %v", err)
|
||||
}
|
||||
resolved, err := cachedProvider(hotQuery, time.Second, "en", false)
|
||||
if err != nil {
|
||||
b.Fatalf("cached fake geo provider: %v", err)
|
||||
}
|
||||
if iteration%64 == 0 {
|
||||
coldQuery := coldQueries[(iteration/64)%len(coldQueries)]
|
||||
if _, err := cachedProvider(coldQuery, time.Second, "en", false); err != nil {
|
||||
b.Fatalf("cached fake geo provider miss: %v", err)
|
||||
}
|
||||
}
|
||||
iteration++
|
||||
for ttl := 1; ttl <= mtrBenchmarkTTLCount; ttl++ {
|
||||
for range mtrBenchmarkPathCount {
|
||||
probe, err := prober.ProbeTTL(context.Background(), ttl)
|
||||
@@ -122,4 +153,7 @@ func BenchmarkPGOTraceWorkload(b *testing.B) {
|
||||
if err := prober.Close(); err != nil {
|
||||
b.Fatalf("close fake prober: %v", err)
|
||||
}
|
||||
if want := 1 + (iteration+63)/64; cachedProviderCalls != want {
|
||||
b.Fatalf("cached fake geo provider calls = %d, want %d", cachedProviderCalls, want)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user