Skip to content

Instantly share code, notes, and snippets.

@testillano
Last active April 16, 2024 12:45
Show Gist options
  • Save testillano/3f7ff732850f42a6e7ee625aa182e617 to your computer and use it in GitHub Desktop.
Save testillano/3f7ff732850f42a6e7ee625aa182e617 to your computer and use it in GitHub Desktop.
http2 load balancer using docker-compose
version: '3'
services:
h2a:
image: ghcr.io/testillano/h2agent_http1:4.2.5
hostname: h2a
#expose:
# - "8001"
ports:
# Ephemeral (use 'docker-compose ps' to see them)
- "8001"
- "8074"
volumes:
- ./matching.json:/conf/matching.json
- ./provision.json:/conf/provision.json
#command: ["-l", "Debug", "--verbose"]
command: ["--traffic-server-matching", "/conf/matching.json", "--traffic-server-provision", "/conf/provision.json"]
nginx:
image: nginx:latest
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
- h2a
ports:
- "8006:8006"
networks:
default:
driver: bridge
{
"algorithm": "FullMatching"
}
worker_processes 100;
events {
worker_connections 2048;
}
http {
upstream backend {
server h2a:8001;
}
access_log off;
server {
listen 8006;
http2 on;
location / {
#proxy_pass http://h2a:8001;
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
proxy_read_timeout 300s;
proxy_connect_timeout 120s;
}
}
}
{
"requestMethod": "GET",
"responseCode": 200,
"responseDelayMs": 10
}
@testillano
Copy link
Author

  1. Requirements: docker, docker-compose
  2. Copy all the files above under a local directory
  3. Run by mean: docker-compose up --scale h2a=2
  4. Test by mean: h2load -n1000 -c10 -m100 "http://localhost:8006/the/path"

Notes: NGINX is not capable to act as http2 client towards backend, so this must be HTTP/1.1. So, we need to use h2agent_http1 image instead of h2agent, because we need HTTP1 support for this server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment