Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/plugin-ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,25 @@ jobs:
fi
fi

# Fails only when 1,000 series do not finish within one poller interval
# (REQ-PERF-001). The timings are printed, not compared: runners vary.
# It runs after the log check, since its budget case logs a warning on
# purpose; its own exit status and the web server log are checked here.
- name: Measure collection and the health page
working-directory: cacti
env:
CLOUD_TEST_DATABASE: disposable
run: |
php -S 127.0.0.1:8081 -t "$GITHUB_WORKSPACE" > "$RUNNER_TEMP/php-perf.log" 2>&1 &
for _ in 1 2 3 4 5 6 7 8 9 10; do
curl -fsS -o /dev/null http://127.0.0.1:8081/cacti/index.php && break
sleep 1
done
php plugins/cloud/tests/bin/perf.php http://127.0.0.1:8081/cacti/
if grep -E "Fatal error|Warning:|Uncaught" "$RUNNER_TEMP/php-perf.log"; then
exit 1
fi

# A 1.2.31 site may still run PHP 8.1. Enabling the plugin there must be
# refused with a message and leave Cacti working, both on a fresh install
# and after an upgrade-in-place left the plugin's hooks registered.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ These steps install the milestone 2 code for evaluation. They require Cacti 1.2.

## Design

- [docs/performance.md](docs/performance.md) has the collector and health page measurements, with the hardware and settings used.
- [docs/PLAN.md](docs/PLAN.md) is the full plan: architecture, the provider and Cacti facts it depends on (with sources), the driver contract, cost arithmetic, security boundaries, testing, and risks.
- [docs/decisions/](docs/decisions/) holds architecture decision records for choices already made.
- [docs/REQUIREMENTS.md](docs/REQUIREMENTS.md) maps every requirement ID to its issue.
Expand Down
2 changes: 1 addition & 1 deletion docs/PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ Arithmetic at 1,000 series collected every 300 seconds (8,640 collections a mont
| Google Cloud | One or more per metric type and project | About $3.82 (8.64 million series, first million free, $0.50 per million) |
| Azure | One per 50 resources, region, and type (if a batch bills as one call) | Within the free million calls per subscription: 20 calls per collection, 172,800 a month. If each resource bills separately, about $76 ([cost model](research/cost-model.md)) |

Engineering targets, to be measured, not yet demonstrated:
Engineering targets, measured against a fixture server in [performance.md](performance.md):

- A collector run for 1,000 series finishes within one poller interval, including provider latency.
- No page request calls a provider, except Verify on the account page.
Expand Down
62 changes: 62 additions & 0 deletions docs/performance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Performance

Measurements for [#47](https://github.com/somethingwithproof/plugin_cloud/issues/47), taken 2026-11-15 with [`tests/bin/perf.php`](../tests/bin/perf.php). CI runs the same script on every Cacti and PHP job. It fails the job only when 1,000 series don't finish within one poller interval, and prints its timings without comparing them, because runner hardware varies.

**Result.** With a local fixture server and no added latency, a collector run reads 1,000 series in about 3 seconds. That is about 3 ms of plugin and TLS work per request. The health page renders 10,000 cached series in 0.08 seconds. With 100 ms of simulated provider latency per request, the same run takes 106 seconds. Provider latency, not the plugin, decides whether 1,000 series fit in one poller interval.

## What runs

The script uses the real collector, the DigitalOcean driver, the guarded transport (operation allowlist) and the socket transport, with TLS verified against a test CA. Only the host is rewritten, after the operation check, so requests reach [`tests/bin/perf-server.php`](../tests/bin/perf-server.php) instead of `api.digitalocean.com`. That server replays the recorded fixtures with their timestamps moved to the current time, and sends the rate-limit headers the driver reads.

| Case | Setup | Measures |
|---|---|---|
| Collect | 4 accounts, 50 Droplets each, 5 series per Droplet (CPU and four bandwidth): 1,000 series | One collector run on poller 1 (REQ-PERF-001) |
| Budget | 1 account, 200 Droplets, 5 series each: 1,000 series | The same run, where the request budget stops the account |
| Page | 10 accounts, 200 Droplets each, 5 cached series per Droplet: 10,000 series | `cloud_health.php` over HTTP as a logged-in administrator, the median of five loads after a warm-up (REQ-PERF-002) |

The collect case uses four accounts because one DigitalOcean token allows 250 requests a minute. At 100 percent request share, that is the most one account reads in a run (`RequestBudget::perRun`). The budget case shows the limit: the account reads 250 series, marks the other 750 unread with reason `budget`, and the health page reports it.

## Hardware and settings (REQ-PERF-003)

| | |
|---|---|
| Host | Apple M3 Max, 14 cores, 36 GiB |
| Runtime | OrbStack Linux VM, aarch64, 14 CPUs, 15.7 GiB, Docker image `cloud-ci:8.2` |
| PHP | 8.2.35, CLI for the collector, built-in web server for the page |
| Database | MariaDB 11.8.9, same VM |
| Cacti | 1.2.31 and the 1.2.x branch (1.2.32) |
| Poller interval | 300 seconds |
| Accounts | Collection interval 300 seconds, request share 100 percent, discovery not due during the run |
| Collector time budget | Poller interval less 10 seconds (290); the plugin's default setting is 240 |

## Results

Three runs on each Cacti version, no added latency:

| Case | Cacti 1.2.31 | Cacti 1.2.x |
|---|---|---|
| Collect, 1,000 series in 4 accounts | 2.83, 3.00, 3.17 s; 1,000 read with 1,000 requests | 3.42, 2.59, 2.61 s; 1,000 read with 1,000 requests |
| Budget, 1,000 series in 1 account | 1.20, 1.32, 1.10 s; 250 read, 750 left with reason `budget` | 1.24, 1.72, 1.10 s; 250 read, 750 left with reason `budget` |
| Health page, 10,000 series | 0.08 s median, 0.08 s slowest, all three runs | 0.08 s median, 0.09 s slowest at most |

With `perf.php <url> 100`, which adds 100 ms before each fixture response, the collect case took 106.26 seconds on Cacti 1.2.31 and read all 1,000 series. The budget case took 27.02 seconds.

The page result was checked by its content, not only its speed. Each of the 10 accounts showed 1,000 current series, and an estimate of 12,000 requests an hour (1,000 series every 300 seconds).

## Reading the results

- **Run time scales with provider latency.** The collector reads one series per request, one request at a time. A run takes about requests × (latency + 3 ms). With the default 240-second time budget, 1,000 series fit while the average round trip stays under about 237 ms. Above that, the collector stops starting new accounts at the budget, and the unread accounts are collected in the next run. The first [live check](research/provider-facts.md#live-checks) (#16) measured a median round trip of 384 ms (301 to 799 ms) from a home connection. At that latency, 1,000 series take about 390 seconds, so the default budget reads about 620 a run and the rest carry over. A poller in a data center near DigitalOcean should see less, so measure from your own poller before planning for more than about 600 series on one poller.
- **DigitalOcean's limit is per token, not per plugin.** At the default 50 percent share, one account reads 125 series a run. Larger estates need more accounts, each with its own token, and the health page estimate shows how close each account is to its share.
- **The page stays cheap at 10,000 series.** It reads cached rows only and never calls a provider, so its cost grows with the plugin's tables, not with provider latency.
- **Not measured here:** RRD updates by Cacti's poller, boost, Spine, remote data collectors, and a database on a separate host. Each adds cost outside the plugin.

## Running it

On a disposable database, with the plugin installed and enabled and Cacti served at a URL:

```sh
CLOUD_TEST_DATABASE=disposable php plugins/cloud/tests/bin/perf.php http://127.0.0.1:8080/cacti/
CLOUD_TEST_DATABASE=disposable php plugins/cloud/tests/bin/perf.php http://127.0.0.1:8080/cacti/ 100
```

The second argument adds that many milliseconds of latency to each fixture response. The script deletes every plugin account, resource, series, and observation, and resets the admin password, so never run it against a database you keep.
110 changes: 110 additions & 0 deletions tests/bin/perf-server.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php
/*
* SPDX-FileCopyrightText: 2026 Thomas Vincent <thomasvincent@gmail.com>
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This file is part of plugin_cloud, a plugin for Cacti.
* https://github.com/somethingwithproof/plugin_cloud
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*/

/*
* The DigitalOcean fixture server for the performance runs (#47). Serves
* every monitoring path over TLS from the recorded fixtures, with their
* timestamps moved to now so each datapoint is current, plus the rate
* limit headers the driver reads. One connection at a time, like the
* collector. Must parse on PHP 8.0.
*
* php perf-server.php <port> <cert.pem> <seconds> [latency ms]
*
* The latency is added before each response, to stand in for the provider.
*/

$port = (int) ($argv[1] ?? 0);
$cert = (string) ($argv[2] ?? '');
$seconds = (int) ($argv[3] ?? 600);
$latency = (int) ($argv[4] ?? 0);
$fixture = dirname(__DIR__) . '/fixtures/digitalocean/';

$templates = array(
'bandwidth' => json_decode((string) file_get_contents($fixture . 'droplet_bandwidth.json'), true),
'default' => json_decode((string) file_get_contents($fixture . 'droplet_cpu.json'), true),
);

$server = stream_socket_server(
'ssl://127.0.0.1:' . $port,
$errno,
$errstr,
STREAM_SERVER_BIND | STREAM_SERVER_LISTEN,
stream_context_create(array('ssl' => array('local_cert' => $cert)))
);

if ($server === false) {
fwrite(STDERR, "listen failed: $errstr\n");
exit(1);
}

/**
* The fixture for $path with each series' points ending a minute ago.
*/
function perf_body($templates, $path) {
$body = $templates[basename($path) === 'bandwidth' ? 'bandwidth' : 'default'];
$now = time() - 60;

foreach ($body['data']['result'] as $i => $series) {
$count = count($series['values']);

foreach ($series['values'] as $j => $point) {
$body['data']['result'][$i]['values'][$j][0] = $now - ($count - 1 - $j) * 60;
}
}

return json_encode($body);
}

$deadline = time() + $seconds;

while (time() < $deadline) {
$conn = @stream_socket_accept($server, 1);

if ($conn === false) {
continue;
}

stream_set_timeout($conn, 5);
$head = '';

while (strpos($head, "\r\n\r\n") === false && strlen($head) < 65536) {
$line = fgets($conn, 8192);

if ($line === false) {
break;
}

$head .= $line;
}

usleep($latency * 1000);

$target = explode(' ', explode("\r\n", $head, 2)[0]) + array('', '', '');
$path = (string) parse_url($target[1], PHP_URL_PATH);
$body = strpos($path, '/v2/monitoring/metrics/') === 0 ? perf_body($templates, $path) : '{"id":"not_found"}';
$status = strpos($path, '/v2/monitoring/metrics/') === 0 ? '200 OK' : '404 Not Found';

@fwrite(
$conn,
"HTTP/1.1 $status\r\nContent-Type: application/json\r\nContent-Length: " . strlen($body) . "\r\n" .
"ratelimit-limit: 5000\r\nratelimit-remaining: 4999\r\nratelimit-reset: " . (time() + 3600) . "\r\n" .
"Connection: close\r\n\r\n" . $body
);
fclose($conn);
}
Loading
Loading