Skip to content

Commit adcfd71

Browse files
authored
fix: rewrite squid_https_latency to use background containers (#1816)
* Initial plan * fix: rewrite squid_https_latency to use background containers Agent-Logs-Url: https://github.com/github/gh-aw-firewall/sessions/f9964b96-7900-4d86-89c4-fcb0dea34f26 --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent 6ec2299 commit adcfd71

1 file changed

Lines changed: 30 additions & 9 deletions

File tree

scripts/ci/benchmark-performance.ts

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,27 +104,48 @@ function benchmarkWarmStart(): BenchmarkResult {
104104
return { metric: "container_startup_warm", unit: "ms", values, ...stats(values) };
105105
}
106106

107-
function benchmarkHttpsLatency(): BenchmarkResult {
107+
async function benchmarkHttpsLatency(): Promise<BenchmarkResult> {
108108
console.error(" Benchmarking HTTPS latency through Squid...");
109109
const values: number[] = [];
110110

111111
for (let i = 0; i < ITERATIONS; i++) {
112112
cleanup();
113+
let child: ChildProcess | null = null;
113114
try {
114-
// Use curl's time_total to measure end-to-end HTTPS request latency
115+
// Start AWF in the background so Squid stays alive, then measure
116+
// latency by curling through the proxy directly from the host.
117+
// This isolates Squid proxy latency from container startup overhead.
118+
const awfParts = AWF_CMD.split(/\s+/);
119+
child = spawn(
120+
awfParts[0],
121+
[...awfParts.slice(1), "--allow-domains", ALLOWED_DOMAIN, "--log-level", "error", "--", "sleep", "30"],
122+
{
123+
detached: true,
124+
stdio: "ignore",
125+
}
126+
);
127+
child.unref();
128+
129+
// Wait for Squid to be running and healthy
130+
await waitForContainers(["awf-squid"], 30_000);
131+
132+
// Measure HTTPS request latency through Squid's proxy port from the host
115133
const output = exec(
116-
`${AWF_CMD} --allow-domains ${ALLOWED_DOMAIN} --log-level error -- ` +
117-
`curl -fsS -o /dev/null -w '%{time_total}' https://${ALLOWED_DOMAIN}/zen`
134+
`curl -fsS -o /dev/null -w '%{time_total}' -x http://172.30.0.10:3128 https://${ALLOWED_DOMAIN}/zen`
118135
);
119136
const seconds = parseFloat(output);
120137
if (!isNaN(seconds)) {
121138
values.push(Math.round(seconds * 1000));
122139
}
123-
} catch {
124-
console.error(` Iteration ${i + 1}/${ITERATIONS}: failed (skipped)`);
125-
continue;
140+
console.error(` Iteration ${i + 1}/${ITERATIONS}: ${values[values.length - 1]}ms`);
141+
} catch (err) {
142+
console.error(` Iteration ${i + 1}/${ITERATIONS}: failed (skipped) - ${err}`);
143+
} finally {
144+
if (child) {
145+
killBackground(child);
146+
}
147+
cleanup();
126148
}
127-
console.error(` Iteration ${i + 1}/${ITERATIONS}: ${values[values.length - 1]}ms`);
128149
}
129150

130151
if (values.length === 0) {
@@ -294,7 +315,7 @@ async function main(): Promise<void> {
294315
results.push(benchmarkNetworkCreation());
295316
results.push(benchmarkWarmStart());
296317
results.push(benchmarkColdStart());
297-
results.push(benchmarkHttpsLatency());
318+
results.push(await benchmarkHttpsLatency());
298319
results.push(await benchmarkMemory());
299320

300321
// Final cleanup

0 commit comments

Comments
 (0)