Skip to content

Commit c04054a

Browse files
committed
get rid of dynamic scaling
1 parent 6fc0083 commit c04054a

File tree

4 files changed

+59
-21
lines changed

4 files changed

+59
-21
lines changed

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,19 @@ docker run --net=host --rm -v ./redis:/usr/local/etc/redis --name test-redis red
1414
pixi run serve
1515
```
1616

17-
### Option 2: Running Multiple API Replicas
17+
### Option 2: Docker Compose with Load Balancing
1818

19-
To run multiple instances of the Streaming API application with automatic load balancing:
19+
The project includes a Docker Compose configuration that sets up:
20+
- Redis server
21+
- 3 Streaming API instances (fixed configuration)
22+
- Traefik reverse proxy for load balancing
2023

24+
To start all services:
2125
```sh
22-
podman-compose up -d --scale streaming_api=3
26+
docker-compose up -d
27+
# or with podman
28+
podman-compose up -d
2329
```
24-
You can scale to any number of instances (e.g., `--scale streaming_api=5` for 5 instances).
25-
26-
**Note**: Scaling with `--scale` requires podman-compose 1.0.6+ or docker-compose.
2730

2831
#### Accessing the Services
2932

docker-compose.yml

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,12 @@ version: '3.8'
33
services:
44
traefik:
55
image: docker.io/library/traefik:v3.0
6-
command:
7-
- "--api.insecure=true"
8-
- "--providers.docker=true"
9-
- "--providers.docker.exposedbydefault=false"
10-
- "--entrypoints.web.address=:8000"
116
ports:
127
- "8000:8000"
138
- "8090:8080" # Traefik dashboard
149
volumes:
15-
- "/var/run/docker.sock:/var/run/docker.sock:ro"
16-
privileged: true
10+
- ./traefik.yml:/etc/traefik/traefik.yml:ro
11+
- ./traefik-routes.yml:/etc/traefik/conf/routes.yml:ro
1712

1813
redis:
1914
image: redis:7-alpine
@@ -28,7 +23,27 @@ services:
2823
timeout: 3s
2924
retries: 5
3025

31-
streaming_api:
26+
streaming_api-1:
27+
build: .
28+
environment:
29+
- REDIS_URL=redis://redis:6379/0
30+
depends_on:
31+
redis:
32+
condition: service_healthy
33+
volumes:
34+
- ./server.py:/app/server.py:ro
35+
36+
streaming_api-2:
37+
build: .
38+
environment:
39+
- REDIS_URL=redis://redis:6379/0
40+
depends_on:
41+
redis:
42+
condition: service_healthy
43+
volumes:
44+
- ./server.py:/app/server.py:ro
45+
46+
streaming_api-3:
3247
build: .
3348
environment:
3449
- REDIS_URL=redis://redis:6379/0
@@ -37,10 +52,3 @@ services:
3752
condition: service_healthy
3853
volumes:
3954
- ./server.py:/app/server.py:ro
40-
labels:
41-
- "traefik.enable=true"
42-
- "traefik.http.routers.streaming_api.rule=Host(`localhost`)"
43-
- "traefik.http.routers.streaming_api.entrypoints=web"
44-
- "traefik.http.services.streaming_api.loadbalancer.server.port=8000"
45-
deploy:
46-
replicas: 3

traefik-routes.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
http:
2+
routers:
3+
api:
4+
rule: "PathPrefix(`/`)"
5+
entryPoints:
6+
- web
7+
service: api-service
8+
9+
services:
10+
api-service:
11+
loadBalancer:
12+
servers:
13+
- url: "http://streaming_api-1:8000"
14+
- url: "http://streaming_api-2:8000"
15+
- url: "http://streaming_api-3:8000"

traefik.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Static configuration
2+
api:
3+
insecure: true
4+
dashboard: true
5+
6+
entryPoints:
7+
web:
8+
address: ":8000"
9+
10+
providers:
11+
file:
12+
directory: /etc/traefik/conf

0 commit comments

Comments
 (0)