Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: build export with compression #146

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 56 additions & 20 deletions test/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (

const dockerfileImagePin = "docker/dockerfile:1.9.0"

var contextDirApplier fstest.Applier

func BenchmarkBuild(b *testing.B) {
mirroredImages := testutil.OfficialImages(
"busybox:latest",
Expand All @@ -23,6 +25,25 @@ func BenchmarkBuild(b *testing.B) {
mirroredImages[dockerfileImagePin] = "docker.io/" + dockerfileImagePin
mirroredImages["amd64/busybox:latest"] = "docker.io/amd64/busybox:latest"
mirroredImages["arm64v8/busybox:latest"] = "docker.io/arm64v8/busybox:latest"

var contextDirAppliers []fstest.Applier
contextDirAppliers = append(contextDirAppliers,
fstest.CreateDir("subdir1", 0755),
fstest.CreateFile("subdir1/file1.txt", []byte("foo"), 0600),
fstest.CreateFile("subdir1/file2.txt", make([]byte, 1024*1024), 0600), // 1MB file
fstest.CreateDir("subdir1/subdir2", 0755),
fstest.CreateFile("subdir1/subdir2/file3.txt", []byte("bar"), 0600),
fstest.CreateFile("subdir1/subdir2/file4.txt", make([]byte, 1024*1024*10), 0600), // 10MB file
)
for i := 0; i < 5000; i++ {
contextDirAppliers = append(contextDirAppliers, fstest.CreateFile(fmt.Sprintf("subdir1/file%d.txt", i+5), []byte("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."), 0600))
}
contextDirAppliers = append(contextDirAppliers,
fstest.CreateFile("subdir1/largefile1.txt", make([]byte, 1024*1024*50), 0600), // 50MB file
fstest.CreateFile("subdir1/largefile2.txt", make([]byte, 1024*1024*100), 0600), // 100MB file
)
contextDirApplier = fstest.Apply(contextDirAppliers...)

testutil.Run(b, testutil.BenchFuncs(
benchmarkBuildSimple,
benchmarkBuildMultistage,
Expand All @@ -34,6 +55,10 @@ func BenchmarkBuild(b *testing.B) {
benchmarkBuildHighParallelization128x,
benchmarkBuildFileTransfer,
benchmarkBuildEmulator,
benchmarkBuildExportUncompressed,
benchmarkBuildExportGzip,
benchmarkBuildExportEstargz,
//benchmarkBuildExportZstd, https://github.com/moby/buildkit-bench/pull/146#discussion_r1771519112
), testutil.WithMirroredImages(mirroredImages))
}

Expand Down Expand Up @@ -133,7 +158,7 @@ RUN cp /etc/foo /etc/bar
fstest.CreateFile("Dockerfile", dockerfile, 0600),
fstest.CreateFile("foo", []byte("foo"), 0600),
)
out, err := buildxBuildCmd(sb, withArgs(dir))
out, err := buildxBuildCmd(sb, withArgs("--output=type=image", dir))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks to be an oversight from me during rebase 😞

// TODO: use sb.WriteLogFile to write buildx logs in a defer with a
// semaphore using a buffered channel to limit the number of
// concurrent goroutines. This might affect timing.
Expand All @@ -146,23 +171,6 @@ RUN cp /etc/foo /etc/bar
}

func benchmarkBuildFileTransfer(b *testing.B, sb testutil.Sandbox) {
var appliers []fstest.Applier
appliers = append(appliers,
fstest.CreateDir("subdir1", 0755),
fstest.CreateFile("subdir1/file1.txt", []byte("foo"), 0600),
fstest.CreateFile("subdir1/file2.txt", make([]byte, 1024*1024), 0600), // 1MB file
fstest.CreateDir("subdir1/subdir2", 0755),
fstest.CreateFile("subdir1/subdir2/file3.txt", []byte("bar"), 0600),
fstest.CreateFile("subdir1/subdir2/file4.txt", make([]byte, 1024*1024*10), 0600), // 10MB file
)
for i := 0; i < 5000; i++ {
appliers = append(appliers, fstest.CreateFile(fmt.Sprintf("subdir1/file%d.txt", i+5), []byte("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."), 0600))
}
appliers = append(appliers,
fstest.CreateFile("subdir1/largefile1.txt", make([]byte, 1024*1024*50), 0600), // 50MB file
fstest.CreateFile("subdir1/largefile2.txt", make([]byte, 1024*1024*100), 0600), // 100MB file
)

dockerfile := []byte(`
FROM busybox:latest
WORKDIR /src
Expand All @@ -171,9 +179,8 @@ RUN du -sh . && tree .
`)
dir := tmpdir(b,
fstest.CreateFile("Dockerfile", dockerfile, 0600),
fstest.Apply(appliers...),
contextDirApplier,
)

b.StartTimer()
out, err := buildxBuildCmd(sb, withArgs(dir))
b.StopTimer()
Expand Down Expand Up @@ -217,3 +224,32 @@ RUN uname -a
sb.WriteLogFile(b, "buildx", []byte(out))
require.NoError(b, err, out)
}

func benchmarkBuildExportUncompressed(b *testing.B, sb testutil.Sandbox) {
benchmarkBuildExport(b, sb, "uncompressed")
}
func benchmarkBuildExportGzip(b *testing.B, sb testutil.Sandbox) {
benchmarkBuildExport(b, sb, "gzip")
}
func benchmarkBuildExportEstargz(b *testing.B, sb testutil.Sandbox) {
benchmarkBuildExport(b, sb, "gzip")
}
func benchmarkBuildExportZstd(b *testing.B, sb testutil.Sandbox) {
benchmarkBuildExport(b, sb, "zstd")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zstd compression in available since v0.10.0 so it fails for older refs like: https://github.com/moby/buildkit-bench/actions/runs/10995084553/job/30525242309?pr=146#step:8:139

BenchmarkBuild/BenchmarkBuildExportZstd/ref=v0.9.0/run=1
    build_test.go:254: 
        	Error Trace:	/src/test/build_test.go:254
        	            				/src/test/build_test.go:238
        	            				/src/util/testutil/run.go:127
        	            				/src/util/testutil/run.go:253
        	            				/src/util/testutil/run.go:258
        	            				/src/util/testutil/run.go:280
        	            				/usr/local/go/src/testing/benchmark.go:193
        	            				/usr/local/go/src/testing/benchmark.go:215
        	            				/usr/local/go/src/runtime/asm_amd64.s:1695
        	Error:      	Received unexpected error:
        	            	exit status 1
        	Test:       	BenchmarkBuild/BenchmarkBuildExportZstd/ref=v0.9.0/run=1
        	Messages:   	ERROR: failed to solve: unsupported layer compression type: zstd

I will disable this benchmark for now but we could solve this with #120 or patches if that makes sense

}
func benchmarkBuildExport(b *testing.B, sb testutil.Sandbox, compression string) {
dockerfile := []byte(`
FROM python:latest
WORKDIR /src
COPY . .
`)
dir := tmpdir(b,
fstest.CreateFile("Dockerfile", dockerfile, 0600),
contextDirApplier,
)
b.StartTimer()
out, err := buildxBuildCmd(sb, withArgs("--output=type=image,compression="+compression, dir))
b.StopTimer()
sb.WriteLogFile(b, "buildx", []byte(out))
require.NoError(b, err, out)
}
28 changes: 28 additions & 0 deletions testconfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,34 @@ runs:
duration:
description: Time (s)
chart: boxplot
BenchmarkBuildExportUncompressed:
description: Build export uncompressed
count: 4
metrics:
duration:
description: Time (s)
chart: boxplot
BenchmarkBuildExportGzip:
description: Build export gzip
count: 4
metrics:
duration:
description: Time (s)
chart: boxplot
BenchmarkBuildExportEstargz:
description: Build export estargz
count: 4
metrics:
duration:
description: Time (s)
chart: boxplot
# BenchmarkBuildExportZstd:
# description: Build export zstd
# count: 4
# metrics:
# duration:
# description: Time (s)
# chart: boxplot

BenchmarkDaemon:
BenchmarkDaemonVersion:
Expand Down
Loading