190 lines
11 KiB
Markdown
190 lines
11 KiB
Markdown
# HealthApp energy workloads
|
|
|
|
JMeter 5.6.3 is installed on this development computer at `~/.local/bin/jmeter`.
|
|
Its launcher uses the installed Java 17; the default Java 26 cannot compile
|
|
JMeter's bundled Groovy scripts. No JMeter plugins are needed.
|
|
|
|
Runs default to **30 minutes of warmup + 4 hours of measurement**. A few additional
|
|
seconds allow startup/draining. Only requests entirely inside the four-hour window
|
|
appear in `measured.csv`. Full raw samples remain in `samples.csv`. `run.json` and
|
|
`timeline.json` identify exact UTC measurement boundaries for your external meter.
|
|
|
|
## Scenarios
|
|
|
|
| Plan | User workflow |
|
|
|---|---|
|
|
| `recording` | View guidance/profile, save a home resting reading, retrieve it, view overview. |
|
|
| `review` | Profile, latest reading, filtered history, numerical insights, trends, overview. |
|
|
| `correction` | Record an erroneous/duplicate entry, correct it, check overview, delete that entry, confirm removal. |
|
|
| `mixed` | Expected session mix: 65% review, 30% recording, 5% correction. |
|
|
| `professional` | Assigned-patient list, profile/latest/history/insights/trends/overview; no writes. |
|
|
| `idle` | No measured API traffic; services remain running for the same observation period. |
|
|
|
|
Each thread retains its own account, patient and opaque token. Login occurs initially
|
|
and before token expiry, including during four-hour runs. Requests use the gateway;
|
|
IDs come from actual responses. Nonexpected HTTP statuses and semantic failures stop
|
|
the affected user and invalidate the run. Only newly created correction-scenario
|
|
observations are deleted. Baseline and ordinary recording observations remain.
|
|
|
|
Per-user seeded random generators produce independent **Gaussian delays**:
|
|
interaction mean 4 seconds, standard deviation 2 seconds; between-session mean
|
|
120 seconds, standard deviation 30 seconds. Negative draws are clamped to zero,
|
|
so the resulting distribution is a clamped normal. Threads also ramp up over
|
|
120 seconds. The seed is recorded; OS scheduling still affects exact timings.
|
|
These are configurable experimental assumptions, not measured population behaviour.
|
|
The default session frequency represents sustained, accelerated prototype activity;
|
|
for less frequent patient visits increase `--session-pause-ms` and its deviation.
|
|
A closed-loop user waits for each response; throughput decreases when the server slows.
|
|
Concurrency means resident simulated users, including their idle/thinking time.
|
|
|
|
## 1. Prepare distinct test accounts (outside measurement)
|
|
|
|
The installer initially supplies only one ordinary patient account. Use distinct
|
|
accounts for realistic many-patient runs. There is no registration API. This setup
|
|
uses the existing external gateway-account configuration and password hash tool.
|
|
It changes no application code or service boundaries.
|
|
|
|
The hash tool has already been built on this computer. To rebuild it:
|
|
|
|
```bash
|
|
dotnet publish tools/PasswordHash -c Release --self-contained false -p:UseAppHost=false -o tools/energy-jmeter/hash-tool
|
|
```
|
|
|
|
From the repository root, copy the supporting tools to the server:
|
|
|
|
```bash
|
|
scp -r tools/energy-jmeter steffen@192.168.1.125:~/healthapp-energy
|
|
```
|
|
|
|
On **testserver**, generate 100 additional synthetic accounts, preserve the old
|
|
configuration, and explicitly install the generated copy:
|
|
|
|
```bash
|
|
sudo python3 ~/healthapp-energy/create-accounts.py --gateway-env /etc/healthapp/api-gateway/service.env --output /var/lib/healthapp-energy-fixture --count 100 --dotnet /usr/bin/dotnet
|
|
sudo cp -a /etc/healthapp/api-gateway/service.env /etc/healthapp/api-gateway/service.env.before-energy
|
|
sudo install -m 600 /var/lib/healthapp-energy-fixture/gateway.env /etc/healthapp/api-gateway/service.env
|
|
sudo systemctl restart healthapp-api-gateway
|
|
sudo install -m 600 -o "$USER" -g "$(id -gn)" /var/lib/healthapp-energy-fixture/accounts.json "$HOME/energy-accounts.json"
|
|
sudo install -m 644 /var/lib/healthapp-installation/deployment/healthapp-ca.crt "$HOME/healthapp-ca.crt"
|
|
```
|
|
|
|
Keep these generated accounts/configuration private. Existing installer accounts
|
|
are retained. The generator refuses to overwrite an existing output or regenerate
|
|
an already-configured energy-account set. Review generated configuration before
|
|
installing it. Do not run this on clinical data.
|
|
|
|
Back on **this development computer**, from the repository root:
|
|
|
|
```bash
|
|
mkdir -p tools/energy-jmeter/.private
|
|
chmod 700 tools/energy-jmeter/.private
|
|
scp steffen@192.168.1.125:~/energy-accounts.json tools/energy-jmeter/.private/accounts.json
|
|
scp steffen@192.168.1.125:~/healthapp-ca.crt tools/energy-jmeter/.private/healthapp-ca.crt
|
|
chmod 600 tools/energy-jmeter/.private/accounts.json
|
|
python3 tools/energy-jmeter/prepare.py --base-url https://192.168.1.125:5443 --ca tools/energy-jmeter/.private/healthapp-ca.crt --accounts tools/energy-jmeter/.private/accounts.json --output tools/energy-jmeter/.private/dataset --days 30
|
|
```
|
|
|
|
This creates/reuses each account's profile and seeds 60 historical synthetic readings
|
|
per patient, including home/resting, clinic, after-activity and unknown contexts.
|
|
Preparation verifies TLS certificates/hostnames and happens outside the
|
|
measurement window. For repeat comparisons, restore the same synthetic database
|
|
snapshot and reuse the same account configuration; recording grows history over time.
|
|
Seeding alone does not reset workload-created records. Use a new preparation output
|
|
folder if reseeding against a restored database.
|
|
|
|
For an immediate read-only trial with the existing prototype account, export the
|
|
installer's `accounts.json` privately instead of creating accounts. Prepare it with
|
|
`prepare.py`, then explicitly use `--allow-shared-read-account` with `review`.
|
|
That measures concurrent sessions sharing one patient, not a many-patient population.
|
|
The reserved `installation-check` account is excluded from preparation.
|
|
|
|
Professional tests require preconfigured professional accounts and assignments
|
|
(see [authentication documentation](../../src/AUTHENTICATION.md)). Create a separate
|
|
private CSV with `account_id,password,patient_id`, one assigned target per professional.
|
|
The runner verifies role/assignments. The default unassigned professional will fail
|
|
preflight instead of silently benchmarking rejected requests.
|
|
|
|
## 2. Find a suitable concurrency before the four-hour run
|
|
|
|
For the 8 GB, 8th/9th-generation Intel NUC, try 10, 25, 50 and 100 users in short
|
|
capacity runs. Generate more accounts before trying 200. Age/RAM do not establish
|
|
capacity. Review CPU, RAM, thermal throttling, error rate and latency on the NUC.
|
|
Choose your acceptable latency before deciding which level to measure for four hours.
|
|
For example, this trial lasts 2 minutes of warmup plus 5 measured minutes:
|
|
|
|
```bash
|
|
python3 tools/energy-jmeter/run.py mixed --host 192.168.1.125 --ca tools/energy-jmeter/.private/healthapp-ca.crt --users-file tools/energy-jmeter/.private/dataset/users.csv --users 50 --warmup 120 --duration 300 --output tools/energy-jmeter/results/capacity-50
|
|
```
|
|
|
|
A short check identifies obvious overload; it does not establish thermal stability
|
|
or long-run capacity. Output directories must be new. Failed users are not silently
|
|
replaced. Do not use a partial/failed run as a successful four-hour measurement.
|
|
|
|
## 3. Run a full experiment
|
|
|
|
Start the external power recording **before** this command, on the NUC only:
|
|
|
|
```bash
|
|
python3 tools/energy-jmeter/run.py mixed --host 192.168.1.125 --ca tools/energy-jmeter/.private/healthapp-ca.crt --users-file tools/energy-jmeter/.private/dataset/users.csv --users 100 --warmup 1800 --duration 14400 --output tools/energy-jmeter/results/mixed-100-run1
|
|
```
|
|
|
|
Substitute another scenario or concurrency as needed. `--warmup 600` or `1200`
|
|
selects 10/20 minutes; the four measured hours remain unchanged. Choose a warmup
|
|
that reaches stable server temperature/power rather than assuming a universal value.
|
|
`--seed 42`, `--think-mean-ms`, `--think-stddev-ms`, `--session-pause-ms` and
|
|
`--session-stddev-ms` control timing. Include these identically across comparisons.
|
|
|
|
Use the same-duration `idle` run to establish baseline power:
|
|
|
|
```bash
|
|
python3 tools/energy-jmeter/run.py idle --host 192.168.1.125 --ca tools/energy-jmeter/.private/healthapp-ca.crt --warmup 1800 --duration 14400 --output tools/energy-jmeter/results/idle-run1
|
|
```
|
|
|
|
The idle runner sends one TLS preflight request before the observation period.
|
|
The application services/PostgreSQL stay running. The load generator and HTML-report
|
|
creation stay on this computer, outside the NUC's energy measurement. Keep server
|
|
power settings, dataset, service versions, logging and other workloads consistent.
|
|
Record those settings, thermal state, meter sampling interval and clock synchronisation.
|
|
Repeat runs and vary their order to check drift. No live NUC load has been run by Codex.
|
|
|
|
## 4. Read results and energy
|
|
|
|
`run.json` contains measurement boundaries, request/error counts, request rate,
|
|
p95 latency, random seed, timings and plan hash. JMeter CSV excludes response bodies,
|
|
request headers and passwords. The private runtime credential CSV is deleted at exit;
|
|
keep the whole result directory private and inspect logs before sharing.
|
|
|
|
JMeter measures HTTP performance, **not energy**. Export your meter's readings as
|
|
CSV with `timestamp,power_watts` (timezone-qualified ISO timestamps, increasing,
|
|
covering the full interval), then integrate only the measured four hours:
|
|
|
|
```bash
|
|
python3 tools/energy-jmeter/energy.py tools/energy-jmeter/results/mixed-100-run1/run.json power.csv
|
|
```
|
|
|
|
The tool interpolates interval edges and integrates watts using trapezoids. It reports
|
|
joules, kWh, mean watts and joules per HTTP request. `--idle-watts VALUE` additionally
|
|
reports energy above the measured idle mean. A request is not a user session;
|
|
compare scenario/mix and achieved throughput when interpreting efficiency.
|
|
Raw meter data must be preserved; missing intervals cannot be repaired by JMeter.
|
|
|
|
JMeter's stock HTTPS client trusts test certificates. The Python runner verifies the
|
|
provided CA and hostname during preflight; JMeter traffic itself remains encrypted
|
|
but does not provide certificate validation. Do not describe this as a TLS security test.
|
|
|
|
## Verification
|
|
|
|
```bash
|
|
python3 tools/energy-jmeter/generate-plans.py
|
|
python3 tools/energy-jmeter/verify-plans.py
|
|
```
|
|
|
|
The validation script exercises every plan against an isolated local HTTPS contract
|
|
stub, including dynamic IDs, token renewal, status/semantic assertions, deletion and
|
|
warmup exclusion. It does not prove capacity or replace the application's acceptance
|
|
suite. The real-server short capacity trial is required before a four-hour measurement.
|
|
|
|
References: [Apache release](https://jmeter.apache.org/download_jmeter.cgi),
|
|
[CLI load testing](https://jmeter.apache.org/usermanual/get-started.html),
|
|
[JMeter components](https://jmeter.apache.org/usermanual/component_reference.html).
|