Skip to content

Scaling based on a number of active calls fixed and filtering by sipTrunkId#598

Open
rafallezanko wants to merge 4 commits intolivekit:mainfrom
rafallezanko:main
Open

Scaling based on a number of active calls fixed and filtering by sipTrunkId#598
rafallezanko wants to merge 4 commits intolivekit:mainfrom
rafallezanko:main

Conversation

@rafallezanko
Copy link

@rafallezanko rafallezanko commented Feb 25, 2026

There was existing TODO to fix -> Scale outbound calls based on number or active calls.

Load-aware affinity routing and trunk whitelisting for SIP bridges

Summary

  • Implement CreateSIPParticipantAffinity to return a dynamic score based on the number of active calls (inbound + outbound),
    replacing the hardcoded 0.5. This enables psrpc to route new outbound calls to the least-loaded SIP bridge.
  • Add sip_trunk_ids config option to restrict a SIP bridge to only serve specific trunk IDs, enabling dedicated gateways per
    trunk.

Affinity algorithm

The function evaluates in order:

  1. Trunk whitelist (sip_trunk_ids) — if configured and the request's trunk ID is not in the list, return 0 immediately (this node
    will not claim the call).
  2. Capacity limit (max_active_calls) — if configured, return 1 - (active / max). Returns 0 when at or over capacity.
  3. Fallback (no max_active_calls) — return 1 / (1 + active). No hard cap, but nodes with fewer calls are always preferred.

Configuration

Optional: maximum number of concurrent calls this bridge should handle.
Affinity scales linearly from 1.0 (idle) to 0.0 (at capacity).
max_active_calls: 100

Optional: only accept outbound calls for these trunk IDs.
Calls for any other trunk will get affinity 0 (routed elsewhere).
If empty/unset, all trunks are accepted.
sip_trunk_ids:
- "ST_abc123"
- "ST_def456"

@rafallezanko rafallezanko requested a review from a team as a code owner February 25, 2026 08:00
@codecov
Copy link

codecov bot commented Feb 25, 2026

Codecov Report

❌ Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 63.07%. Comparing base (0460b40) to head (cfd3770).
⚠️ Report is 229 commits behind head on main.

Files with missing lines Patch % Lines
pkg/sip/service.go 87.50% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #598      +/-   ##
==========================================
- Coverage   65.25%   63.07%   -2.18%     
==========================================
  Files          51       35      -16     
  Lines        6588     6920     +332     
==========================================
+ Hits         4299     4365      +66     
- Misses       1915     2128     +213     
- Partials      374      427      +53     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rafallezanko rafallezanko changed the title Scaling based on a number of active calls fixed Scaling based on a number of active calls fixed and filtering by sipTrunkId Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant