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 with large file transfer #176

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ ARG GO_VERSION=1.22
ARG ALPINE_VERSION=3.20
ARG XX_VERSION=1.4.0

ARG BUILDKIT_VERSION=v0.16.0
ARG BUILDX_VERSION=v0.17.1
ARG BUILDKIT_VERSION=v0.17.1
ARG BUILDX_VERSION=v0.18.0
ARG REGISTRY_VERSION=v2.8.3

# named contexts
Expand Down
34 changes: 16 additions & 18 deletions cmd/refcandidates/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package main
import (
"encoding/json"
"log"
"math/rand"
"os"
"path/filepath"
"strings"
"time"

"github.com/alecthomas/kong"
"github.com/moby/buildkit-bench/util/candidates"
Expand Down Expand Up @@ -105,22 +103,22 @@ func setGhaOutput(name string, c *candidates.Candidates) error {
})
}

if gha.IsPullRequestEvent() {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
if len(includes) > 2 {
s := make([]include, 0, 2)
si := make(map[int]struct{})
for len(s) < 2 {
idx := r.Intn(len(includes))
if _, exists := si[idx]; !exists {
si[idx] = struct{}{}
s = append(s, includes[idx])
}
}
includes = s
}
log.Printf("Reducing candidates to %d for pull request event in GHA output", len(includes))
}
//if gha.IsPullRequestEvent() {
// r := rand.New(rand.NewSource(time.Now().UnixNano()))
// if len(includes) > 2 {
// s := make([]include, 0, 2)
// si := make(map[int]struct{})
// for len(s) < 2 {
// idx := r.Intn(len(includes))
// if _, exists := si[idx]; !exists {
// si[idx] = struct{}{}
// s = append(s, includes[idx])
// }
// }
// includes = s
// }
// log.Printf("Reducing candidates to %d for pull request event in GHA output", len(includes))
//}

dt, err := json.Marshal(includes)
if err != nil {
Expand Down
33 changes: 33 additions & 0 deletions test/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package test

import (
"fmt"
"math/rand"
"strings"
"sync"
"testing"
Expand Down Expand Up @@ -55,6 +56,7 @@ func BenchmarkBuild(b *testing.B) {
benchmarkBuildHighParallelization128x,
benchmarkBuildFileTransfer,
benchmarkBuildFileTransferCachedWithIteration,
benchmarkBuildLargeFileTransfer,
benchmarkBuildEmulator,
benchmarkBuildExportUncompressed,
benchmarkBuildExportGzip,
Expand Down Expand Up @@ -215,6 +217,37 @@ RUN du -sh . && tree .
})
}

func benchmarkBuildLargeFileTransfer(b *testing.B, sb testutil.Sandbox) {
dockerfile := []byte(`
FROM busybox:latest
WORKDIR /src
COPY . .
RUN du -sh .
`)

var contextDirLargeAppliers []fstest.Applier
contextDirLargeAppliers = append(contextDirLargeAppliers,
fstest.CreateDir("subdir9", 0755),
fstest.CreateFile("subdir9/largefile1.txt", make([]byte, 1024*1024*200), 0600), // 200MB file
fstest.CreateFile("subdir9/largefile2.txt", make([]byte, 1024*1024*400), 0600), // 400MB file
)
for i := 0; i < 10000; i++ {
fsize := rand.Intn(100*1024-5*1024) + 5*1024 // random size between 5KB and 100KB
contextDirLargeAppliers = append(contextDirLargeAppliers, fstest.CreateFile(fmt.Sprintf("subdir9/file%d.txt", i+5), make([]byte, fsize), 0600))
}
dir := tmpdir(b,
fstest.CreateFile("Dockerfile", dockerfile, 0600),
fstest.Apply(append(contextDirLargeAppliers, contextDirApplier)...),
)
reportBuildkitdAlloc(b, sb, func() {
b.StartTimer()
out, err := buildxBuildCmd(sb, withArgs(dir))
b.StopTimer()
sb.WriteLogFile(b, "buildx", []byte(out))
require.NoError(b, err, out)
})
}

func benchmarkBuildFileTransferCachedWithIteration(b *testing.B, sb testutil.Sandbox) {
dockerfile := []byte(`
FROM busybox:latest
Expand Down
10 changes: 10 additions & 0 deletions testconfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ runs:
alloc:
description: Allocated memory (bytes)
chart: boxplot
BenchmarkBuildLargeFileTransfer:
description: Build with large file transfer
count: 4
metrics:
duration:
description: Time (s)
chart: boxplot
alloc:
description: Allocated memory (bytes)
chart: boxplot
BenchmarkBuildEmulator:
description: Build with emulator
count: 10
Expand Down
Loading