From: Thomas Lamprecht <t.lamprecht@proxmox.com>
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 [thread overview]
Message-ID: <20261201101913.1885484-1-t.lamprecht@proxmox.com> (raw)
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
next reply other threads:[~2026-12-01 10:20 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 10:18 Thomas Lamprecht [this message]
2026-12-01 10:18 ` [PATCH http-server v2 1/9] response: support deferred async API2 responses Thomas Lamprecht
2026-12-01 10:18 ` [PATCH http-server v2 2/9] proxy: strip chunked framing headers from decoded responses Thomas Lamprecht
2026-12-01 10:18 ` [PATCH http-server v2 3/9] response: support incremental streaming API2 responses Thomas Lamprecht
2026-12-01 10:18 ` [PATCH apiclient v2 4/9] add non-blocking AnyEvent API client Thomas Lamprecht
2026-12-01 10:19 ` [PATCH apiclient v2 5/9] add bounded AnyEvent request pool with backpressure and timeout Thomas Lamprecht
2026-12-01 10:19 ` [PATCH manager v2 6/9] api: metrics export: fetch remote nodes asynchronously Thomas Lamprecht
2026-12-01 10:19 ` [PATCH manager v2 7/9] api: metrics export: stream sorted metrics via incremental k-way merge Thomas Lamprecht
2026-12-01 10:19 ` [PATCH manager v2 8/9] api: metrics export: add unsorted pass-through streaming option Thomas Lamprecht
2026-12-01 10:19 ` [PATCH manager v2 9/9] test: add pull metric export test suite Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201101913.1885484-1-t.lamprecht@proxmox.com \
--to=t.lamprecht@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox