HTTP Server Configuration
Configure the HTTP server that handles SSE connections.
Configuration Options
bind_address
The address and port to listen on.
| Value | Description |
|---|---|
0.0.0.0:8080 |
Listen on all interfaces, port 8080 |
127.0.0.1:8080 |
Listen on localhost only |
192.168.1.10:8080 |
Listen on specific interface |
max_connections
Maximum number of concurrent client connections.
When the limit is reached, new connections receive 503 Service Unavailable.
Considerations:
- Each connection uses ~2KB of memory
- Set based on available RAM and file descriptors
- Monitor connections_active metric
connection_timeout_sec
Time in seconds before idle connections are closed.
Recommendations: - Mobile clients: 60-120 seconds (battery considerations) - Web clients: 300-600 seconds - Internal services: 3600+ seconds
keepalive_interval_sec
Interval for sending SSE keepalive comments.
Keepalives prevent: - Proxy/load balancer timeouts - Client connection detection issues - NAT table expiration
Format sent to clients:
max_message_queue_size
Maximum pending messages per connection.
When the queue is full, backpressure_policy determines behavior.
thread_pool_size
Number of worker threads for handling connections.
| Value | Behavior |
|---|---|
0 |
Auto-detect (recommended) |
N |
Use exactly N threads |
Guidelines: - CPU-bound: Match CPU core count - I/O-bound: 2x CPU core count - Memory-constrained: Reduce threads
Request Size Limits
Protect against malicious requests:
[http]
max_request_line_size = 8192 # Maximum URL length
max_header_size = 8192 # Maximum single header size
max_headers = 100 # Maximum number of headers
Requests exceeding limits receive 413 Request Entity Too Large.
Rate Limiting
Per-IP rate limiting configuration:
[http]
rate_limit_per_ip = 100 # Requests per window
rate_limit_window_sec = 60 # Window duration in seconds
Example: 100 requests per 60 seconds = ~1.67 requests/second average
Clients exceeding the limit receive 429 Too Many Requests.
Tip
Set higher limits for trusted internal networks using a reverse proxy.
cors_allowed_origins
CORS (Cross-Origin Resource Sharing) configuration:
[http]
cors_allowed_origins = "*" # Allow all origins
# cors_allowed_origins = "https://app.example.com" # Specific origin
Response headers set:
Access-Control-Allow-Origin: <configured-value>
Access-Control-Allow-Methods: GET, OPTIONS
Access-Control-Allow-Headers: Authorization, Content-Type
backpressure_policy
Behavior when message queue is full:
| Policy | Behavior | Use Case |
|---|---|---|
drop_newest |
Reject new messages | Prefer historical data |
drop_oldest |
Remove oldest messages | Prefer latest data |
block |
Wait for queue space | Guaranteed delivery |
Performance Tuning
High Connection Count
For 100k+ connections:
[http]
bind_address = "0.0.0.0:8080"
max_connections = 500000
thread_pool_size = 32
max_message_queue_size = 100
keepalive_interval_sec = 60
System tuning required:
# Increase file descriptor limit
ulimit -n 1000000
# Kernel parameters
sysctl -w net.core.somaxconn=65535
sysctl -w net.ipv4.tcp_max_syn_backlog=65535
Low Latency
For minimal message latency:
[http]
thread_pool_size = 0 # Match CPU cores
max_message_queue_size = 10 # Small queue
backpressure_policy = "drop_oldest"
Memory Constrained
For limited memory environments:
Example Configurations
Development
[http]
bind_address = "127.0.0.1:8080"
max_connections = 100
connection_timeout_sec = 3600
keepalive_interval_sec = 60
rate_limit_per_ip = 1000
cors_allowed_origins = "*"
Production
[http]
bind_address = "0.0.0.0:8080"
max_connections = 100000
connection_timeout_sec = 300
keepalive_interval_sec = 30
max_message_queue_size = 500
thread_pool_size = 0
max_request_line_size = 4096
max_header_size = 4096
max_headers = 50
rate_limit_per_ip = 100
rate_limit_window_sec = 60
cors_allowed_origins = "https://app.example.com"
backpressure_policy = "drop_newest"
Monitoring
Key metrics to monitor:
| Metric | Description | Alert Threshold |
|---|---|---|
connections_active |
Current connections | > 80% of max |
connections_rejected |
Rejected connections | > 0 sustained |
queue_depth |
Message queue size | > 80% of max |
rate_limit_hits |
Rate limit triggers | Unusual spikes |