[GH-ISSUE #5218] [Feature]: Per-client bandwidth throttling / QoS (Traffic Shaping) #3655

Closed
opened 2026-10-31 20:34:01 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @dead-man1 on GitHub (Jun 12, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5218

On high-bandwidth servers (e.g., 1 Gbps), a single client can easily saturate the server's network interface, leading to packet loss and high latency for all other clients sharing the same inbound.

Describe the solution you'd like

It would be incredibly useful if the panel could implement traffic shaping at the system level. A potential implementation could involve configuring Xray to apply specific socket marks (fwmark) per client/UUID routing, and having the 3x-ui panel automatically manage Linux tc (Traffic Control) classes to throttle those specific marks.

Alternatives you've considered

I haven't found any native way to do this in Xray or 3x-ui. Manual tc configuration is too complex and gets overwritten/reset when the panel restarts or configs change.

Concrete use case

I manage a server with 1 Gbps uplink. I need the ability to cap a specific client at 30 Mbps to ensure fair resource allocation and prevent one user from choking the connection for everyone else.

Mockups, screenshots, or examples

No specific UI mockup, but adding a 'Speed Limit (Mbps)' input field in the 'Add/Edit Client' dialog would be perfect.

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 @dead-man1 on GitHub (Jun 12, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5218 ### Is your feature request related to a problem? On high-bandwidth servers (e.g., 1 Gbps), a single client can easily saturate the server's network interface, leading to packet loss and high latency for all other clients sharing the same inbound. ### Describe the solution you'd like It would be incredibly useful if the panel could implement traffic shaping at the system level. A potential implementation could involve configuring Xray to apply specific socket marks (fwmark) per client/UUID routing, and having the 3x-ui panel automatically manage Linux tc (Traffic Control) classes to throttle those specific marks. ### Alternatives you've considered I haven't found any native way to do this in Xray or 3x-ui. Manual tc configuration is too complex and gets overwritten/reset when the panel restarts or configs change. ### Concrete use case I manage a server with 1 Gbps uplink. I need the ability to cap a specific client at 30 Mbps to ensure fair resource allocation and prevent one user from choking the connection for everyone else. ### Mockups, screenshots, or examples No specific UI mockup, but adding a 'Speed Limit (Mbps)' input field in the 'Add/Edit Client' dialog would be perfect. ### 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.
bsakaguchi 2026-10-31 20:34:01 +07:00
Author
Owner

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

Per-client bandwidth rate limiting is not implemented anywhere in the current codebase. The feature request is valid and not a duplicate of any existing issue.

What currently exists for per-client limits

The Client struct (internal/database/model/model.go) has two per-client constraint fields, neither of which is a rate/bandwidth limit:

  • LimitIP (limit_ip) — caps the number of concurrent IP connections per client
  • TotalGB (total_gb) — a cumulative data-volume quota; the client is disabled once the quota is exhausted, not throttled

There is no maxUpMbps, maxDownMbps, or any equivalent field. The frontend schemas (frontend/src/schemas/protocols/inbound/) and the Xray config generation code (internal/xray/) confirm the same: no rate-limiting data is emitted to Xray-core.

Why Xray-core cannot do this natively

Xray-core's policy system (internal/xray/config.go, policy levels) exposes connection-timeout fields (connIdle, uplinkOnly, downlinkOnly) and a bufferSize for memory tuning, but no per-user bandwidth cap. statsUserOnline (used by the IP-limit job) is the only per-user policy feature the panel currently uses. There is no per-email or per-UUID rate-limit knob in any of the supported protocols (VLESS, VMess, Trojan, Shadowsocks, Hysteria2, WireGuard).

The uplinkMbps/downlinkMbps labels that appear in the translation files (internal/web/translation/en-US.json:532-533) belong to the XHTTP transport stream settings, not client-level caps.

On the proposed fwmark + tc approach

The approach described — assigning per-client socket marks combined with Linux tc classes — is technically viable as a host-level workaround, but Xray-core does not currently support setting SO_MARK on a per-email/per-UUID basis on inbound-accepted sockets. It can set an outbound mark, which would require routing each client through a dedicated outbound — a significant change to how configs are generated today.

An alternative that stays entirely within the kernel is to apply tc rules keyed on the source IP of accepted connections (possible since the panel already tracks per-IP activity in internal/web/job/), but that breaks per-client isolation when multiple clients share a NAT address.

Scope of a proper implementation

Any implementation would touch at minimum:

  1. A new field on the Client model and ClientRecord (database migration required)
  2. Frontend: a numeric input in the Add/Edit Client dialog
  3. Xray config generation: translating the limit into an enforceable constraint
  4. System-level: a privileged component that creates, updates, and tears down tc rules on inbound restarts — with correct handling of NET_ADMIN capability in Docker deployments (docker-compose.yml already grants NET_ADMIN/NET_RAW for the fail2ban job)

This is a substantive feature that requires a design decision on the enforcement mechanism before a PR could be accepted. If you plan to implement it, opening a design discussion or draft PR early would be the best way to align on approach.

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:4687968063 --> @github-actions[bot] commented on GitHub (Jun 12, 2026): Per-client bandwidth rate limiting is not implemented anywhere in the current codebase. The feature request is valid and not a duplicate of any existing issue. **What currently exists for per-client limits** The `Client` struct (`internal/database/model/model.go`) has two per-client constraint fields, neither of which is a rate/bandwidth limit: - `LimitIP` (`limit_ip`) — caps the number of concurrent IP connections per client - `TotalGB` (`total_gb`) — a cumulative data-volume quota; the client is disabled once the quota is exhausted, not throttled There is no `maxUpMbps`, `maxDownMbps`, or any equivalent field. The frontend schemas (`frontend/src/schemas/protocols/inbound/`) and the Xray config generation code (`internal/xray/`) confirm the same: no rate-limiting data is emitted to Xray-core. **Why Xray-core cannot do this natively** Xray-core's policy system (`internal/xray/config.go`, policy levels) exposes connection-timeout fields (`connIdle`, `uplinkOnly`, `downlinkOnly`) and a `bufferSize` for memory tuning, but no per-user bandwidth cap. `statsUserOnline` (used by the IP-limit job) is the only per-user policy feature the panel currently uses. There is no per-email or per-UUID rate-limit knob in any of the supported protocols (VLESS, VMess, Trojan, Shadowsocks, Hysteria2, WireGuard). The `uplinkMbps`/`downlinkMbps` labels that appear in the translation files (`internal/web/translation/en-US.json:532-533`) belong to the XHTTP transport stream settings, not client-level caps. **On the proposed `fwmark` + `tc` approach** The approach described — assigning per-client socket marks combined with Linux `tc` classes — is technically viable as a host-level workaround, but Xray-core does not currently support setting `SO_MARK` on a per-email/per-UUID basis on inbound-accepted sockets. It can set an outbound `mark`, which would require routing each client through a dedicated outbound — a significant change to how configs are generated today. An alternative that stays entirely within the kernel is to apply `tc` rules keyed on the source IP of accepted connections (possible since the panel already tracks per-IP activity in `internal/web/job/`), but that breaks per-client isolation when multiple clients share a NAT address. **Scope of a proper implementation** Any implementation would touch at minimum: 1. A new field on the `Client` model and `ClientRecord` (database migration required) 2. Frontend: a numeric input in the Add/Edit Client dialog 3. Xray config generation: translating the limit into an enforceable constraint 4. System-level: a privileged component that creates, updates, and tears down `tc` rules on inbound restarts — with correct handling of `NET_ADMIN` capability in Docker deployments (`docker-compose.yml` already grants `NET_ADMIN`/`NET_RAW` for the fail2ban job) This is a substantive feature that requires a design decision on the enforcement mechanism before a PR could be accepted. If you plan to implement it, opening a design discussion or draft PR early would be the best way to align on approach. *This reply was generated automatically; a maintainer may follow up.*
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#3655
No description provided.