mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #6387] [Feature]: Add support for priority/preferential outgoing requests for load balancers. #4333
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#4333
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ad0mant on GitHub (Sep 2, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6387
Is your feature request related to a problem?
When creating/editing a load balancer, add the optional parameter Outgoing traffic priority.
Describe the solution you'd like
Balancer
Outgoing traffic:
[ Server A ]
[ Server B ]
[ Server C ]
[ Server D ]
Outgoing traffic priority:
[ Server A ]
Priority RTT threshold:
[ 300 ] ms
Alternatives you've considered
Current workaround
Currently, I can achieve similar behavior by creating a separate balancer for each user and using another balancer as a backup.
For example:
Balancer User 1
Selector: A
Backup: General balancer
General balancer
Selectors: A, B, C, D
Strategy: Least load
However, this requires backup switching between balancers and a feedback mechanism.
3x-ui issues a warning:
Traffic will be routed as follows: Balancer → Feedback → Server → Target balancer → Outgoing connection.
This works, but it’s overly complex for such a simple use case as “preferred server → backup pool”.
Concrete use case
For example:
Outgoing traffic priority: Server A
Fallback option: General load balancer
RTT threshold: 300 ms
Behavior:
If server A is available and its RTT is below 300 ms → use server A.
If server A is unavailable → use the backup load balancer.
If the RTT of server A exceeds 300 ms → use the backup load balancer.
Then, the backup balancer selects an available server in accordance with its configured strategy, for example, “Least Load.”
The RTT threshold should be optional. If it is disabled, switching to the backup server should occur only when the outgoing traffic priority is considered unavailable..
This would allow for a simple configuration, for example:
User 1 → Balancer 1
Priority: Server A
User 2 → Load Balancer 2
Priority: Server B
User 3 → Load Balancer 3
Priority: Server C
Mockups, screenshots, or examples
No response
Which parts of the panel would this affect?
Frontend (UI / panel pages)
Are you willing to help?
Before submitting
@github-actions[bot] commented on GitHub (Sep 2, 2026):
Thanks for the detailed write-up — this is a valid feature request, but almost everything you describe is already expressible with fields the Balancer form ships today, so what is actually missing is a shortcut in the UI rather than new routing capability. Details below, with the caveat that one of the knobs (
costs) has a semantic I could not verify from this repository.What already exists
The balancer object the panel writes is Xray-core's own shape —
tag,selector,fallbackTag,strategy: { type, settings }and nothing else. Seefrontend/src/pages/xray/balancers/BalancersTab.tsx:235-238:and the schema at
frontend/src/schemas/routing.ts:69-75.RTT threshold — this is
settings.maxRTT, already in the form as Max RTT (frontend/src/pages/xray/balancers/BalancerFormModal.tsx:295-304, label"maxRtt": "Max RTT"atinternal/web/translation/en-US.json:1896, schemamaxRTT: z.string().optional()atfrontend/src/schemas/routing.ts:56). The field is a free-form Xray duration string — the placeholder ise.g. 1s, and the panel does not validate it, so300msgoes through as typed.Preferring one member — this is
settings.costs, already in the form as Costs, with a per-entry Tag pattern, Weight and a literal/regex switch (BalancerFormModal.tsx:353-418;internal/web/translation/en-US.json:1899-1902; schemafrontend/src/schemas/routing.ts:47-51).Per-user mapping — routing rules already match on the client, so “User 1 → Balancer 1” needs no new mechanism:
RuleObjectSchemahasuser: z.array(z.string()).optional()(frontend/src/schemas/routing.ts:26) and the rule form exposes it as User (frontend/src/pages/xray/routing/RuleFormModal.tsx:299-311,internal/web/translation/en-US.json:1706).So your use case collapses into a single balancer, no second balancer and no fallback hop:
Two constraints worth knowing before you try it:
settingsis kept only for Least load —BalancerFormModal.tsx:193is literallyif (result.strategy !== 'leastLoad') delete result.settings;, so an RTT threshold is not available on Random / Round-robin.burstObservatory, but you do not have to create one: the panel adds and removes it for you from your balancer strategies (frontend/src/pages/xray/balancers/balancer-helpers.ts:62-85, and the Observatory tab says so —internal/web/translation/en-US.json:1849).What I could not determine: the direction of the
costsweight — whether a lower or a highervaluemakes a tag more preferred. That is decided inside Xray-core'sleastLoadstrategy, which is a Go module dependency and is not part of this checkout, so I will not guess at it. You can settle it in one step on a live panel: set a weight onA, then read back which member the balancer is actually picking — the panel queries the running core for that (balancerStatusininternal/web/controller/xray_setting.go:366-386, "reports the live state (override + strategy picks)"). If the preference lands the wrong way, invert the weight.About the message you quoted
That is an informational notice, not a warning about a misconfiguration —
"balancerFallbackInfo"atinternal/web/translation/en-US.json:1889. It appears only when the fallback you pick is another balancer (BalancerFormModal.tsx:167-170and:265-272). The reason is that Xray'sfallbackTagnames an outbound, not a balancer, so to chain to a balancer the panel synthesizes aloopbackoutbound plus a routing rule —ensureBalancerLoopbackatfrontend/src/pages/xray/balancers/balancer-loopback.ts:71-109:Picking a plain outbound tag as the fallback instead adds no loopback and no extra hop (
BalancerFormModal.tsx:140-165).What is genuinely new here
A first-class “priority member + threshold” control that compiles down to
selector+maxRTT+costs, so an operator does not have to know theleastLoadtuning fields to express “prefer A, fall back to the pool”. That is a reasonable UI ask and I have left theenhancementlabel in place.One correction to the scoping in your report: you selected Frontend (UI / panel pages) only. A new balancer key cannot be frontend-only — the panel hands
routingthrough to Xray-core as raw JSON, so apriorityfield would either have to be understood by Xray-core upstream, or be a panel-side control that emits the existing Xray fields.Related but not duplicates, so I am leaving this issue open and separate: #6355 (chained balancers — a second balancing stage on the selected node) and #6305 (routing rules inside the client/subscription balancer).
Verdict: Feature request
This reply was generated automatically; a maintainer may follow up.
@ad0mant commented on GitHub (Sep 2, 2026):
Could you please tell me if I understood this correctly: we create a load balancer, select the least load mode, and choose the selectors.
In the costs parameters, we specify the cost of our servers. In the end, this means that with this load balancer, traffic will first go to the server with a cost of 10; if its RTT is exceeded, it will switch to the next one, which has a cost of 7, and so on?
P.S. This setting isn’t working as expected; I’m constantly being redirected to different servers — I’m checking it via 2ip.io.