public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
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	[thread overview]
Message-ID: <20261130010113.2166775-1-t.lamprecht@proxmox.com> (raw)

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




             reply	other threads:[~2026-11-30  1:01 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  0:58 Thomas Lamprecht [this message]
2026-11-30  0:58 ` [PATCH http-server 01/09] response: support deferred async API2 responses Thomas Lamprecht
2026-11-30  0:58 ` [PATCH http-server 02/09] proxy: strip chunked framing headers from decoded responses Thomas Lamprecht
2026-11-30  0:58 ` [PATCH http-server 03/09] response: support incremental streaming API2 responses Thomas Lamprecht
2026-11-30  0:58 ` [PATCH apiclient 04/09] add non-blocking AnyEvent API client Thomas Lamprecht
2026-11-30  0:58 ` [PATCH apiclient 05/09] add bounded AnyEvent request pool with backpressure and timeout Thomas Lamprecht
2026-11-30  0:58 ` [PATCH manager 06/09] api: metrics export: fetch remote nodes asynchronously Thomas Lamprecht
2026-11-30  0:58 ` [PATCH manager 07/09] api: metrics export: stream sorted metrics via incremental k-way merge Thomas Lamprecht
2026-11-30  0:58 ` [PATCH manager 08/09] api: metrics export: add unsorted pass-through streaming option Thomas Lamprecht
2026-11-30  0:58 ` [PATCH manager 09/09] test: add pull metric export test suite Thomas Lamprecht
2026-12-01 10:13 ` [PATCH http-server,apiclient,manager 00/09] async and streaming pull metric export Jonas Theisen
2026-12-01 10:22 ` superseded: " 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=20261130010113.2166775-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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal