[GH-ISSUE #5195] [Feature]: Per-Client Speed Limit (Bandwidth Throttling in KB/s or MB/s) #3643

Closed
opened 2026-10-31 20:33:56 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @hazindu on GitHub (Jun 11, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5195

I'm always frustrated when a single client consumes the entire server bandwidth. Currently, 3X-UI allows limiting the Total Traffic Quota (GB) and Expiry Date, but there is no built-in way to throttle the actual connection speed (e.g., limiting a specific user to 10 Mbps). When managing a server with multiple users, a few heavy downloaders can negatively impact the latency and speed of everyone else.

Describe the solution you'd like

I would like to see "Up Speed" and "Down Speed" limit fields added to the Add/Edit Client modal in the UI. The panel should allow setting a maximum speed (in KB/s or MB/s) per individual client. The backend could implement this using Xray's built-in traffic shaping capabilities or by dynamically managing Linux 'tc' (traffic control) rules tied to the client's connection.

Alternatives you've considered

I have considered using Linux 'tc' (Traffic Control) commands manually via SSH, but it is extremely difficult to manage dynamically for individual UUIDs managed by Xray. Setting connection/IP limits helps slightly, but it doesn't solve the bandwidth monopolization issue.

Concrete use case

I manage a server where I provide free access to a considerable group of users. I need to limit their individual speeds to a specific fixed value (5 MB/s) so they can browse normally, but ensure they won't cause lag or high ping for other users who are playing online multiplayer games on the same server.

Mockups, screenshots, or examples

Image

Which parts of the panel would this affect?

Frontend (UI / panel pages), Backend (API endpoints, login, settings), Xray config generation

Are you willing to help?

  • I'd like to implement this feature myself and open a PR.
  • I can help test once a PR is open.

Before submitting

  • I searched existing issues and this feature has not been requested.
  • This feature request is written in English.
Originally created by @hazindu on GitHub (Jun 11, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5195 ### Is your feature request related to a problem? I'm always frustrated when a single client consumes the entire server bandwidth. Currently, 3X-UI allows limiting the Total Traffic Quota (GB) and Expiry Date, but there is no built-in way to throttle the actual connection speed (e.g., limiting a specific user to 10 Mbps). When managing a server with multiple users, a few heavy downloaders can negatively impact the latency and speed of everyone else. ### Describe the solution you'd like I would like to see "Up Speed" and "Down Speed" limit fields added to the Add/Edit Client modal in the UI. The panel should allow setting a maximum speed (in KB/s or MB/s) per individual client. The backend could implement this using Xray's built-in traffic shaping capabilities or by dynamically managing Linux 'tc' (traffic control) rules tied to the client's connection. ### Alternatives you've considered I have considered using Linux 'tc' (Traffic Control) commands manually via SSH, but it is extremely difficult to manage dynamically for individual UUIDs managed by Xray. Setting connection/IP limits helps slightly, but it doesn't solve the bandwidth monopolization issue. ### Concrete use case I manage a server where I provide free access to a considerable group of users. I need to limit their individual speeds to a specific fixed value (5 MB/s) so they can browse normally, but ensure they won't cause lag or high ping for other users who are playing online multiplayer games on the same server. ### Mockups, screenshots, or examples <img width="1141" height="1379" alt="Image" src="https://github.com/user-attachments/assets/d2c79418-46dd-4140-b40f-ab67560484c7" /> ### Which parts of the panel would this affect? Frontend (UI / panel pages), Backend (API endpoints, login, settings), Xray config generation ### Are you willing to help? - [ ] I'd like to implement this feature myself and open a PR. - [ ] I can help test once a PR is open. ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this feature has not been requested. - [x] This feature request is written in English.
Author
Owner

@github-actions[bot] commented on GitHub (Jun 11, 2026):

Thanks for the detailed request and mockup — this is a well-understood pain point that has come up many times in this tracker.

Current state (confirmed in source)

There is no speed limiting in 3x-ui today. The Client struct in internal/database/model/model.go tracks only LimitIP, TotalGB, ExpiryTime, and Enable — no upload/download speed fields. The Xray config generation in internal/xray/ passes the policy section as-is (raw JSON from the panel's template), and it is not populated with any per-client rate values.

Why it is non-trivial

Xray-core's policy levels control connection timeouts (handshake, connIdle, uplinkOnly, downlinkOnly) and buffer sizes — not bandwidth caps. There is no native "max speed per user" knob in Xray-core's config. This is a known upstream limitation; per-client rate limiting is tracked in XTLS/Xray-core but not yet shipped.

That means any implementation in 3x-ui would have to use Linux tc (traffic control), which has its own challenges:

  • Xray-core multiplexes multiple virtual connections over a single TCP socket, so tc rules keyed on IP cannot cleanly isolate one client's traffic.
  • Rules must be created/removed dynamically when clients connect/disconnect or are added/deleted via the panel API.
  • This requires elevated privileges (CAP_NET_ADMIN) and works differently in Docker vs. bare-metal installs.

What a PR would need to touch

If someone wants to attempt this:

  1. internal/database/model/model.go — add UpSpeedKBps/DownSpeedKBps (int) fields to Client, ClientRecord, and the MergeClientRecord logic.
  2. A database migration in internal/database/.
  3. Backend enforcement logic — either inject tc rules via the OS (complex) or wait for upstream Xray-core support (blocked on upstream).
  4. Frontend — add the two numeric fields to the Add/Edit Client modal.
  5. Subscription/API serialisation if the fields need to be exported.

Given the upstream limitation, a PR adding only the UI fields + DB columns and deferring enforcement is the realistic first step. Enforcement via tc could follow separately.

Prior related issues (for reference): #4333, #3263, #2522, #2934 — all requested the same feature; none were implemented.

<!-- gh-comment-id:4676620346 --> @github-actions[bot] commented on GitHub (Jun 11, 2026): Thanks for the detailed request and mockup — this is a well-understood pain point that has come up many times in this tracker. **Current state (confirmed in source)** There is no speed limiting in 3x-ui today. The `Client` struct in `internal/database/model/model.go` tracks only `LimitIP`, `TotalGB`, `ExpiryTime`, and `Enable` — no upload/download speed fields. The Xray config generation in `internal/xray/` passes the `policy` section as-is (raw JSON from the panel's template), and it is not populated with any per-client rate values. **Why it is non-trivial** Xray-core's [policy levels](https://xtls.github.io/config/policy.html) control connection timeouts (`handshake`, `connIdle`, `uplinkOnly`, `downlinkOnly`) and buffer sizes — **not bandwidth caps**. There is no native "max speed per user" knob in Xray-core's config. This is a known upstream limitation; per-client rate limiting is tracked in [XTLS/Xray-core](https://github.com/XTLS/Xray-core) but not yet shipped. That means any implementation in 3x-ui would have to use **Linux `tc` (traffic control)**, which has its own challenges: - Xray-core multiplexes multiple virtual connections over a single TCP socket, so `tc` rules keyed on IP cannot cleanly isolate one client's traffic. - Rules must be created/removed dynamically when clients connect/disconnect or are added/deleted via the panel API. - This requires elevated privileges (`CAP_NET_ADMIN`) and works differently in Docker vs. bare-metal installs. **What a PR would need to touch** If someone wants to attempt this: 1. `internal/database/model/model.go` — add `UpSpeedKBps`/`DownSpeedKBps` (int) fields to `Client`, `ClientRecord`, and the `MergeClientRecord` logic. 2. A database migration in `internal/database/`. 3. Backend enforcement logic — either inject `tc` rules via the OS (complex) or wait for upstream Xray-core support (blocked on upstream). 4. Frontend — add the two numeric fields to the Add/Edit Client modal. 5. Subscription/API serialisation if the fields need to be exported. Given the upstream limitation, a PR adding only the **UI fields + DB columns** and deferring enforcement is the realistic first step. Enforcement via `tc` could follow separately. **Prior related issues** (for reference): #4333, #3263, #2522, #2934 — all requested the same feature; none were implemented.
Author
Owner

@NewMreza commented on GitHub (Jun 11, 2026):

you can manage bandwidth on xray only if you specify 1 port per client, which is not related to xray at all but to server itself.
that's the only way i know

<!-- gh-comment-id:4684281221 --> @NewMreza commented on GitHub (Jun 11, 2026): you can manage bandwidth on xray only if you specify 1 port per client, which is not related to xray at all but to server itself. that's the only way i know
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#3643
No description provided.