compose: [BUG] Severe performance degradation of all commands with versions >=2.24.4 (incl. 2.25.0)

Description

Starting with version 2.24.4 I observe a noticeable and severe performance degradation with all docker compose commands.

We have a pretty sizable project with over 100 containers, in case that helps paint a better picture.

Steps To Reproduce

A big project with all containers stopped (assuming that even matters).

For versions <= 2.24.3

$ time docker compose ps
NAME      IMAGE     COMMAND   SERVICE   CREATED   STATUS    PORTS


real	0m0.423s
user	0m0.478s
sys	0m0.134s

With version >= 2.24.4:

$ time docker compose ps
NAME      IMAGE     COMMAND   SERVICE   CREATED   STATUS    PORTS


real	0m8.815s
user	0m13.045s
sys	0m0.358s

The delay (~8s) is observed before any output is produced and regardless of which command is ran. I cannot reproduce the slowness with a simple test project of a couple of containers.

Happy to provide more information that can help hunt this down.

Compose Version

Docker Compose version v2.24.4
Docker Compose version v2.24.5
Docker Compose version v2.24.6
Docker Compose version v2.24.7
Docker Compose version v2.25.0

Docker Environment

Client:
 Version:    24.0.7
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  0.12.0
    Path:     /usr/lib/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.24.3
    Path:     /home/xxx/.docker/cli-plugins/docker-compose

Server:
 Containers: 2121
  Running: 1
  Paused: 0
  Stopped: 2120
 Images: 910
 Server Version: 24.0.7
 Storage Driver: overlay2
  Backing Filesystem: btrfs
  Supports d_type: true
  Using metacopy: true
  Native Overlay Diff: false
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 64b8a811b07ba6288238eefc14d898ee0b5b99ba.m
 runc version: 
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.1.71-1
 Operating System: xxx
 OSType: linux
 Architecture: x86_64
 CPUs: 12
 Total Memory: 31.01GiB
 Name: xxx
 ID: xxx
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Username: xxx
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Anything else?

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 26 (5 by maintainers)

Most upvoted comments

The issue has been introduced by the change: https://github.com/compose-spec/compose-go/pull/546

It can be reproduced with this compose.yaml file.

Running docker compose config on my machine takes with

I created the custom 2.25.0 build without https://github.com/compose-spec/compose-go/pull/546 in the following way:

  • Checkout compose.git v2.25.0
  • run: go mod vendor
  • Apply the following change:
    diff --git a/vendor/github.com/compose-spec/compose-go/v2/loader/validate.go b/vendor/github.com/compose-spec/compose-go/v2/loader/validate.go
    index c5133f963..aa1e67192 100644
    --- a/vendor/github.com/compose-spec/compose-go/v2/loader/validate.go
    +++ b/vendor/github.com/compose-spec/compose-go/v2/loader/validate.go
    @@ -76,12 +76,6 @@ func checkConsistency(project *types.Project) error {
                                    return fmt.Errorf("service %q depends on undefined service %q: %w", s.Name, dependedService, errdefs.ErrInvalid)
                            }
                    }
    -               // Check there isn't a cycle in depends_on declarations
    -               if err := graph.InDependencyOrder(context.Background(), project, func(ctx context.Context, s string, config types.ServiceConfig) error {
    -                       return nil
    -               }); err != nil {
    -                       return err
    -               }
    
                    if strings.HasPrefix(s.NetworkMode, types.ServicePrefix) {
                            serviceName := s.NetworkMode[len(types.ServicePrefix):]
    
  • build a new compose binary: go build -o compose cmd/main.go

Yeah 🎉 Thanks @ndeloof for taking care of this when I was away 🙏🤗

I can confirm removing this check has a mass impact on performance. There’s something wrong with InDependencyOrder implementation, I’ll look into it

$ time (source .envrc; docker ps &>/dev/null)

real	0m0.058s
user	0m0.017s
sys	0m0.016s

$ time (source .envrc; docker compose ps &>/dev/null)

real	0m9.797s
user	0m14.592s
sys	0m0.327s

$ time (source .envrc; docker --tls=false compose ps &>/dev/null)

real	0m9.856s
user	0m14.742s
sys	0m0.289s

@glours I can confirm the correct version is being used:

$ docker compose version
Docker Compose version v2.24.6

$ ~/.docker/cli-plugins/docker-compose version
Docker Compose version v2.24.6

Hey @nocive @dave-shawley Can both of you share the result of docker compose version? I wanted to be sure you don’t have a old version of Compose taking precedence to the latest one installed because docker info tell you the version of the detected Compose plugin but there is not guarantee this is the Compose binary that will be used. To let you know, I tried to reproduce on my Mac M1 with Desktop in both admin/non-admin mode and with an Unbuntu 23.10 VM without any success

FWIW I’m seeing the same behavior with v2.24.3-desktop.1 and v2.24.6 on an Apple M2 laptop

Docker Compose version v2.24.6

Client:
 Cloud integration: v1.0.35+desktop.10
 Version:           25.0.2
 API version:       1.44
 Go version:        go1.21.6
 Git commit:        29cf629
 Built:             Thu Feb  1 00:18:45 2024
 OS/Arch:           darwin/arm64
 Context:           desktop-linux

Server: Docker Desktop 4.27.1 (136059)
 Engine:
  Version:          25.0.2
  API version:      1.44 (minimum version 1.24)
  Go version:       go1.21.6
  Git commit:       fce6e0c
  Built:            Thu Feb  1 00:23:21 2024
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.6.28
  GitCommit:        ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

This is reproducible with a simple compose.yaml and any docker compose sub-command. The following docker compose config took 8 seconds. The interesting thing is that it seems to be sleeping or doing whatever it is up to after the output is printed.

$ time docker compose config
name: asdf
services:
  nginx:
    image: nginx:1.24-alpine
    networks:
      default: null
    ports:
      - mode: ingress
        target: 80
        protocol: tcp
networks:
  default:
    name: asdf_default
docker compose config  0.08s user 0.03s system 5% cpu 2.106 total