perf(clients): batch client creation by destination node (#7367)

Group compatible client creates by destination and effective payload via the existing clients/add API. Resolve node-local inbound IDs, preserve distinct flow/address/credential payloads, bound delivery concurrency and use a shared four-second remote delivery budget after local commits.

Advance reconciliation fingerprints only for acknowledged intended settings, retaining previous-fingerprint CAS rather than stamping unrelated rebased changes. Preserve FIFO turns, node-wide barriers, dirty generations, durable delete supersession, partial and uncertain delivery recovery and downstream outcomes. Protect later reattachments in final Delete cleanup and complete Create metadata before remote delivery.

Validation: all 12 CI jobs passed on 63e70cda38 (run 46935177853). PostgreSQL logs confirm 21 ordering/grouped-create tests and prior reporter-lock, reconciliation and traffic contention gates; node E2E confirms all four version pairings. Author reports SQLite/PostgreSQL race tests, make verify and isolated full make race.

Author-reported paired PostgreSQL 18 benchmark: 11 -> 1 RPC, fixed 200 ms peer delay 11-target p95 1552.0 -> 731.9 ms, timeout probe 12.41–12.42 -> 4.41–4.50 s. Size-dependent peer cost can instead cause pending delivery (1.74 -> 4.51 s with 0.74 s recovery); four stalled nodes can defer a fifth. Monitor production convergence and pending rate. No general production latency or allocation improvement claimed.

Refs #7299
This commit is contained in:
Hamed
2026-12-03 00:08:12 +03:30
committed by GitHub
parent 32e4b8bcfe
commit 91d5ff400d
13 changed files with 1521 additions and 59 deletions
+40 -8
View File
@@ -2,12 +2,14 @@ package web
import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"path/filepath"
"reflect"
"slices"
"strconv"
"strings"
"sync"
@@ -235,6 +237,35 @@ func TestMasterNodeContract(t *testing.T) {
t.Fatalf("node clients = %v, want c3 among them", got)
}
}},
{"AddClientGroup attaches one client to two inbounds", []string{"AddClientGroup"}, func() error {
second := masterInbound("grouped", false)
second.Tag, second.Port = "in-51002-tcp", 51002
if err := master.AddInbound(ctx, second); err != nil {
return err
}
client, err := json.Marshal(model.Client{
Email: "grouped", ID: "0b6d5c2e-7c1a-4f4e-9d3b-000000000004", SubID: "s-grouped", Enable: true,
})
if err != nil {
return err
}
_, ack, err := master.AddClientGroup(ctx, []string{contractTag, second.Tag}, client)
if err == nil && !slices.Equal(ack, []bool{true, true}) {
return fmt.Errorf("acknowledged inbounds %v, want both", ack)
}
return err
}, func(t *testing.T) {
for _, tag := range []string{contractTag, "in-51002-tcp"} {
inbound, ok := nodeRow(t, tag)
if !ok {
t.Fatalf("node has no inbound %s", tag)
}
clients, err := (&service.InboundService{}).GetClients(inbound)
if err != nil || !slices.ContainsFunc(clients, func(c model.Client) bool { return c.Email == "grouped" }) {
t.Fatalf("node inbound %s received no grouped client, err=%v", tag, err)
}
}
}},
{"UpdateUser changes the client's limits", []string{"UpdateUser"}, func() error {
_, err := master.UpdateUser(ctx, masterInbound("updated", false), "c3", model.Client{
Email: "c3", ID: "0b6d5c2e-7c1a-4f4e-9d3b-000000000003", SubID: "s-c3", Enable: true, TotalGB: 5 << 30,
@@ -421,14 +452,15 @@ func TestMasterNodeContract(t *testing.T) {
// Remote methods that never reach the node, or that this table must not run.
var remoteMethodsOutsideContract = map[string]string{
"Name": "local label",
"RecordAdoptedInbound": "local fingerprint bookkeeping",
"AdoptInboundAlias": "local alias bookkeeping",
"AdoptedInboundAliases": "local alias bookkeeping",
"AdvancePushedInbound": "local fingerprint bookkeeping",
"ForgetPushedInbound": "local fingerprint bookkeeping",
"ForgetInbound": "local bookkeeping for an inbound the node no longer has",
"UpdatePanel": "replaces the node binary; node-sync is denied it on purpose (#6201)",
"Name": "local label",
"RecordAdoptedInbound": "local fingerprint bookkeeping",
"AdoptInboundAlias": "local alias bookkeeping",
"AdoptedInboundAliases": "local alias bookkeeping",
"AdvancePushedInbound": "local fingerprint bookkeeping",
"PreparePushedInboundAdvance": "local fingerprint bookkeeping",
"ForgetPushedInbound": "local fingerprint bookkeeping",
"ForgetInbound": "local bookkeeping for an inbound the node no longer has",
"UpdatePanel": "replaces the node binary; node-sync is denied it on purpose (#6201)",
}
// A Remote method with no cell is how activeInbounds and bulkResetTraffic