Skip to content

Commit dfe967c

Browse files
committed
Scalability: Add deboucing for several API in the UI, to better handle large job / queue throughput.
1 parent 56558c1 commit dfe967c

2 files changed

Lines changed: 25 additions & 9 deletions

File tree

htdocs/js/pages/Events.class.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Page.Events = class Events extends Page.PageUtils {
1010
// called once at page load
1111
this.default_sub = 'list';
1212
this.dom_prefix = 'ee';
13+
14+
this.handleJobsChangedViewDebounce = debounce( this.handleJobsChangedView.bind(this), 1000 );
1315
}
1416

1517
onActivate(args) {
@@ -1243,19 +1245,26 @@ Page.Events = class Events extends Page.PageUtils {
12431245
} ); // confirm
12441246
}
12451247

1248+
handleJobsChangedView() {
1249+
// called via debounce when jobs changed on view page
1250+
if (!this.active || !this.event) return; // sanity
1251+
1252+
this.renderActiveJobs();
1253+
this.getQueuedJobs();
1254+
this.fetchJobHistory();
1255+
1256+
// recompute upcoming: shift() entries off if they happened
1257+
this.autoExpireUpcomingJobs();
1258+
this.renderUpcomingJobs();
1259+
}
1260+
12461261
handleStatusUpdateView(data) {
12471262
// received status update from server, see if major or minor
12481263
var self = this;
12491264
var div = this.div;
12501265

12511266
if (data.jobsChanged) {
1252-
this.renderActiveJobs();
1253-
this.getQueuedJobs();
1254-
this.fetchJobHistory();
1255-
1256-
// recompute upcoming: shift() entries off if they happened
1257-
this.autoExpireUpcomingJobs();
1258-
this.renderUpcomingJobs();
1267+
this.handleJobsChangedViewDebounce();
12591268
}
12601269
else {
12611270
// fast update without redrawing entire table

htdocs/js/pages/Job.class.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Page.Job = class Job extends Page.PageUtils {
1010
// called once at page load
1111
this.colors = app.colors;
1212
this.header_bar_width = 175;
13+
14+
// throttle this API call for dealing with heavy jobs
15+
this.getWorkflowQueueSummaryDebounce = debounce( this.getWorkflowQueueSummary.bind(this), 1000 );
1316
}
1417

1518
onActivate(args) {
@@ -1061,7 +1064,7 @@ Page.Job = class Job extends Page.PageUtils {
10611064
this.decorateWorkflowNodes();
10621065

10631066
// we have to fetch queued job information separately
1064-
if (!this.job.final) this.getWorkflowQueueSummary();
1067+
if (!this.job.final) this.getWorkflowQueueSummaryDebounce();
10651068

10661069
// show orange notification if sus level has increased
10671070
if (!this.lastSuspendedCount) this.lastSuspendedCount = 0;
@@ -1235,14 +1238,18 @@ Page.Job = class Job extends Page.PageUtils {
12351238
getWorkflowQueueSummary() {
12361239
// fetch summary of queued job counts per node
12371240
var self = this;
1241+
if (!self.active || !self.job || self.job.final) return; // sanity checks
1242+
12381243
var workflow = this.job.workflow;
12391244
var $cont = this.wfGetContainer();
1245+
if (!workflow || !workflow.nodes || !$cont.length) return; // more sanity checks
12401246

12411247
app.api.get( 'app/get_workflow_job_summary', { 'workflow.job': this.job.id, state: 'queued' }, function(resp) {
1242-
if (!self.active || !resp || !resp.nodes || !self.job || self.job.final) return; // sanity checks
1248+
if (!self.active || !resp || !resp.nodes || !self.job || self.job.final) return; // even more sanity checks
12431249

12441250
workflow.nodes.filter( function(node) { return !!node.type.match(/^(event|job)$/); } ).forEach( function(node) {
12451251
var $div = $cont.find(`#d_wfn_${node.id} > .wf_active_bar > .wf_active_widget.wf_queued`);
1252+
if (!$div.length) return; // sanity
12461253
var count = resp.nodes[node.id] || 0;
12471254

12481255
if (count) $div.show().html( `<i class="mdi mdi-tray-full"></i><span>${commify(count)}</span>` );

0 commit comments

Comments
 (0)