core/mount: add benchmark test for GetUsernsFD
```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>
This commit is contained in:
parent
0ecaec4dde
commit
bcdf507363
@ -20,6 +20,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
@ -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},
|
||||
|
Loading…
Reference in New Issue
Block a user