Skip to content

Proxy: Make Redis and Memory LB TTL configurable#4650

Open
liukun4515 wants to merge 1 commit intoossrs:developfrom
liukun4515:feature/issue-4647-configurable-redis-ttl
Open

Proxy: Make Redis and Memory LB TTL configurable#4650
liukun4515 wants to merge 1 commit intoossrs:developfrom
liukun4515:feature/issue-4647-configurable-redis-ttl

Conversation

@liukun4515
Copy link
Copy Markdown

Summary

Fixes #4647

Makes the hardcoded TTL values in Redis and Memory load balancers configurable through environment variables, allowing customers to adjust them based on their scenarios.

Problem

Currently, the TTL values are hardcoded:

  • ServerAliveDuration = 300s (5 minutes)
  • HLSAliveDuration = 120s (2 minutes)
  • RTCAliveDuration = 120s (2 minutes)

For some scenarios, 300 seconds is too long, and customers need the ability to configure these values.

Solution

Added three new configurable environment variables:

  • PROXY_SERVER_ALIVE_DURATION (default: 300s)
  • PROXY_HLS_ALIVE_DURATION (default: 120s)
  • PROXY_RTC_ALIVE_DURATION (default: 120s)

Usage Examples

Reduce server TTL to 60 seconds:

PROXY_SERVER_ALIVE_DURATION=60s ./srs-proxy

Custom TTL for all values:

PROXY_SERVER_ALIVE_DURATION=180s \
PROXY_HLS_ALIVE_DURATION=90s \
PROXY_RTC_ALIVE_DURATION=90s \
./srs-proxy

Changes

  1. env.go: Added three new methods to Environment interface and their implementations
  2. lb.go: Replaced hardcoded constants with configurable helper functions
  3. mem.go: Updated MemoryLoadBalancer.Pick() to use configurable duration
  4. redis.go: Updated RedisLoadBalancer to use configurable TTL for all Redis keys

Testing

  • ✅ Code compiles successfully
  • ✅ All TTL values are logged on startup for visibility
  • ✅ Defaults match previous hardcoded values (backward compatible)

Files Changed

  • proxy/internal/env/env.go: +27, -1
  • proxy/internal/lb/lb.go: +28, -6
  • proxy/internal/lb/mem.go: +5, -1
  • proxy/internal/lb/redis.go: +19, -5

🤖 Generated with Claude Code

Fixes ossrs#4647

Changed hardcoded TTL constants to configurable environment variables:
- PROXY_SERVER_ALIVE_DURATION (default: 300s)
- PROXY_HLS_ALIVE_DURATION (default: 120s)
- PROXY_RTC_ALIVE_DURATION (default: 120s)

This allows customers to adjust TTL values based on their scenarios.

Changes:
- Added three new environment variable getters in env.Environment interface
- Replaced hardcoded constants with configurable helper functions
- Updated MemoryLoadBalancer.Pick() to use configurable server alive duration
- Updated RedisLoadBalancer TTL for server, HLS, and RTC keys
- Added TTL values to startup logs for visibility
@winlinvip winlinvip added the EnglishNative This issue is conveyed exclusively in English. label Mar 18, 2026
@winlinvip winlinvip force-pushed the develop branch 2 times, most recently from 70f14fc to ebf8b71 Compare March 22, 2026 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

EnglishNative This issue is conveyed exclusively in English.

Development

Successfully merging this pull request may close these issues.

The Redis TTL specified by the customer in the proxy

2 participants