Skip to content

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

Merged
dennwc merged 4 commits intolivekit:mainfrom
rafallezanko:main
Mar 11, 2026
Merged

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

Conversation

@rafallezanko
Copy link
Copy Markdown
Contributor

@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
Copy Markdown

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 234 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
@rafallezanko
Copy link
Copy Markdown
Contributor Author

Hi @dennwc are you able to review this change? Or call someone who can :) Thank you!

Copy link
Copy Markdown
Contributor

@alexlivekit alexlivekit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't look too deep into this one, but overall lgtm

@rafallezanko
Copy link
Copy Markdown
Contributor Author

Hi @alexlivekit, thank you! How does merging to main work for this repository? Will you merge? When do you have a plan to release a new version of SIP bridge?

Thank you :)

@rafallezanko
Copy link
Copy Markdown
Contributor Author

Hi @alexlivekit, thank you! How does merging to main work for this repository? Will you merge? When do you have a plan to release a new version of SIP bridge?

Thank you :)

Hi @alexlivekit @dennwc can you have a look at the comment please?

Copy link
Copy Markdown
Contributor

@dennwc dennwc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Apologies for the delay on our end.

@dennwc dennwc merged commit 2a711c7 into livekit:main Mar 11, 2026
5 checks passed
@rafallezanko
Copy link
Copy Markdown
Contributor Author

Great, thank you for merging! Do you have any release timeline for this project?

@alexlivekit
Copy link
Copy Markdown
Contributor

@rafallezanko , no immediate plans for releases as I understand. I'll ask around just in case.

On another note, related to this PR, this change in protocol actually drops the usage of this affinity function altogether. It is not yet propagated anywhere, but for future reference please make sure to use an appropriate version or a patched version that re-enabled this use.

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.

3 participants