# Slow-receiver webhook dispatch benchmark for the Cycles Events Service.
# Adapted from runcycles/cycles-server-events v0.1.25.32, tools/load-test (Apache License 2.0).
# Run `sh run-benchmark.sh`; see the comments there for single-deployment runs.
# Requires Docker Compose v2.17 or later. Publishes no host ports. The worker
# images are linux/amd64 only; ARM hosts run them under emulation.
services:
  redis:
    image: redis:7-alpine@sha256:6ab0b6e7381779332f97b8ca76193e45b0756f38d4c0dcda72dbb3c32061ab99
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 1s
      timeout: 2s
      retries: 20
  worker:
    image: ${EVENTS_IMAGE:-ghcr.io/runcycles/cycles-server-events:0.1.25.32}
    platform: linux/amd64
    environment:
      REDIS_HOST: redis
      # Benchmark-only settings: plaintext signing secrets and delivery to the
      # load container on the private network.
      WEBHOOK_SECRET_ALLOW_PLAINTEXT: "true"
      WEBHOOK_URL_GUARD_ALLOW_PRIVATE_NETWORKS: "true"
    depends_on:
      redis:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "wget", "-qO", "/dev/null", "http://localhost:9980/actuator/health/readiness"]
      interval: 2s
      timeout: 3s
      retries: 45
  load:
    build:
      context: .
      dockerfile_inline: |
        FROM python:3.12-slim@sha256:5b5fe805d367f8f5a359ded6ab2652b7f9a206453ee6ee789c0045ba6ec15016
        WORKDIR /load
        RUN pip install --no-cache-dir redis==5.2.1
        COPY dispatch.py .
        CMD ["python", "-u", "dispatch.py"]
    environment:
      LOAD_TENANTS: ${LOAD_TENANTS:-8}
      LOAD_HEALTHY_P95_LIMIT_MS: ${LOAD_HEALTHY_P95_LIMIT_MS:-0}
      LOAD_COUNT: ${LOAD_COUNT:-160}
      LOAD_RATE: ${LOAD_RATE:-20}
      LOAD_REPEATS: ${LOAD_REPEATS:-2}
      LOAD_SLOW_MS: ${LOAD_SLOW_MS:-500}
    depends_on:
      worker:
        condition: service_healthy
networks:
  default:
    internal: true
