Provide four-hour idle baseline without application requests
This commit is contained in:
1 parent
e50cf0a011
commit
79bb6a11cd
4 files changed
+55
-8
No files matched your search
@@ -221,11 +221,11 @@ that reaches stable server temperature/power rather than assuming a universal va
|
|||||||
Use the same-duration `idle` run to establish baseline power:
|
Use the same-duration `idle` run to establish baseline power:
|
||||||
|
|
||||||
```bash
|
```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
|
bash tools/energy-jmeter/run-idle.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
The idle runner sends one TLS preflight request before the observation period, then uses a JMeter idle plan with live PerfMon collection.
|
The idle runner sends zero application requests, including during startup. No CA, credentials or dataset is needed. JMeter collects only PerfMon host metrics and Shelly power readings.
|
||||||
The application services/PostgreSQL stay running. The load generator and HTML-report
|
The application services/PostgreSQL stay running as they are. The runner does not start, stop or restart them. Keep the PerfMon agent running. The one-command launcher creates a timestamped result folder under `results/idle-*`. The load generator and HTML-report
|
||||||
creation stay on this computer, outside the NUC's energy measurement. Keep server
|
creation stay on this computer, outside the NUC's energy measurement. Keep server
|
||||||
power settings, dataset, service versions, logging and other workloads consistent.
|
power settings, dataset, service versions, logging and other workloads consistent.
|
||||||
Record those settings, thermal state, meter sampling interval and clock synchronisation.
|
Record those settings, thermal state, meter sampling interval and clock synchronisation.
|
||||||
@@ -263,6 +263,7 @@ python3 tools/energy-jmeter/generate-plans.py
|
|||||||
python3 tools/energy-jmeter/verify-plans.py
|
python3 tools/energy-jmeter/verify-plans.py
|
||||||
python3 tools/energy-jmeter/verify-perfmon.py
|
python3 tools/energy-jmeter/verify-perfmon.py
|
||||||
python3 tools/energy-jmeter/verify-shelly.py
|
python3 tools/energy-jmeter/verify-shelly.py
|
||||||
|
python3 tools/energy-jmeter/verify-idle.py
|
||||||
```
|
```
|
||||||
|
|
||||||
The validation script exercises every plan against an isolated local HTTPS contract
|
The validation script exercises every plan against an isolated local HTTPS contract
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
|
||||||
|
run_id=$(date -u +%Y%m%dT%H%M%SZ)
|
||||||
|
exec python3 "$script_dir/run.py" idle \
|
||||||
|
--host "${HEALTHAPP_HOST:-192.168.1.125}" \
|
||||||
|
--shelly-host "${SHELLY_HOST:-192.168.1.44}" \
|
||||||
|
--warmup 1800 --duration 14400 \
|
||||||
|
--output "$script_dir/results/idle-$run_id" "$@"
|
||||||
@@ -9,7 +9,7 @@ HERE=Path(__file__).resolve().parent
|
|||||||
p=argparse.ArgumentParser()
|
p=argparse.ArgumentParser()
|
||||||
p.add_argument('scenario',choices=['recording','review','correction','professional','mixed','idle'])
|
p.add_argument('scenario',choices=['recording','review','correction','professional','mixed','idle'])
|
||||||
p.add_argument('--host',required=True);p.add_argument('--port',type=int,default=5443)
|
p.add_argument('--host',required=True);p.add_argument('--port',type=int,default=5443)
|
||||||
p.add_argument('--ca',required=True);p.add_argument('--users-file');p.add_argument('--users',type=int,default=50)
|
p.add_argument('--ca');p.add_argument('--users-file');p.add_argument('--users',type=int,default=50)
|
||||||
p.add_argument('--warmup',type=int,default=1800);p.add_argument('--duration',type=int,default=14400);p.add_argument('--ramp',type=int,default=120)
|
p.add_argument('--warmup',type=int,default=1800);p.add_argument('--duration',type=int,default=14400);p.add_argument('--ramp',type=int,default=120)
|
||||||
p.add_argument('--think-mean-ms',type=int,default=4000);p.add_argument('--think-stddev-ms',type=int,default=2000)
|
p.add_argument('--think-mean-ms',type=int,default=4000);p.add_argument('--think-stddev-ms',type=int,default=2000)
|
||||||
p.add_argument('--session-pause-ms',type=int,default=120000)
|
p.add_argument('--session-pause-ms',type=int,default=120000)
|
||||||
@@ -23,6 +23,8 @@ p.add_argument('--shelly-switch-id',type=int,default=0);p.add_argument('--shelly
|
|||||||
a=p.parse_args()
|
a=p.parse_args()
|
||||||
if a.users<1 or a.duration<1 or a.warmup<0 or a.ramp<0 or min(a.think_mean_ms,a.think_stddev_ms,a.session_pause_ms,a.session_stddev_ms)<0: p.error('Invalid timing/concurrency')
|
if a.users<1 or a.duration<1 or a.warmup<0 or a.ramp<0 or min(a.think_mean_ms,a.think_stddev_ms,a.session_pause_ms,a.session_stddev_ms)<0: p.error('Invalid timing/concurrency')
|
||||||
if a.scenario!='idle' and not a.users_file: p.error('--users-file is required')
|
if a.scenario!='idle' and not a.users_file: p.error('--users-file is required')
|
||||||
|
if a.scenario!='idle' and not a.ca: p.error('--ca is required for application scenarios')
|
||||||
|
if a.scenario=='idle' and a.users_file:p.error('Idle does not use accounts; omit --users-file')
|
||||||
if a.perfmon_interval_ms<1000 or a.perfmon_interval_ms%1000: p.error('PerfMon interval must be a whole number of seconds, at least 1000 ms')
|
if a.perfmon_interval_ms<1000 or a.perfmon_interval_ms%1000: p.error('PerfMon interval must be a whole number of seconds, at least 1000 ms')
|
||||||
agent_host=a.perfmon_host or a.host
|
agent_host=a.perfmon_host or a.host
|
||||||
if not a.no_perfmon: check_agent(agent_host,a.perfmon_port)
|
if not a.no_perfmon: check_agent(agent_host,a.perfmon_port)
|
||||||
@@ -39,9 +41,10 @@ if a.users_file:
|
|||||||
if len(rows)<a.users:
|
if len(rows)<a.users:
|
||||||
if not a.allow_shared_read_account or a.scenario not in ['review','professional']: p.error('Provide at least one distinct account per user. Shared accounts are allowed only for explicitly labelled read-only runs.')
|
if not a.allow_shared_read_account or a.scenario not in ['review','professional']: p.error('Provide at least one distinct account per user. Shared accounts are allowed only for explicitly labelled read-only runs.')
|
||||||
rows=(rows*((a.users+len(rows)-1)//len(rows)))[:a.users]
|
rows=(rows*((a.users+len(rows)-1)//len(rows)))[:a.users]
|
||||||
context=ssl.create_default_context(cafile=a.ca)
|
if a.scenario!='idle':
|
||||||
with urllib.request.urlopen(f'https://{a.host}:{a.port}/api/measurement-guidance',context=context,timeout=15) as r:
|
context=ssl.create_default_context(cafile=a.ca)
|
||||||
if r.status!=200: p.error('Gateway preflight failed')
|
with urllib.request.urlopen(f'https://{a.host}:{a.port}/api/measurement-guidance',context=context,timeout=15) as r:
|
||||||
|
if r.status!=200: p.error('Gateway preflight failed')
|
||||||
# Fail before a long run if accounts, profiles, baseline data or assignments are missing.
|
# Fail before a long run if accounts, profiles, baseline data or assignments are missing.
|
||||||
def get(path,token=None,body=None):
|
def get(path,token=None,body=None):
|
||||||
headers={'Content-Type':'application/json'}
|
headers={'Content-Type':'application/json'}
|
||||||
@@ -59,7 +62,7 @@ for row in {r['account_id']:r for r in rows}.values():
|
|||||||
overview=get('/api/patients/'+row['patient_id']+'/overview?from='+period_from+'&to='+period_to,token)
|
overview=get('/api/patients/'+row['patient_id']+'/overview?from='+period_from+'&to='+period_to,token)
|
||||||
if overview['insight'] is None or overview['latestObservation'] is None: p.error('Seed patient history before running')
|
if overview['insight'] is None or overview['latestObservation'] is None: p.error('Seed patient history before running')
|
||||||
out=Path(a.output).resolve();out.mkdir(parents=True,mode=0o700,exist_ok=False)
|
out=Path(a.output).resolve();out.mkdir(parents=True,mode=0o700,exist_ok=False)
|
||||||
metadata={'scenario':a.scenario,'users':a.users,'measurement_duration_seconds':a.duration,'warmup_seconds':a.warmup,'ramp_seconds':a.ramp,'think_mean_ms':a.think_mean_ms,'think_stddev_ms':a.think_stddev_ms,'session_pause_ms':a.session_pause_ms,'session_stddev_ms':a.session_stddev_ms,'random_seed':a.seed,'host':a.host,'port':a.port,'period_from':period_from,'period_to':period_to,'load_generator':platform.platform(),'distinct_accounts':len({r['account_id'] for r in rows}),'login':'initial login and renewal before expiry included','energy':'Shelly status polled live by JMeter; calculations exclude warmup'}
|
metadata={'scenario':a.scenario,'users':0 if a.scenario=='idle' else a.users,'measurement_duration_seconds':a.duration,'warmup_seconds':a.warmup,'ramp_seconds':0 if a.scenario=='idle' else a.ramp,'think_mean_ms':a.think_mean_ms,'think_stddev_ms':a.think_stddev_ms,'session_pause_ms':a.session_pause_ms,'session_stddev_ms':a.session_stddev_ms,'random_seed':a.seed,'host':a.host,'port':a.port,'period_from':period_from,'period_to':period_to,'load_generator':platform.platform(),'distinct_accounts':len({r['account_id'] for r in rows}),'login':'none; no application requests' if a.scenario=='idle' else 'initial login and renewal before expiry included','energy':'Shelly status polled live by JMeter; calculations exclude warmup'}
|
||||||
runtime_csv=out/'runtime-users.csv'
|
runtime_csv=out/'runtime-users.csv'
|
||||||
with runtime_csv.open('x') as f:
|
with runtime_csv.open('x') as f:
|
||||||
os.chmod(f.name,0o600); w=csv.DictWriter(f,fieldnames=['account_id','password','patient_id']);w.writeheader();w.writerows(rows)
|
os.chmod(f.name,0o600); w=csv.DictWriter(f,fieldnames=['account_id','password','patient_id']);w.writeheader();w.writerows(rows)
|
||||||
@@ -93,6 +96,14 @@ if (out/'timeline.json').exists():
|
|||||||
timeline=json.loads((out/'timeline.json').read_text());metadata.update(timeline)
|
timeline=json.loads((out/'timeline.json').read_text());metadata.update(timeline)
|
||||||
for name in ['warmup_start','measurement_start','measurement_end']:
|
for name in ['warmup_start','measurement_start','measurement_end']:
|
||||||
metadata[name+'_utc']=dt.datetime.fromtimestamp(timeline[name+'_ms']/1000,dt.timezone.utc).isoformat()
|
metadata[name+'_utc']=dt.datetime.fromtimestamp(timeline[name+'_ms']/1000,dt.timezone.utc).isoformat()
|
||||||
|
if a.scenario=='idle':
|
||||||
|
with (out/'samples.csv').open() as f: idle_samples=list(csv.DictReader(f))
|
||||||
|
app_samples=[r for r in idle_samples if r['label'].startswith('HTTP ')]
|
||||||
|
metadata.update(http_samples=len(app_samples),measured_http_samples=len(app_samples),measured_http_requests_per_second=0,failed_samples_including_scripts=sum(r['success'].lower()!='true' for r in idle_samples))
|
||||||
|
if app_samples or metadata['failed_samples_including_scripts']:
|
||||||
|
print('Idle baseline contains application requests or failed samples');code=1
|
||||||
|
if metadata['actual_elapsed_seconds']+2<a.warmup+a.duration:
|
||||||
|
print('Idle baseline stopped early; measurement is incomplete');code=1
|
||||||
if a.scenario!='idle' and (out/'samples.csv').exists():
|
if a.scenario!='idle' and (out/'samples.csv').exists():
|
||||||
with (out/'samples.csv').open() as f: all_samples=list(csv.DictReader(f))
|
with (out/'samples.csv').open() as f: all_samples=list(csv.DictReader(f))
|
||||||
samples=[r for r in all_samples if r['label'].startswith('HTTP ')]
|
samples=[r for r in all_samples if r['label'].startswith('HTTP ')]
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Verify the idle runner makes zero application requests, including preflight."""
|
||||||
|
import csv,json,subprocess,tempfile,threading
|
||||||
|
from pathlib import Path
|
||||||
|
from http.server import BaseHTTPRequestHandler,ThreadingHTTPServer
|
||||||
|
HERE=Path(__file__).parent
|
||||||
|
class Application(BaseHTTPRequestHandler):
|
||||||
|
requests=0
|
||||||
|
def do_GET(self):
|
||||||
|
type(self).requests+=1;self.send_response(500);self.end_headers()
|
||||||
|
do_POST=do_GET
|
||||||
|
def log_message(self,*args):pass
|
||||||
|
server=ThreadingHTTPServer(('127.0.0.1',0),Application)
|
||||||
|
threading.Thread(target=server.serve_forever,daemon=True).start()
|
||||||
|
try:
|
||||||
|
with tempfile.TemporaryDirectory(prefix='healthapp-idle-') as name:
|
||||||
|
out=Path(name)/'run'
|
||||||
|
result=subprocess.run(['python3',str(HERE/'run.py'),'idle','--host','127.0.0.1','--port',str(server.server_port),'--no-perfmon','--no-shelly','--warmup','1','--duration','3','--output',str(out)],capture_output=True,text=True)
|
||||||
|
assert result.returncode==0,result.stdout+result.stderr
|
||||||
|
data=json.loads((out/'run.json').read_text())
|
||||||
|
assert Application.requests==0 and data['http_samples']==0 and data['users']==0
|
||||||
|
assert data['measurement_end_ms']-data['measurement_start_ms']==3000
|
||||||
|
assert data['measurement_start_ms']-data['warmup_start_ms']==1000
|
||||||
|
with (out/'samples.csv').open() as f:assert all(not r['label'].startswith('HTTP ') for r in csv.DictReader(f))
|
||||||
|
print('Idle baseline passed: no application calls or login, no CA/accounts needed, warmup excluded')
|
||||||
|
finally:server.shutdown()
|
||||||
Reference in new issue
Block a user