Skip to content

optimize tunnel counting from O(n) SCAN to O(1)#30

Open
Khaleelhabeeb wants to merge 1 commit intooutray-tunnel:mainfrom
Khaleelhabeeb:perf(fix)optimize-tunnel-counting-from-O(n)-SCAN-to-O(1)
Open

optimize tunnel counting from O(n) SCAN to O(1)#30
Khaleelhabeeb wants to merge 1 commit intooutray-tunnel:mainfrom
Khaleelhabeeb:perf(fix)optimize-tunnel-counting-from-O(n)-SCAN-to-O(1)

Conversation

@Khaleelhabeeb
Copy link
Contributor

Maintain a global atomic counter (tunnel:global:online_count) that
gets incremented/decremented by TunnelRouter when tunnels come
online/offline.

  • Added GLOBAL_ONLINE_COUNT_KEY constant to TunnelRouter
  • Increment counter in persistTunnelState on successful registration
  • Decrement counter in unregisterTunnel
  • Updated cron job to read counter with GET instead of SCAN
  • Added fallback to SCAN for backward compatibility on first run
    This eliminates the expensive SCAN operation that iterates through
    all Redis keys, critical for scaling to thousands of active tunnels.

@vercel
Copy link

vercel bot commented Jan 14, 2026

@Khaleelhabeeb is attempting to deploy a commit to the Akinkunmi Team on Vercel.

A member of the Team first needs to authorize it.

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