Skip to content

Commit

Permalink
core/mount: add benchmark test for GetUsernsFD
Browse files Browse the repository at this point in the history
```bash
$ go test -bench=.  -benchmem ./ -exec sudo
goos: linux
goarch: amd64
pkg: github.com/containerd/containerd/v2/core/mount
cpu: AMD Ryzen 7 5800H with Radeon Graphics
BenchmarkBatchRunGetUsernsFD_Concurrent1-16                 2398            532424 ns/op            1145 B/op         43 allocs/op
BenchmarkBatchRunGetUsernsFD_Concurrent10-16                 343           3701695 ns/op           11552 B/op        421 allocs/op
PASS
ok      github.com/containerd/containerd/v2/core/mount  2.978s
```

Signed-off-by: Wei Fu <fuweid89@gmail.com>
  • Loading branch information
fuweid committed Aug 19, 2024
1 parent 0ecaec4 commit bcdf507
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions core/mount/mount_idmapped_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"os"
"path/filepath"
"sync"
"syscall"
"testing"

Expand All @@ -29,6 +30,34 @@ import (
"golang.org/x/sys/unix"
)

func BenchmarkBatchRunGetUsernsFD_Concurrent1(b *testing.B) {
for range b.N {
benchmarkBatchRunGetUsernsFD(1)
}
}

func BenchmarkBatchRunGetUsernsFD_Concurrent10(b *testing.B) {
for range b.N {
benchmarkBatchRunGetUsernsFD(10)
}
}

func benchmarkBatchRunGetUsernsFD(n int) {
var wg sync.WaitGroup
wg.Add(n)
for i := 0; i < n; i++ {
go func() {
defer wg.Done()
fd, err := getUsernsFD(testUIDMaps, testGIDMaps)
if err != nil {
panic(err)
}
fd.Close()
}()
}
wg.Wait()
}

var (
testUIDMaps = []syscall.SysProcIDMap{
{ContainerID: 1000, HostID: 0, Size: 100},
Expand Down

0 comments on commit bcdf507

Please sign in to comment.