2016-03-09 21:23:04 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-07-14 18:02:38 +00:00
|
|
|
"context"
|
2016-03-09 21:23:04 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"runtime"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
2019-09-09 21:06:12 +00:00
|
|
|
"testing"
|
2022-06-16 21:32:10 +00:00
|
|
|
"time"
|
2016-03-09 21:23:04 +00:00
|
|
|
|
2023-07-27 11:37:34 +00:00
|
|
|
"github.com/docker/docker/integration-cli/cli"
|
2020-02-07 13:39:24 +00:00
|
|
|
"gotest.tools/v3/assert"
|
2016-03-09 21:23:04 +00:00
|
|
|
)
|
|
|
|
|
2022-06-16 21:32:10 +00:00
|
|
|
type DockerBenchmarkSuite struct {
|
|
|
|
ds *DockerSuite
|
|
|
|
}
|
|
|
|
|
2023-07-14 18:02:38 +00:00
|
|
|
func (s *DockerBenchmarkSuite) TearDownTest(ctx context.Context, c *testing.T) {
|
|
|
|
s.ds.TearDownTest(ctx, c)
|
2022-06-16 21:32:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerBenchmarkSuite) OnTimeout(c *testing.T) {
|
|
|
|
s.ds.OnTimeout(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerBenchmarkSuite) BenchmarkConcurrentContainerActions(c *testing.B) {
|
2016-03-09 21:23:04 +00:00
|
|
|
maxConcurrency := runtime.GOMAXPROCS(0)
|
|
|
|
numIterations := c.N
|
|
|
|
outerGroup := &sync.WaitGroup{}
|
|
|
|
outerGroup.Add(maxConcurrency)
|
|
|
|
chErr := make(chan error, numIterations*2*maxConcurrency)
|
|
|
|
|
|
|
|
for i := 0; i < maxConcurrency; i++ {
|
|
|
|
go func() {
|
|
|
|
defer outerGroup.Done()
|
|
|
|
innerGroup := &sync.WaitGroup{}
|
|
|
|
innerGroup.Add(2)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
defer innerGroup.Done()
|
|
|
|
for i := 0; i < numIterations; i++ {
|
2019-07-08 16:42:08 +00:00
|
|
|
args := []string{"run", "-d", "busybox"}
|
2016-08-17 22:46:28 +00:00
|
|
|
args = append(args, sleepCommandForDaemonPlatform()...)
|
2016-03-09 21:23:04 +00:00
|
|
|
out, _, err := dockerCmdWithError(args...)
|
|
|
|
if err != nil {
|
|
|
|
chErr <- fmt.Errorf(out)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
id := strings.TrimSpace(out)
|
2021-08-24 10:10:50 +00:00
|
|
|
tmpDir, err := os.MkdirTemp("", "docker-concurrent-test-"+id)
|
2016-03-09 21:23:04 +00:00
|
|
|
if err != nil {
|
|
|
|
chErr <- err
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer os.RemoveAll(tmpDir)
|
|
|
|
out, _, err = dockerCmdWithError("cp", id+":/tmp", tmpDir)
|
|
|
|
if err != nil {
|
|
|
|
chErr <- fmt.Errorf(out)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
out, _, err = dockerCmdWithError("kill", id)
|
|
|
|
if err != nil {
|
|
|
|
chErr <- fmt.Errorf(out)
|
|
|
|
}
|
|
|
|
|
|
|
|
out, _, err = dockerCmdWithError("start", id)
|
|
|
|
if err != nil {
|
|
|
|
chErr <- fmt.Errorf(out)
|
|
|
|
}
|
|
|
|
|
|
|
|
out, _, err = dockerCmdWithError("kill", id)
|
|
|
|
if err != nil {
|
|
|
|
chErr <- fmt.Errorf(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 <- fmt.Errorf(out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
defer innerGroup.Done()
|
|
|
|
for i := 0; i < numIterations; i++ {
|
|
|
|
out, _, err := dockerCmdWithError("ps")
|
|
|
|
if err != nil {
|
|
|
|
chErr <- fmt.Errorf(out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
innerGroup.Wait()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
outerGroup.Wait()
|
|
|
|
close(chErr)
|
|
|
|
|
|
|
|
for err := range chErr {
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2016-03-09 21:23:04 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-16 21:32:10 +00:00
|
|
|
|
|
|
|
func (s *DockerBenchmarkSuite) BenchmarkLogsCLIRotateFollow(c *testing.B) {
|
2023-07-27 11:37:34 +00:00
|
|
|
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()
|
2022-06-16 21:32:10 +00:00
|
|
|
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 <- fmt.Errorf(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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|