mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 07:54:49 +03:00
perf(wirecodec): bound node envelope compression memory (#7275)
The shared zstd encoder for master-to-node request bodies was built with library defaults: one workspace per CPU, each holding a 16 MiB history for the default 8 MiB window. The pool hands its workspaces out in rotation and never frees them, so a 4-vCPU master kept about 70 MiB alive after its first few pushes and a 16-core one about 280 MiB. Build it with a 1 MiB window, at most four workers and zstd's low-memory mode, which retains about 10 MiB whatever the CPU count. Callers queue for a worker on a slot channel, so a cancelled push stops waiting instead of blocking inside EncodeAll. Frames stay standard zstd: capability negotiation, the SHA-256 of the uncompressed body and the node's decode bounds are unchanged. Closes #7274
This commit is contained in:
@@ -354,7 +354,10 @@ func (r *Remote) do(ctx context.Context, method, path string, body any) (*envelo
|
||||
if bodyBytes != nil {
|
||||
hashHex = wirecodec.Sha256Hex(bodyBytes)
|
||||
if len(bodyBytes) >= zstdMinBodyBytes && r.nodeSupportsZstd() {
|
||||
bodyBytes = wirecodec.Compress(bodyBytes)
|
||||
bodyBytes, err = wirecodec.CompressContext(ctx, bodyBytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
zstdEncoded = true
|
||||
}
|
||||
reqBody = bytes.NewReader(bodyBytes)
|
||||
|
||||
Reference in New Issue
Block a user