mirror of https://github.com/grafana/grafana
Live: throttle messages when FPS decreases (#32627)
* throttle when FPS is low * fix throttling * grafanaStreamingPerfBudget * grafanaStreamingPerfBudget * change global strategy * also throttle frontend Co-authored-by: Leon Sorokin <leeoniya@gmail.com>pull/32806/head
parent
8ab223d79f
commit
455fbce020
@ -0,0 +1,28 @@ |
||||
let lastUpdate = Date.now(); |
||||
|
||||
/** |
||||
* This object indicats how overloaded the main thread is |
||||
*/ |
||||
export const perf = { |
||||
budget: 1, |
||||
threshold: 1.05, // trial and error appears about right
|
||||
ok: true, |
||||
last: lastUpdate, |
||||
}; |
||||
|
||||
// Expose this as a global object so it can be changed locally
|
||||
// NOTE: when we are confident this is the right budget, this should be removed
|
||||
(window as any).grafanaStreamingPerf = perf; |
||||
|
||||
// target is 20hz (50ms), but we poll at 100ms to smooth out jitter
|
||||
const interval = 100; |
||||
|
||||
function measure() { |
||||
const now = Date.now(); |
||||
perf.last = now; |
||||
perf.budget = (now - lastUpdate) / interval; |
||||
perf.ok = perf.budget <= perf.threshold; |
||||
lastUpdate = now; |
||||
} |
||||
|
||||
setInterval(measure, interval); |
Loading…
Reference in new issue