Discovery is VERY slow when using swarmmode

I'm getting really slow discovery times any time I use swarm mode. It takes 10-30s for Traefik to pick up the routing rules.

See a reproducible example here

To reproduce, follow these steps, and then refresh Traefik's router page until you see the Host rule for whoami.

What is going on? Any idea how to fix this?

> docker stack deploy --compose-file docker-compose.yml test-stack
version: '3'

services:
  reverse-proxy:
    # The official v2 Traefik docker image
    image: traefik:v2.10
    # Enables the web UI and tells Traefik to listen to docker
    command:
      - --api.insecure=true
      - --providers.docker
      - --providers.docker.swarmmode=true
    ports:
      # The HTTP port
      - "80:80"
      # The Web UI (enabled by --api.insecure=true)
      - "8080:8080"
    volumes:
      # So that Traefik can listen to the Docker events
      - /var/run/docker.sock:/var/run/docker.sock

  whoami:
    # A container that exposes an API to show its IP address
    image: traefik/whoami
    deploy:
      labels:
        - "traefik.http.routers.whoami.rule=Host(`whoami.docker.localhost`)"
        - "traefik.http.services.whoami.loadbalancer.server.port=80"

Traefik pulls the info from Docker Swarm in intervals. So I would think around 20 secs is normal. (Doc)

swarmModeRefreshSeconds
Optional, Default=15

Well that explains what I'm seeing. Thank you!

During Docker service update you should set --update-delay accordingly (doc), to not have the situation of no active target service instance be known to Traefik. That would kill HA.