mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-01 06:54:47 +03:00
perf(node-sync): avoid redundant full inbound snapshots (#7014)
Every five seconds the master fetched each node's complete inbound list, settings JSON and enrichment included, parsed it and reconciled every client, whether anything had changed or not. A node that advertises traffic-snapshot-v1 now answers a revisioned endpoint: counters and lifecycle state on every poll, inbound configuration and attachments only when its revision changed. The master skips structural parsing and client reconciliation while the node's revision, its own rows for that node, the lifecycle state and the full remote-to-central inbound mapping are all unchanged; anything else falls back to the full merge. Old and new panels keep talking through the previous endpoints. Revisions come from a hidden per-row token on inbounds and clients, maintained by database triggers on SQLite and PostgreSQL so that direct and background writes count too. Counter and timestamp updates leave it alone. The triggers are dropped before migrations and recreated after them, and the previous build runs unchanged on a database that carries them. Measured here at 20,000 clients on one node, per idle poll: master SQL statements 551 -> 44, node statements 55 -> 4, transfer 23.0 MB -> 4.8 MB. When every client is shared between nodes the ownership checks keep the full master merge, so only the node and the transfer get cheaper. The node still reads every membership and counter on each poll. Closes #7007
This commit is contained in:
@@ -16,6 +16,13 @@ _openapi:
|
||||
legacy callers that send them back as JSON-encoded strings are still
|
||||
accepted on write.
|
||||
url: '#list-every-inbound-owned-by-the-authenticated-user-including-each-inbounds-clientstats-traffic-counters-settings-streamsettings-and-sniffing-are-returned-as-nested-json-objects-no-escaped-strings-legacy-callers-that-send-them-back-as-json-encoded-strings-are-still-accepted-on-write'
|
||||
- depth: 2
|
||||
title: 'Internal node sync v1: complete raw local counters and online state on
|
||||
every poll. Send the last validated revision to omit unchanged
|
||||
structure. Omitted structure requires a matching cached catalog; a
|
||||
present structure with empty arrays is authoritative. Uses admin,
|
||||
node-admin or node-sync authorization.'
|
||||
url: '#internal-node-sync-v1-complete-raw-local-counters-and-online-state-on-every-poll-send-the-last-validated-revision-to-omit-unchanged-structure-omitted-structure-requires-a-matching-cached-catalog-a-present-structure-with-empty-arrays-is-authoritative-uses-admin-node-admin-or-node-sync-authorization'
|
||||
- depth: 2
|
||||
title: Same shape as /list but with settings.clients[] stripped down to {email,
|
||||
enable, comment} and ClientStats not enriched with UUID/SubId. Use this
|
||||
@@ -130,6 +137,12 @@ _openapi:
|
||||
legacy callers that send them back as JSON-encoded strings are still
|
||||
accepted on write.
|
||||
id: list-every-inbound-owned-by-the-authenticated-user-including-each-inbounds-clientstats-traffic-counters-settings-streamsettings-and-sniffing-are-returned-as-nested-json-objects-no-escaped-strings-legacy-callers-that-send-them-back-as-json-encoded-strings-are-still-accepted-on-write
|
||||
- content: 'Internal node sync v1: complete raw local counters and online state on
|
||||
every poll. Send the last validated revision to omit unchanged
|
||||
structure. Omitted structure requires a matching cached catalog; a
|
||||
present structure with empty arrays is authoritative. Uses admin,
|
||||
node-admin or node-sync authorization.'
|
||||
id: internal-node-sync-v1-complete-raw-local-counters-and-online-state-on-every-poll-send-the-last-validated-revision-to-omit-unchanged-structure-omitted-structure-requires-a-matching-cached-catalog-a-present-structure-with-empty-arrays-is-authoritative-uses-admin-node-admin-or-node-sync-authorization
|
||||
- content: Same shape as /list but with settings.clients[] stripped down to
|
||||
{email, enable, comment} and ClientStats not enriched with UUID/SubId.
|
||||
Use this for list pages; fetch /get/:id when you need the full
|
||||
@@ -228,7 +241,7 @@ export default function Layout(props) {
|
||||
return (
|
||||
<>
|
||||
{props.children}
|
||||
<OpenAPIPage document="./public/openapi.json" webhooks={[]} operations={[{"path":"/panel/api/inbounds/list","method":"get"},{"path":"/panel/api/inbounds/list/slim","method":"get"},{"path":"/panel/api/inbounds/options","method":"get"},{"path":"/panel/api/inbounds/amneziawgKernelReadiness","method":"get"},{"path":"/panel/api/inbounds/allLinks","method":"get"},{"path":"/panel/api/inbounds/get/{id}","method":"get"},{"path":"/panel/api/inbounds/add","method":"post"},{"path":"/panel/api/inbounds/del/{id}","method":"post"},{"path":"/panel/api/inbounds/bulkDel","method":"post"},{"path":"/panel/api/inbounds/update/{id}","method":"post"},{"path":"/panel/api/inbounds/setEnable/{id}","method":"post"},{"path":"/panel/api/inbounds/{id}/subSortIndex","method":"post"},{"path":"/panel/api/inbounds/{id}/resetTraffic","method":"post"},{"path":"/panel/api/inbounds/{id}/delAllClients","method":"post"},{"path":"/panel/api/inbounds/resetAllTraffics","method":"post"},{"path":"/panel/api/inbounds/import","method":"post"},{"path":"/panel/api/inbounds/pushClientTraffics","method":"post"},{"path":"/panel/api/inbounds/{id}/fallbacks","method":"get"},{"path":"/panel/api/inbounds/{id}/fallbacks","method":"post"}]} showTitle />
|
||||
<OpenAPIPage document="./public/openapi.json" webhooks={[]} operations={[{"path":"/panel/api/inbounds/list","method":"get"},{"path":"/panel/api/inbounds/trafficSnapshot","method":"get"},{"path":"/panel/api/inbounds/list/slim","method":"get"},{"path":"/panel/api/inbounds/options","method":"get"},{"path":"/panel/api/inbounds/amneziawgKernelReadiness","method":"get"},{"path":"/panel/api/inbounds/allLinks","method":"get"},{"path":"/panel/api/inbounds/get/{id}","method":"get"},{"path":"/panel/api/inbounds/add","method":"post"},{"path":"/panel/api/inbounds/del/{id}","method":"post"},{"path":"/panel/api/inbounds/bulkDel","method":"post"},{"path":"/panel/api/inbounds/update/{id}","method":"post"},{"path":"/panel/api/inbounds/setEnable/{id}","method":"post"},{"path":"/panel/api/inbounds/{id}/subSortIndex","method":"post"},{"path":"/panel/api/inbounds/{id}/resetTraffic","method":"post"},{"path":"/panel/api/inbounds/{id}/delAllClients","method":"post"},{"path":"/panel/api/inbounds/resetAllTraffics","method":"post"},{"path":"/panel/api/inbounds/import","method":"post"},{"path":"/panel/api/inbounds/pushClientTraffics","method":"post"},{"path":"/panel/api/inbounds/{id}/fallbacks","method":"get"},{"path":"/panel/api/inbounds/{id}/fallbacks","method":"post"}]} showTitle />
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -4587,6 +4587,105 @@
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"NodeClientTraffic": {
|
||||
"properties": {
|
||||
"down": {
|
||||
"example": 2097152,
|
||||
"format": "int64",
|
||||
"type": "integer"
|
||||
},
|
||||
"email": {
|
||||
"example": "user1",
|
||||
"type": "string"
|
||||
},
|
||||
"enable": {
|
||||
"example": true,
|
||||
"type": "boolean"
|
||||
},
|
||||
"expiryTime": {
|
||||
"example": 1735689600000,
|
||||
"format": "int64",
|
||||
"type": "integer"
|
||||
},
|
||||
"id": {
|
||||
"example": 14825,
|
||||
"type": "integer"
|
||||
},
|
||||
"inboundId": {
|
||||
"example": 1,
|
||||
"type": "integer"
|
||||
},
|
||||
"lastOnline": {
|
||||
"example": 1735680000000,
|
||||
"format": "int64",
|
||||
"type": "integer"
|
||||
},
|
||||
"reset": {
|
||||
"type": "integer"
|
||||
},
|
||||
"resetCount": {
|
||||
"type": "integer"
|
||||
},
|
||||
"resetDay": {
|
||||
"type": "integer"
|
||||
},
|
||||
"resetMax": {
|
||||
"type": "integer"
|
||||
},
|
||||
"resetWeekday": {
|
||||
"type": "integer"
|
||||
},
|
||||
"total": {
|
||||
"example": 10737418240,
|
||||
"format": "int64",
|
||||
"type": "integer"
|
||||
},
|
||||
"up": {
|
||||
"example": 1048576,
|
||||
"format": "int64",
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"down",
|
||||
"email",
|
||||
"enable",
|
||||
"expiryTime",
|
||||
"id",
|
||||
"inboundId",
|
||||
"lastOnline",
|
||||
"reset",
|
||||
"resetCount",
|
||||
"resetDay",
|
||||
"resetMax",
|
||||
"resetWeekday",
|
||||
"total",
|
||||
"up"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"NodeInboundTraffic": {
|
||||
"properties": {
|
||||
"down": {
|
||||
"format": "int64",
|
||||
"type": "integer"
|
||||
},
|
||||
"id": {
|
||||
"example": 1,
|
||||
"type": "integer"
|
||||
},
|
||||
"up": {
|
||||
"format": "int64",
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"down",
|
||||
"id",
|
||||
"up"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"NodeMutationRequest": {
|
||||
"description": "NodeMutationRequest is the node write/probe contract. ApiToken is accepted\nonly as input. On update, nil means keep the stored token; replacement and\nclearing are explicit and mutually exclusive.",
|
||||
"properties": {
|
||||
@@ -4677,6 +4776,124 @@
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"NodeSnapshotAttachment": {
|
||||
"properties": {
|
||||
"email": {
|
||||
"example": "user1",
|
||||
"type": "string"
|
||||
},
|
||||
"inboundId": {
|
||||
"example": 1,
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"email",
|
||||
"inboundId"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"NodeSnapshotStructure": {
|
||||
"properties": {
|
||||
"attachments": {
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/NodeSnapshotAttachment"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"inbounds": {
|
||||
"items": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/Inbound"
|
||||
}
|
||||
],
|
||||
"nullable": true
|
||||
},
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"attachments",
|
||||
"inbounds"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"NodeTrafficSnapshotV1": {
|
||||
"description": "NodeTrafficSnapshotV1 carries complete counters every tick; only unchanged structure is omitted.",
|
||||
"properties": {
|
||||
"activeInboundTree": {
|
||||
"additionalProperties": {
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"clients": {
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/NodeClientTraffic"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"inboundTraffic": {
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/NodeInboundTraffic"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"lastOnlineMap": {
|
||||
"additionalProperties": {
|
||||
"format": "int64",
|
||||
"type": "integer"
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"onlineEmails": {
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"onlineTree": {
|
||||
"additionalProperties": {
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"revision": {
|
||||
"example": "0000000000000000000000000000000000000000000000000000000000000001",
|
||||
"type": "string"
|
||||
},
|
||||
"structure": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/NodeSnapshotStructure"
|
||||
}
|
||||
],
|
||||
"nullable": true
|
||||
},
|
||||
"version": {
|
||||
"example": 1,
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"activeInboundTree",
|
||||
"clients",
|
||||
"inboundTraffic",
|
||||
"lastOnlineMap",
|
||||
"onlineEmails",
|
||||
"onlineTree",
|
||||
"revision",
|
||||
"version"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"NodeView": {
|
||||
"description": "NodeView is the browser/API read contract for nodes. Credentials are\nwrite-only: responses expose only whether a node has a token configured.",
|
||||
"properties": {
|
||||
@@ -6553,6 +6770,88 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/panel/api/inbounds/trafficSnapshot": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"Inbounds"
|
||||
],
|
||||
"summary": "Internal node sync v1: complete raw local counters and online state on every poll. Send the last validated revision to omit unchanged structure. Omitted structure requires a matching cached catalog; a present structure with empty arrays is authoritative. Uses admin, node-admin or node-sync authorization.",
|
||||
"operationId": "get_panel_api_inbounds_trafficSnapshot",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "revision",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"description": "Opaque revision of the last validated complete catalog. Omit when no catalog is cached.",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Successful response",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"success": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"msg": {
|
||||
"type": "string"
|
||||
},
|
||||
"obj": {
|
||||
"$ref": "#/components/schemas/NodeTrafficSnapshotV1"
|
||||
}
|
||||
}
|
||||
},
|
||||
"example": {
|
||||
"success": true,
|
||||
"obj": {
|
||||
"activeInboundTree": {},
|
||||
"clients": [
|
||||
{
|
||||
"down": 2097152,
|
||||
"email": "user1",
|
||||
"enable": true,
|
||||
"expiryTime": 1735689600000,
|
||||
"id": 14825,
|
||||
"inboundId": 1,
|
||||
"lastOnline": 1735680000000,
|
||||
"reset": 0,
|
||||
"resetCount": 0,
|
||||
"resetDay": 0,
|
||||
"resetMax": 0,
|
||||
"resetWeekday": 0,
|
||||
"total": 10737418240,
|
||||
"up": 1048576
|
||||
}
|
||||
],
|
||||
"inboundTraffic": [
|
||||
{
|
||||
"down": 0,
|
||||
"id": 1,
|
||||
"up": 0
|
||||
}
|
||||
],
|
||||
"lastOnlineMap": {},
|
||||
"onlineEmails": [
|
||||
""
|
||||
],
|
||||
"onlineTree": {},
|
||||
"revision": "0000000000000000000000000000000000000000000000000000000000000001",
|
||||
"structure": null,
|
||||
"version": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/panel/api/inbounds/list/slim": {
|
||||
"get": {
|
||||
"tags": [
|
||||
|
||||
Reference in New Issue
Block a user