Ai
17 Star 91 Fork 2

Gitee 极速下载/docker

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/docker/docker/
克隆/下载
benchmark_test.go 2.86 KB
一键复制 编辑 原始数据 按行查看 历史
Paweł Gronowski 提交于 2025-12-16 01:26 +08:00 . modernize: Use range int
package main
import (
"context"
"errors"
"os"
"runtime"
"strings"
"sync"
"testing"
"time"
"github.com/moby/moby/v2/integration-cli/cli"
"gotest.tools/v3/assert"
)
type DockerBenchmarkSuite struct {
ds *DockerSuite
}
func (s *DockerBenchmarkSuite) TearDownTest(ctx context.Context, t *testing.T) {
s.ds.TearDownTest(ctx, t)
}
func (s *DockerBenchmarkSuite) OnTimeout(t *testing.T) {
s.ds.OnTimeout(t)
}
func (s *DockerBenchmarkSuite) BenchmarkConcurrentContainerActions(c *testing.B) {
maxConcurrency := runtime.GOMAXPROCS(0)
numIterations := c.N
outerGroup := &sync.WaitGroup{}
outerGroup.Add(maxConcurrency)
chErr := make(chan error, numIterations*2*maxConcurrency)
for range maxConcurrency {
go func() {
defer outerGroup.Done()
innerGroup := &sync.WaitGroup{}
innerGroup.Add(2)
go func() {
defer innerGroup.Done()
for range numIterations {
args := []string{"run", "-d", "busybox"}
args = append(args, sleepCommandForDaemonPlatform()...)
out, _, err := dockerCmdWithError(args...)
if err != nil {
chErr <- errors.New(out)
return
}
id := strings.TrimSpace(out)
tmpDir, err := os.MkdirTemp("", "docker-concurrent-test-"+id)
if err != nil {
chErr <- err
return
}
defer os.RemoveAll(tmpDir)
out, _, err = dockerCmdWithError("cp", id+":/tmp", tmpDir)
if err != nil {
chErr <- errors.New(out)
return
}
out, _, err = dockerCmdWithError("kill", id)
if err != nil {
chErr <- errors.New(out)
}
out, _, err = dockerCmdWithError("start", id)
if err != nil {
chErr <- errors.New(out)
}
out, _, err = dockerCmdWithError("kill", id)
if err != nil {
chErr <- errors.New(out)
}
// don't do an rm -f here since it can potentially ignore errors from the graphdriver
out, _, err = dockerCmdWithError("rm", id)
if err != nil {
chErr <- errors.New(out)
}
}
}()
go func() {
defer innerGroup.Done()
for range numIterations {
out, _, err := dockerCmdWithError("ps")
if err != nil {
chErr <- errors.New(out)
}
}
}()
innerGroup.Wait()
}()
}
outerGroup.Wait()
close(chErr)
for err := range chErr {
assert.NilError(c, err)
}
}
func (s *DockerBenchmarkSuite) BenchmarkLogsCLIRotateFollow(c *testing.B) {
out := cli.DockerCmd(c, "run", "-d", "--log-opt", "max-size=1b", "--log-opt", "max-file=10", "busybox", "sh", "-c", "while true; do usleep 50000; echo hello; done").Combined()
id := strings.TrimSpace(out)
ch := make(chan error, 1)
go func() {
ch <- nil
out, _, _ := dockerCmdWithError("logs", "-f", id)
// if this returns at all, it's an error
ch <- errors.New(out)
}()
<-ch
select {
case <-time.After(30 * time.Second):
// ran for 30 seconds with no problem
return
case err := <-ch:
if err != nil {
c.Fatal(err)
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mirrors/docker.git
git@gitee.com:mirrors/docker.git
mirrors
docker
docker
master

搜索帮助