From 81ec76bdef03e3706bd7502703a58f6195c5e70f Mon Sep 17 00:00:00 2001 From: Andrej Ocenas Date: Fri, 13 Sep 2019 10:58:29 +0200 Subject: [PATCH] Explore: Add throttling when doing live queries (#19085) --- public/app/features/explore/state/actions.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/public/app/features/explore/state/actions.ts b/public/app/features/explore/state/actions.ts index c09d0f8c2c1..b6de5dbd0e5 100644 --- a/public/app/features/explore/state/actions.ts +++ b/public/app/features/explore/state/actions.ts @@ -1,5 +1,6 @@ // Libraries -import { map } from 'rxjs/operators'; +import { map, throttleTime } from 'rxjs/operators'; +import { identity } from 'rxjs'; // Services & Utils import store from 'app/core/store'; import { getDatasourceSrv } from 'app/features/plugins/datasource_srv'; @@ -481,9 +482,11 @@ export function runQueries(exploreId: ExploreId): ThunkResult { const newQuerySub = runRequest(datasourceInstance, transaction.request) .pipe( - map((data: PanelData) => { - return preProcessPanelData(data, queryResponse); - }) + map((data: PanelData) => preProcessPanelData(data, queryResponse)), + // Simple throttle for live tailing, in case of > 1000 rows per interval we spend about 200ms on processing and + // rendering. In case this is optimized this can be tweaked, but also it should be only as fast as user + // actually can see what is happening. + live ? throttleTime(500) : identity ) .subscribe((data: PanelData) => { if (!data.error && firstResponse) {