Skip to content

Commit f0e06fb

Browse files
committed
tune update frequency
1 parent 86665f0 commit f0e06fb

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/api-monitor-cs-main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { windowListen, windowPost } from '@/api/communication.ts';
22
import { IS_DEV } from './api/env.ts';
33
import {
44
TELEMETRY_FREQUENCY_1PS,
5-
TELEMETRY_FREQUENCY_60PS,
5+
TELEMETRY_FREQUENCY_30PS,
66
} from '@/api/const.ts';
77
import { Timer } from '@/api/time.ts';
88
import {
@@ -76,7 +76,7 @@ windowListen((o) => {
7676
// adaptive update-frequency
7777
const ackTrafficDuration = Date.now() - o.timeSent;
7878
const newDelay = (o.trafficDuration + ackTrafficDuration) * 3;
79-
tick.delay = Math.max(TELEMETRY_FREQUENCY_60PS, newDelay);
79+
tick.delay = Math.max(TELEMETRY_FREQUENCY_30PS, newDelay);
8080
} else if (o.msg === 'start-observe') {
8181
startObserve();
8282
} else if (o.msg === 'stop-observe') {

src/api/const.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export const ERRORS_IGNORED = [
44
];
55
export const TELEMETRY_FREQUENCY_30PS = 100 / 3; //MS
66
export const TELEMETRY_FREQUENCY_1PS = 1000; // ms
7+
export const MAX_TRAFFIC_DURATION_BEFORE_AUTOPAUSE = 2e3; // ms
78
// store native functions
89
export const setTimeout = window.setTimeout.bind(window);
910
export const clearTimeout = window.clearTimeout.bind(window);

src/view/App.svelte

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import InfoBar from '@/view/components/InfoBar.svelte';
1313
import { getSettings, setSettings } from '@/api/settings.ts';
1414
import TickSpinner from '@/view/components/TickSpinner.svelte';
15+
import { MAX_TRAFFIC_DURATION_BEFORE_AUTOPAUSE } from '@/api/const.ts';
1516
1617
let spinner: TickSpinner | null = null;
1718
let paused = false;
@@ -25,11 +26,17 @@
2526
msg = o.metrics;
2627
2728
const now = Date.now();
28-
portPost({
29-
msg: 'telemetry-acknowledged',
30-
trafficDuration: now - o.metrics.collectingStartTime,
31-
timeSent: now,
32-
});
29+
const trafficDuration = now - o.metrics.collectingStartTime;
30+
31+
if (trafficDuration > MAX_TRAFFIC_DURATION_BEFORE_AUTOPAUSE) {
32+
!paused && onTogglePause();
33+
} else {
34+
portPost({
35+
msg: 'telemetry-acknowledged',
36+
trafficDuration,
37+
timeSent: now,
38+
});
39+
}
3340
3441
spinner?.tick();
3542
}

0 commit comments

Comments
 (0)