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 76A7B1FF0B7 for ; Mon, 30 Nov 2026 02:01:39 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id E2B49216FF; Mon, 30 Nov 2026 02:01:25 +0100 (CET) From: Thomas Lamprecht To: pve-devel@lists.proxmox.com Subject: [PATCH http-server,apiclient,manager 00/09] async and streaming pull metric export Date: Mon, 30 Nov 2026 01:58:04 +0100 Message-ID: <20261130010113.2166775-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: 1796000478541 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.003 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: IBRMWQZIZ4WEQR2IZCUMAIRCRENKBHOM X-Message-ID-Hash: IBRMWQZIZ4WEQR2IZCUMAIRCRENKBHOM 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 pveproxy's three AnyEvent workers 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). - pve-manager (patches 6-9): switch GET /cluster/metrics/export to bounded async fan-out (16 peers per export, 32 per worker), 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. 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; /ping HOL = concurrent /ping latency on the same worker): Scenario | Mode | Total | TTFB | VmHWM | /ping HOL --------------------+---------------+--------+-------+----------+-------------- 25x100 latest | Sync LWP | 980ms | - | 105 MiB | 952 ms (max) (25,475 metrics) | K-way stream | 188ms | 118ms | 83 MiB | 7.9 ms (max) | Pass-through | 154ms | 2.3ms | 81 MiB | 6.6 ms (max) 25x100 hist10 | Sync LWP | 2146ms | - | 337 MiB | 2194 ms (max) (254,750 metrics) | K-way stream | 827ms | 129ms | 98 MiB | 5.3 ms (max) | Pass-through | 744ms | 6.7ms | 92 MiB | 5.3 ms (med) 100x100 latest | Sync LWP | 4445ms | - | 180 MiB | 4128 ms (max) (101,900 metrics) | K-way stream | 644ms | 401ms | 90 MiB | 13.3 ms (max) | Pass-through | 463ms | 2.8ms | 81 MiB | 13.7 ms (max) 100x1000 | Buffered | 5.1 s | - | 973 MiB | - (1,001,900 metrics) | K-way stream | 2969ms | 360ms | 103 MiB | 10.5 ms (max) | Pass-through | 2790ms | 7.5ms | 93 MiB | 5.5 ms (med) 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 | 338 +++++++++++++++++++++++++++++++---- src/PVE/APIServer/AsyncStream.pm | 375 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 678 insertions(+), 36 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 | 496 +++++++++++ src/PVE/APIClient/AnyEvent/Pool.pm | 272 ++++++ src/test/anyevent_client.t | 1653 ++++++++++++++++++++++++++++++++++++ src/test/anyevent_pool.t | 690 +++++++++++++++ 7 files changed, 3133 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 | 117 ++- PVE/Makefile | 3 +- PVE/PullMetricExport.pm | 822 +++++++++++++++ PVE/PullMetricExport/Makefile | 15 + PVE/PullMetricExport/Reader.pm | 276 +++++ test/Makefile | 6 +- test/PullMetricExport_test.pl | 2082 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 3277 insertions(+), 44 deletions(-) -- 2.47.3