[GH-ISSUE #7028] [Feature]: Make the external traffic inform interval configurable and independent from Xray traffic polling #4625

Open
opened 2026-10-31 20:40:58 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @fq0222 on GitHub (Oct 30, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/7028

Feature description

Please add a configurable interval for External Traffic Inform (ExternalTrafficInformEnable / ExternalTrafficInformURI).

Currently, the external traffic webhook is called from XrayTrafficJob, which runs every 5 seconds:

cadenceXrayTraffic = "@every 5s"

This couples two different concerns:

  1. Internal Xray traffic collection, local accounting, online status, quota enforcement, and automatic client disabling.
  2. Sending traffic updates to an external HTTP endpoint.

The internal Xray traffic collection should continue running every 5 seconds. However, the external traffic notification should have its own configurable interval.

Proposed behavior

Add a setting such as:

External Traffic Inform Interval

Suggested behavior:

  • Default: 5 seconds, preserving the existing behavior.
  • The interval applies only to requests sent to ExternalTrafficInformURI.
  • The internal XrayTrafficJob continues running every 5 seconds.
  • Traffic deltas collected between external notifications are accumulated and sent together on the next notification.
  • Failed webhook requests must not block local traffic accounting or the next Xray traffic collection cycle.
  • The receiver should not lose traffic deltas when the external interval is greater than 5 seconds.

Example:

Internal Xray traffic polling: 5 seconds
External Traffic Inform Interval: 60 seconds

In this example, 3x-ui still updates local traffic, online state, and quota enforcement every 5 seconds, but sends one aggregated external notification every 60 seconds.

Motivation

Sending one HTTP request every 5 seconds from every panel or node can create unnecessary load on the receiving service, especially in multi-node deployments.

For example:

  • 1 node: 12 requests per minute
  • 10 nodes: 120 requests per minute
  • 100 nodes: 1,200 requests per minute

Many external billing and subscription systems do not require five-second updates. A separate configurable interval would reduce network and receiver load without delaying local quota enforcement.

Alternatives considered

Changing cadenceXrayTraffic itself is not suitable because it would also delay:

  • Local traffic accounting
  • Quota enforcement and automatic disabling
  • Online-client detection
  • Dashboard traffic updates

Therefore, the external notification schedule should be decoupled from the internal Xray traffic polling schedule.

  • #6115 addressed timeout and blocking risks in the external traffic notification path, but the notification interval remains coupled to the 5-second Xray traffic polling interval.
Originally created by @fq0222 on GitHub (Oct 30, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/7028 ### Feature description Please add a configurable interval for External Traffic Inform (`ExternalTrafficInformEnable` / `ExternalTrafficInformURI`). Currently, the external traffic webhook is called from `XrayTrafficJob`, which runs every 5 seconds: ~~~go cadenceXrayTraffic = "@every 5s" ~~~ This couples two different concerns: 1. Internal Xray traffic collection, local accounting, online status, quota enforcement, and automatic client disabling. 2. Sending traffic updates to an external HTTP endpoint. The internal Xray traffic collection should continue running every 5 seconds. However, the external traffic notification should have its own configurable interval. ### Proposed behavior Add a setting such as: ~~~text External Traffic Inform Interval ~~~ Suggested behavior: - Default: 5 seconds, preserving the existing behavior. - The interval applies only to requests sent to ExternalTrafficInformURI. - The internal XrayTrafficJob continues running every 5 seconds. - Traffic deltas collected between external notifications are accumulated and sent together on the next notification. - Failed webhook requests must not block local traffic accounting or the next Xray traffic collection cycle. - The receiver should not lose traffic deltas when the external interval is greater than 5 seconds. Example: ~~~text Internal Xray traffic polling: 5 seconds External Traffic Inform Interval: 60 seconds ~~~ In this example, 3x-ui still updates local traffic, online state, and quota enforcement every 5 seconds, but sends one aggregated external notification every 60 seconds. ### Motivation Sending one HTTP request every 5 seconds from every panel or node can create unnecessary load on the receiving service, especially in multi-node deployments. For example: - 1 node: 12 requests per minute - 10 nodes: 120 requests per minute - 100 nodes: 1,200 requests per minute Many external billing and subscription systems do not require five-second updates. A separate configurable interval would reduce network and receiver load without delaying local quota enforcement. ### Alternatives considered Changing cadenceXrayTraffic itself is not suitable because it would also delay: - Local traffic accounting - Quota enforcement and automatic disabling - Online-client detection - Dashboard traffic updates Therefore, the external notification schedule should be decoupled from the internal Xray traffic polling schedule. ### Related issue - #6115 addressed timeout and blocking risks in the external traffic notification path, but the notification interval remains coupled to the 5-second Xray traffic polling interval.
Author
Owner

@github-actions[bot] commented on GitHub (Oct 30, 2026):

This is a valid feature request. The current code works the way you describe: the external traffic POST runs inside the 5-second XrayTrafficJob, and no setting changes how often it fires.

What the code does today

  • The cadence is hard-coded: cadenceXrayTraffic = "@every 5s" (internal/web/web.go:305). It is registered once with s.cron.AddJob(cadenceXrayTraffic, job.NewXrayTrafficJob()) (internal/web/web.go:342).
  • Each run calls the webhook inline, after local accounting (internal/web/job/xray_traffic_job.go:103-104):
    if ExternalTrafficInformEnable, err := j.settingService.GetExternalTrafficInformEnable(); ExternalTrafficInformEnable {
    	j.informTrafficToExternalAPI(traffics, clientTraffics)
    
  • Only two settings exist for this feature: externalTrafficInformEnable and externalTrafficInformURI (internal/web/service/setting.go:203-204). There is no interval key.
  • The only thing that skips a POST is both slices being empty (xray_traffic_job.go:228). Xray reports a row for every known email even when it moved no bytes (see the comment at xray_traffic_job.go:35-36), so with any clients configured the receiver gets a request on almost every 5s tick.

Points for whoever builds this

  • Today's behaviour already loses data on failure. When DoTimeout fails (xray_traffic_job.go:255-256), the delta is logged and discarded, with no retry and no buffer. Your "receiver must not lose deltas" requirement therefore needs an accumulate-and-resend buffer for failures too, not just for a longer interval.
  • The POST is still synchronous. Since #6115 (0e69f64e) it is capped at externalInformTimeout = 3 * time.Second (xray_traffic_job.go:57), but a slow receiver can still delay the WebSocket broadcast later in the same Run() by up to 3s. Moving the inform onto its own schedule would also remove that coupling.
  • A new setting means a new key in setting.go defaults, a field in entity.AllSetting (internal/web/entity/entity.go:115-116), a settings-UI field, and i18n keys in all 14 locale files.

Related: #6115 (bounded the POST's timeout but left the cadence alone) and #3197 (how to use the feature). I found no duplicate.

Verdict: Feature request

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

<!-- gh-comment-id:6525036761 --> @github-actions[bot] commented on GitHub (Oct 30, 2026): This is a valid feature request. The current code works the way you describe: the external traffic POST runs inside the 5-second `XrayTrafficJob`, and no setting changes how often it fires. **What the code does today** - The cadence is hard-coded: `cadenceXrayTraffic = "@every 5s"` (`internal/web/web.go:305`). It is registered once with `s.cron.AddJob(cadenceXrayTraffic, job.NewXrayTrafficJob())` (`internal/web/web.go:342`). - Each run calls the webhook inline, after local accounting (`internal/web/job/xray_traffic_job.go:103-104`): ```go if ExternalTrafficInformEnable, err := j.settingService.GetExternalTrafficInformEnable(); ExternalTrafficInformEnable { j.informTrafficToExternalAPI(traffics, clientTraffics) ``` - Only two settings exist for this feature: `externalTrafficInformEnable` and `externalTrafficInformURI` (`internal/web/service/setting.go:203-204`). There is no interval key. - The only thing that skips a POST is both slices being empty (`xray_traffic_job.go:228`). Xray reports a row for every known email even when it moved no bytes (see the comment at `xray_traffic_job.go:35-36`), so with any clients configured the receiver gets a request on almost every 5s tick. **Points for whoever builds this** - Today's behaviour already loses data on failure. When `DoTimeout` fails (`xray_traffic_job.go:255-256`), the delta is logged and discarded, with no retry and no buffer. Your "receiver must not lose deltas" requirement therefore needs an accumulate-and-resend buffer for failures too, not just for a longer interval. - The POST is still synchronous. Since #6115 (`0e69f64e`) it is capped at `externalInformTimeout = 3 * time.Second` (`xray_traffic_job.go:57`), but a slow receiver can still delay the WebSocket broadcast later in the same `Run()` by up to 3s. Moving the inform onto its own schedule would also remove that coupling. - A new setting means a new key in `setting.go` defaults, a field in `entity.AllSetting` (`internal/web/entity/entity.go:115-116`), a settings-UI field, and i18n keys in all 14 locale files. Related: #6115 (bounded the POST's timeout but left the cadence alone) and #3197 (how to use the feature). I found no duplicate. Verdict: Feature request _This reply was generated automatically; a maintainer may follow up._ <!-- claude-issue:analyst -->
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#4625
No description provided.