[benchmarks] Update BenchmarkStartEmpty benchmark.

Update the start benchmark on empty to only "Start" a container, not wait
for its completion.

TL:DR only measure the actual start call for the empty container.

Previously, we were measuring the completion of /bin/true in container
alpine AND the cleanup. This was fine until profiling started failing all
the time on ptrace. This is a cost that runc is not paying.

These changes will reduce the over all timing of the benchmark, but it will
give more sane results.

Instead, use "Spawn" which is similar to `docker run --detach alpine
/bin/sleep 100`. Call sleep so containers stick around long enough
for the profiler to read profile data from them.

PiperOrigin-RevId: 390705431
This commit is contained in:
Zach Koopmans
2021-08-13 15:29:11 -07:00
committed by gVisor bot
parent 6eb8596f72
commit 868ed0e807
+8 -4
View File
@@ -34,15 +34,19 @@ func BenchmarkStartupEmpty(b *testing.B) {
defer machine.CleanUp()
ctx := context.Background()
b.StopTimer()
b.ResetTimer()
for i := 0; i < b.N; i++ {
harness.DebugLog(b, "Running container: %d", i)
container := machine.GetContainer(ctx, b)
defer container.CleanUp(ctx)
if _, err := container.Run(ctx, dockerutil.RunOpts{
b.StartTimer()
if err := container.Spawn(ctx, dockerutil.RunOpts{
Image: "benchmarks/alpine",
}, "true"); err != nil {
b.Fatalf("failed to run container: %v", err)
}, "sleep", "100"); err != nil {
b.Fatalf("failed to start container: %v", err)
}
b.StopTimer()
container.CleanUp(ctx)
harness.DebugLog(b, "Ran container: %d", i)
}
}