From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id C2B401FF09F for ; Tue, 01 Dec 2026 11:20:45 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 62E77216F4; Tue, 01 Dec 2026 11:20:31 +0100 (CET) From: Thomas Lamprecht To: pve-devel@lists.proxmox.com Subject: [PATCH http-server,apiclient,manager v2 0/9] async and streaming pull metric export Date: Tue, 1 Dec 2026 11:18:55 +0100 Message-ID: <20261201101913.1885484-1-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1796120358640 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.002 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) POISEN_SPAM_PILL 0.1 Meta: its spam POISEN_SPAM_PILL_1 0.1 random spam to be learned in bayes POISEN_SPAM_PILL_3 0.1 random spam to be learned in bayes RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: J45S4JTIP62F7DROGXGB3VT37GURSBDB X-Message-ID-Hash: J45S4JTIP62F7DROGXGB3VT37GURSBDB X-MailFrom: t.lamprecht@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: GET /cluster/metrics/export runs inside the pveproxy worker handling the request and is polled regularly by Proxmox Datacenter Manager (PDM) via /api2/extjs/cluster/metrics/export (often with history=1) as well as external /api2/json/ and pvesh consumers. Today, the endpoint fetches every remote cluster node serially with blocking PVE::APIClient::LWP calls, stalling the worker event loop for all other clients while waiting on peer responses. On larger clusters or history scrapes, decoding all remote metrics into Perl hashes before sorting and compressing also drives worker memory into gigabytes and blocks the loop during JSON encoding and gzip compression. This series replaces the synchronous serial fan-out with non-blocking concurrent peer fetches and incremental streaming responses across three repositories: - pve-http-server (patches 1-3): add deferred async and incremental streaming API2 responses (PVE::APIServer::AsyncStream) with on-the-fly compression and backpressure, plus chunked proxy response framing fixes. - pve-apiclient (patches 4-5): add PVE::APIClient::AnyEvent as a non-blocking counterpart to LWP.pm with fingerprint pinning and raw body access, plus a bounded-concurrency request pool (PVE::APIClient::AnyEvent::Pool) with separate backpressure and capacity gates. - pve-manager (patches 6-9): switch GET /cluster/metrics/export to bounded async fan-out (16 peers per export, 32 per worker), add an opt-in fail-on-error=1 option to fail on online peer fetch/read errors, stream timestamp-sorted metrics incrementally without decoding each metric into Perl hashes, add an opt-in unsorted=1 pass-through streaming mode, and add a test suite. Default unsorted=0 preserves the existing global timestamp order and /api2/extjs/ envelope, so existing PDM and API clients benefit without changes. Rolling cluster upgrades work in any node order because peer fetches continue calling GET /api2/json/cluster/metrics/export with local-only=1. Changes in v2 (see individual patches for full per-patch changelogs): - pve-http-server: harden proxy header framing and HTTP 205 handling, verify the selected formatter in async_stream_supported(), validate status codes and compressor init in AsyncStream::start(), gate final keep-alive reuse on write backpressure, preserve write-only wtimeout on non-reusable final drain, and document the async/streaming contracts. - pve-apiclient: tighten TLS peername/fingerprint verification, anchor HTTP method validation with \A...\z, encode bare API tokens for PVE/PBS/PDM schemes (keeping literal TOKENID: for PBS/PDM and URI-escaping bare PVE tokens with '=', ';', or '%'), report ExtJS success: 0 via on_error in get()/post()/put()/delete() while call() still delivers the full envelope to on_response, add a shared exception-isolated Pool capacity limiter with re-entrant wake safety and distinct capacity/backpressure timeout semantics, and enforce monotonic timeout expiration in resume_timeout(). - pve-manager: wire the worker-wide peer cap through Pool's shared limiter and add a deadlock-free 128 MiB retained-byte dispatch admission threshold, add opt-in fail-on-error=1 with API 504/502 error mapping, unify wire-level signed 64-bit integer timestamp and duplicate-key validation across buffered and streaming paths with incremental multi-chunk scanning and monotonicity aborts, refine endpoint docs, and expand loopback, proxy-framing, wire-abort, formatter, budget, and recovery tests. Measured on a single pveproxy worker in a mock harness (25 ms per-peer latency, TLS with SHA-256 pinning, gzip, 16-peer cap; scenarios are nodes x guests, hist10 = 10 history generations; Max /ping HOL = maximum concurrent /ping latency on the same worker): Scenario | Mode | Total | TTFB | VmHWM | Max /ping HOL --------------------+---------------+--------+-------+----------+-------------- 25x100 latest | Sync LWP | 1034ms | - | 106 MiB | 1024 ms (25,475 metrics) | K-way stream | 196ms | 114ms | 84 MiB | 5.0 ms | Pass-through | 147ms | 2.0ms | 82 MiB | 8.0 ms 25x100 hist10 | Sync LWP | 2302ms | - | 338 MiB | 2354 ms (254,750 metrics) | K-way stream | 871ms | 123ms | 99 MiB | 9.4 ms | Pass-through | 761ms | 6.2ms | 93 MiB | 6.0 ms 100x100 latest | Sync LWP | 4195ms | - | 180 MiB | 4178 ms (101,900 metrics) | K-way stream | 687ms | 399ms | 91 MiB | 7.3 ms | Pass-through | 445ms | 2.1ms | 82 MiB | 9.5 ms 100x1000 | Buffered | 5.1 s | - | 973 MiB | - (1,001,900 metrics) | K-way stream | 3296ms | 397ms | 103 MiB | 9.5 ms | Pass-through | 2955ms | 5.3ms | 94 MiB | 8.6 ms Repo (build-)dependencies: pve-manager -> pve-http-server, pve-apiclient pve-http-server and pve-apiclient are independent of each other and must both be released before pve-manager, with pve-manager's Build-Depends and Depends bumped to the resulting package versions on apply. pve-http-server: Thomas Lamprecht (3): response: support deferred async API2 responses proxy: strip chunked framing headers from decoded responses response: support incremental streaming API2 responses src/Makefile | 1 + src/PVE/APIServer/AnyEvent.pm | 375 +++++++++++++++++++++++++++++++---- src/PVE/APIServer/AsyncStream.pm | 411 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 749 insertions(+), 38 deletions(-) pve-apiclient: Thomas Lamprecht (2): add non-blocking AnyEvent API client add bounded AnyEvent request pool with backpressure and timeout Makefile | 4 + debian/control | 12 +- src/Makefile | 8 +- src/PVE/APIClient/AnyEvent.pm | 574 +++++++++++ src/PVE/APIClient/AnyEvent/Pool.pm | 444 ++++++++ src/test/anyevent_client.t | 1974 ++++++++++++++++++++++++++++++++++++ src/test/anyevent_pool.t | 995 ++++++++++++++++++ 7 files changed, 4009 insertions(+), 2 deletions(-) pve-manager: Thomas Lamprecht (4): api: metrics export: fetch remote nodes asynchronously api: metrics export: stream sorted metrics via incremental k-way merge api: metrics export: add unsorted pass-through streaming option test: add pull metric export test suite PVE/API2/Cluster/MetricServer.pm | 141 +- PVE/Makefile | 3 +- PVE/PullMetricExport.pm | 1014 +++++++++++ PVE/PullMetricExport/Makefile | 15 + PVE/PullMetricExport/Reader.pm | 396 +++++ test/Makefile | 6 +- test/PullMetricExport_test.pl | 3590 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 5121 insertions(+), 44 deletions(-) -- 2.47.3