Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

Monitor: the host reads the graphics card every 3 s only while a model runs or the Monitor is open, every 30 s otherwise, and the PCIe sample only while a model runs (#4066)

Niko1221085dcded737f
diff --git a/apps/host/server/device-probes.mjs b/apps/host/server/device-probes.mjs
index f29bd6669..cee55a4b4 100644
--- a/apps/host/server/device-probes.mjs
+++ b/apps/host/server/device-probes.mjs
@@ -73,14 +73,15 @@ export async function detectDrmGpus() {
}
return result;
}
-export async function readGpuTelemetry(gpus) {
+/** `transfer: false` skips the PCIe throughput sample (a second nvidia-smi); it only means something while a model runs. */
+export async function readGpuTelemetry(gpus, { transfer: wantTransfer = true, run = probe } = {}) {
const now=new Date().toISOString();
const hasNvidia=gpus.some(g=>g.vendor==='nvidia');
- let raw=hasNvidia?await probe('nvidia-smi',['--query-gpu=uuid,temperature.gpu,utilization.gpu,memory.used,power.draw,power.limit,pcie.link.gen.current,pcie.link.gen.max,pcie.link.width.current','--format=csv,noheader,nounits'],2000):'';
+ let raw=hasNvidia?await run('nvidia-smi',['--query-gpu=uuid,temperature.gpu,utilization.gpu,memory.used,power.draw,power.limit,pcie.link.gen.current,pcie.link.gen.max,pcie.link.width.current','--format=csv,noheader,nounits'],2000):'';
// Older drivers can reject a field; retain their basic sensors in that case.
- if(hasNvidia&&!raw)raw=await probe('nvidia-smi',['--query-gpu=uuid,temperature.gpu,utilization.gpu,memory.used','--format=csv,noheader,nounits'],2000);
+ if(hasNvidia&&!raw)raw=await run('nvidia-smi',['--query-gpu=uuid,temperature.gpu,utilization.gpu,memory.used','--format=csv,noheader,nounits'],2000);
const nvidia=new Map(parseNvidiaReadings(raw).map(r=>[r.id,r]));
- const transfer=hasNvidia?parsePcieThroughput(await probe('nvidia-smi',['dmon','-s','t','-c','1'],1500)):new Map();
+ const transfer=hasNvidia&&wantTransfer?parsePcieThroughput(await run('nvidia-smi',['dmon','-s','t','-c','1'],1500)):new Map();
return Promise.all(gpus.map(async gpu=>{
let reading=nvidia.get(gpu.id)??{id:gpu.id??`${gpu.vendor}:${gpu.index}`,temperatureC:null,utilizationPct:null,memoryUsedGb:null,powerW:null,powerLimitW:null,pcieGen:null,pcieGenMax:null,pcieWidth:null,pcieRxMbs:null};
if(gpu.vendor==='nvidia')reading={...reading,pcieRxMbs:transfer.get(gpu.sensorIndex??gpu.index)??null};
diff --git a/apps/host/server/index.mjs b/apps/host/server/index.mjs
index 0025520ad..b9640e1db 100644
--- a/apps/host/server/index.mjs
+++ b/apps/host/server/index.mjs
@@ -224,6 +224,7 @@ models.init(hub);
engine.init(hub);
engineInstall.init(hub);
monitor.init(hub, boot);
+monitor.setLiveProbe(() => native.hasLive());
serving.init(hub, { port: PORT, host: HOST });
runtimeModels=createRuntimeModels({hardware:()=>hardware.cachedHardware()??boot,library:()=>models.library(),requests:()=>serving.state().requests,real:models.REAL,changed:value=>{
if(!models.REAL){const primary=value.instances.find(i=>i.id===value.defaultId);if(store.get().loaded!==(primary?.variantId??null))store.update({loaded:primary?.variantId??null});}
@@ -1586,7 +1587,7 @@ async function api(req, res, path, method, url) {
if (cancelMatch && method === 'POST') return json(res, 200, serving.cancel(cancelMatch[1]));
// --- monitor ------------------------------------------------------------
- if (path === '/api/monitor') return json(res, 200, monitor.snapshot());
+ if (path === '/api/monitor') { monitor.watch(); return json(res, 200, monitor.snapshot()); }
// --- skills / workspace -------------------------------------------------
if (path === '/api/skills' && method === 'GET') {
diff --git a/apps/host/server/monitor.mjs b/apps/host/server/monitor.mjs
index 4c6733603..e07e291fb 100644
--- a/apps/host/server/monitor.mjs
+++ b/apps/host/server/monitor.mjs
@@ -3,6 +3,7 @@ import { variant as catalogVariant, footprint } from './catalog.mjs';
import { detect, cachedHardware } from './hardware.mjs';
import { readGpuTelemetry, gpuMemoryTotals } from './device-probes.mjs';
import { createSystemSampler } from './system-telemetry.mjs';
+import { sensorPace, WATCH_MS } from './sensor-pace.mjs';
import { state as servingState } from './serving.mjs';
import { originalDashboard } from './monitor-dashboard.mjs';
import { get as getStore } from './store.mjs';
@@ -58,6 +59,14 @@ let hwCache = null;
let ticker = null;
let memoryWarningShown = false;
let sensorsPending = false, sensorsAt = 0;
+/* The Monitor screen asks (GET /api/monitor) every few seconds while it is open; a model that is loaded counts as live (#4066). */
+let watchedUntil = 0, liveProbe = () => false;
+export function watch() {
+ const wasIdle = Date.now() >= watchedUntil;
+ watchedUntil = Date.now() + WATCH_MS;
+ if (wasIdle) sensorsAt = 0; // opening the Monitor after a quiet spell reads the card at once
+}
+export function setLiveProbe(probe) { liveProbe = typeof probe === 'function' ? probe : () => false; }
let systemReading=null;
const sampleSystem=createSystemSampler();
const finite = value => typeof value==='number'&&Number.isFinite(value);
@@ -108,10 +117,11 @@ function approach(current, target, factor = 0.22) {
}
function tick() {
- if(!sensorsPending&&Date.now()-sensorsAt>=3000){
+ const pace=sensorPace({live:supervisor.status().running||!!liveProbe(),watchedUntil});
+ if(!sensorsPending&&Date.now()-sensorsAt>=pace.intervalMs){
sensorsPending=true;sensorsAt=Date.now();
const hardware=cachedHardware()??hwCache;
- void Promise.all([readGpuTelemetry(hardware?.gpus??[]),sampleSystem(hardware?.processors??[])])
+ void Promise.all([readGpuTelemetry(hardware?.gpus??[],{transfer:pace.transfer}),sampleSystem(hardware?.processors??[])])
.then(([readings,system])=>{state.hardware.gpus=readings;systemReading=system;})
.catch(()=>{state.hardware.gpus=[];systemReading=null;})
.finally(()=>{sensorsPending=false;});
diff --git a/apps/host/server/sensor-pace.mjs b/apps/host/server/sensor-pace.mjs
new file mode 100644
index 000000000..b8884bb87
--- /dev/null
+++ b/apps/host/server/sensor-pace.mjs
@@ -0,0 +1,16 @@
+/**
+ * How often the host asks the graphics card driver for its readings (#4066).
+ * It used to start two nvidia-smi processes every 3 s for as long as the app was open, even with nothing loaded and
+ * the Monitor out of sight; on some PCs that was felt as a stutter while typing. Now the 3 s pace is kept while a model
+ * runs or the Monitor is being looked at, and an idle app asks once every 30 s.
+ */
+export const ACTIVE_MS = 3000;
+export const IDLE_MS = 30000;
+/** The Monitor screen asks again every 10 s while it is open; this is how long one ask keeps the fast pace. */
+export const WATCH_MS = 25000;
+
+/** `live`: a model is loaded or an engine runs. `watchedUntil`: ms timestamp until which the Monitor was last seen open. */
+export function sensorPace({ live = false, watchedUntil = 0, now = Date.now() } = {}) {
+ const watched = now < watchedUntil;
+ return { intervalMs: live || watched ? ACTIVE_MS : IDLE_MS, transfer: !!live };
+}
diff --git a/apps/host/src/screens/Monitor.tsx b/apps/host/src/screens/Monitor.tsx
index 87cd4f58c..451ea29db 100644
--- a/apps/host/src/screens/Monitor.tsx
+++ b/apps/host/src/screens/Monitor.tsx
@@ -2,7 +2,7 @@ import {localeTag} from '../lib/i18n';
import { tr } from '../lib/i18n';
import { scopedMonitor, instanceLabel, deviceLabel } from '../lib/runtime-models';
/** The original Strata dashboard, adapted to the current shell and device inventory. */
-import { useRef, useState, type ReactNode } from 'react';
+import { useEffect, useRef, useState, type ReactNode } from 'react';
import { flushSync } from 'react-dom';
import { SnapshotDialog } from '../components/SnapshotDialog';
import { requestSummary } from '../lib/monitor-summary';
@@ -14,6 +14,7 @@ import { Screen } from '../components/layout';
import { contextLabel, duration, tokens, tps } from '../lib/format';
import { defaultGpuSet, gpuCapacity, gpuId, gpuMetric, gpuReported, hasReading, shortGpuName } from '../lib/monitor-hardware';
import { useStore } from '../lib/store';
+import { api } from '../lib/client';
import { useKept } from '../lib/kept-state';
import type { Hardware, MonitorState, ServeRequest } from '../lib/types';
import { useNative, nativeRouting, type NativeState } from '../lib/native';
@@ -57,6 +58,14 @@ function requestStatus(request: ServeRequest) {
}
export function MonitorScreen() {
const native = useNative();
+ // While this screen is open and visible the host reads the graphics card every 3 s; otherwise it asks only every 30 s (#4066).
+ useEffect(() => {
+ const ask = () => { if (typeof document === 'undefined' || document.visibilityState !== 'hidden')
+ void api.get('/api/monitor').catch(() => undefined); };
+ ask();
+ const timer = setInterval(ask, 10000);
+ return () => clearInterval(timer);
+ }, []);
return <LegacyMonitorScreen native={native?.instances.length ? native : null}/>;
}
function LegacyMonitorScreen({ native }: {
diff --git a/apps/host/tests/sensor-pace.test.mjs b/apps/host/tests/sensor-pace.test.mjs
new file mode 100644
index 000000000..46d99f37e
--- /dev/null
+++ b/apps/host/tests/sensor-pace.test.mjs
@@ -0,0 +1,49 @@
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import { readFile } from 'node:fs/promises';
+import { sensorPace, ACTIVE_MS, IDLE_MS, WATCH_MS } from '../server/sensor-pace.mjs';
+import { readGpuTelemetry } from '../server/device-probes.mjs';
+
+test('an idle app with the Monitor out of sight asks the card rarely (#4066)', () => {
+ const idle = sensorPace({ live: false, watchedUntil: 0, now: 1_000 });
+ assert.equal(idle.intervalMs, IDLE_MS);
+ assert.equal(idle.transfer, false);
+ assert.ok(IDLE_MS >= 10 * ACTIVE_MS);
+});
+
+test('a running model or an open Monitor keeps the 3 s pace', () => {
+ assert.equal(sensorPace({ live: true, now: 1_000 }).intervalMs, ACTIVE_MS);
+ assert.equal(sensorPace({ live: true, now: 1_000 }).transfer, true);
+ const watched = sensorPace({ live: false, watchedUntil: 1_000 + WATCH_MS, now: 1_000 });
+ assert.equal(watched.intervalMs, ACTIVE_MS);
+ assert.equal(watched.transfer, false, 'the PCIe sample only means something while a model runs');
+ assert.equal(sensorPace({ live: false, watchedUntil: 1_000, now: 1_000 + 1 }).intervalMs, IDLE_MS);
+});
+
+const gpus = [{ id: 'GPU-1', vendor: 'nvidia', index: 0, sensorIndex: 0 }];
+const calls = [];
+const run = async (cmd, args) => {
+ calls.push(args[0]);
+ return args[0] === 'dmon' ? '# gpu rxpci txpci\n# Idx MB/s MB/s\n 0 12 3' : 'GPU-1, 41, 5, 1024, 30.5, 200, 4, 4, 16';
+};
+
+test('without the PCIe sample one nvidia-smi process is started, with it two', async () => {
+ calls.length = 0;
+ const idle = await readGpuTelemetry(gpus, { transfer: false, run });
+ assert.deepEqual(calls.map(c => c === 'dmon' ? 'dmon' : 'query'), ['query']);
+ assert.equal(idle[0].temperatureC, 41);
+ calls.length = 0;
+ await readGpuTelemetry(gpus, { run });
+ assert.deepEqual(calls.map(c => c === 'dmon' ? 'dmon' : 'query'), ['query', 'dmon']);
+});
+
+test('the monitor uses the pace, the Monitor screen asks while it is open, and /api/monitor marks it watched', async () => {
+ const monitor = await readFile(new URL('../server/monitor.mjs', import.meta.url), 'utf8');
+ assert.match(monitor, /sensorPace\(/);
+ assert.doesNotMatch(monitor, /sensorsAt>=3000/);
+ const index = await readFile(new URL('../server/index.mjs', import.meta.url), 'utf8');
+ assert.match(index, /monitor\.watch\(\); return json\(res, 200, monitor\.snapshot\(\)\)/);
+ assert.match(index, /monitor\.setLiveProbe\(/);
+ const screen = await readFile(new URL('../src/screens/Monitor.tsx', import.meta.url), 'utf8');
+ assert.match(screen, /api\.get\('\/api\/monitor'\)/);
+});