Skip to content

Commit

Permalink
[SPARK-21254][WebUI] Removing unnecessary DOM processing
Browse files Browse the repository at this point in the history
Logic related to `hasMultipleAttempts` flag:

 - Hiding attmptId column (if `hasMultipleAttempts = false`)
 - Seting white background color for first 2 columns (if `hasMultipleAttempts = true`)

was updating DOM after mustache template processing, which was causing 2 unnecessary
iterations over full data set (first through jquery selector, than through for-loop).

Refactoring it inside mustache template helps saving 80-90ms on large data sets (10k+ rows)
  • Loading branch information
2ooom committed Jul 31, 2017
1 parent 332b398 commit 0af596a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
App Name
</span>
</th>
<th class="attemptIDSpan">
{{#hasMultipleAttempts}}
<th>
<span data-toggle="tooltip" data-placement="top" title="The attempt ID of this application since one application might be launched several times">
Attempt ID
</span>
</th>
{{/hasMultipleAttempts}}
<th>
<span data-toggle="tooltip" data-placement="top" title="Started time of this application.">
Started
Expand Down Expand Up @@ -68,10 +70,12 @@
<tbody>
{{#applications}}
<tr>
<td class="rowGroupColumn"><span title="{{id}}"><a href="{{uiroot}}/history/{{id}}/{{num}}/jobs/">{{id}}</a></span></td>
<td class="rowGroupColumn">{{name}}</td>
<td {{#hasMultipleAttempts}}style="background-color:#fff"{{/hasMultipleAttempts}}><span title="{{id}}"><a href="{{uiroot}}/history/{{id}}/{{num}}/jobs/">{{id}}</a></span></td>
<td {{#hasMultipleAttempts}}style="background-color:#fff"{{/hasMultipleAttempts}}>{{name}}</td>
{{#attempts}}
<td class="attemptIDSpan"><a href="{{uiroot}}/history/{{id}}/{{attemptId}}/jobs/">{{attemptId}}</a></td>
{{#hasMultipleAttempts}}
<td><a href="{{uiroot}}/history/{{id}}/{{attemptId}}/jobs/">{{attemptId}}</a></td>
{{/hasMultipleAttempts}}
<td>{{startTime}}</td>
<td class="completedColumn">{{endTime}}</td>
<td class="durationColumn"><span title="{{durationMillisec}}">{{duration}}</span></td>
Expand Down
77 changes: 40 additions & 37 deletions core/src/main/resources/org/apache/spark/ui/static/historypage.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ function getParameterByName(name, searchString) {
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

function removeColumnByName(columns, columnName) {
return columns.filter(function(col) {return col.name != columnName})
}

function getColumnIndex(columns, columnName) {
for(var i = 0; i < columns.length; i++) {
if (columns[i].name == columnName)
return i;
}
return -1;
}

jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"title-numeric-pre": function ( a ) {
var x = a.match(/title="*(-?[0-9\.]+)/)[1];
Expand Down Expand Up @@ -134,51 +146,38 @@ $(document).ready(function() {

var data = {
"uiroot": uiRoot,
"applications": array
}
"applications": array,
"hasMultipleAttempts": hasMultipleAttempts,
}

$.get("static/historypage-template.html", function(template) {
var apps = $(Mustache.render($(template).filter("#history-summary-template").html(),data));
var selector = "#history-summary-table";
var attemptIdColumnName = 'attemptId';
var defaultSortColumn = completedColumnName = 'completed';
var durationColumnName = 'duration';
var conf = {
"columns": [
{name: 'first', type: "appid-numeric"},
{name: 'second'},
{name: 'third'},
{name: 'fourth'},
{name: 'fifth'},
{name: 'sixth', type: "title-numeric"},
{name: 'seventh'},
{name: 'eighth'},
{name: 'ninth'},
],
"columnDefs": [
{"searchable": false, "targets": [5]}
],
"autoWidth": false,
"order": [[ 4, "desc" ]]
};

var rowGroupConf = {
"rowsGroup": [
'first:name',
'second:name'
],
"columns": [
{name: 'appId', type: "appid-numeric"},
{name: 'appName'},
{name: attemptIdColumnName},
{name: 'started'},
{name: completedColumnName},
{name: durationColumnName, type: "title-numeric"},
{name: 'user'},
{name: 'lastUpdated'},
{name: 'eventLog'},
],
"autoWidth": false,
};

if (hasMultipleAttempts) {
jQuery.extend(conf, rowGroupConf);
var rowGroupCells = apps.find(".rowGroupColumn");
for (i = 0; i < rowGroupCells.length; i++) {
rowGroupCells[i].style='background-color: #ffffff';
}
}

if (!hasMultipleAttempts) {
var attemptIDCells = apps.find(".attemptIDSpan");
for (i = 0; i < attemptIDCells.length; i++) {
attemptIDCells[i].style.display='none';
}
conf.rowsGroup = [
'appId:name',
'appName:name'
];
} else {
conf.columns = removeColumnByName(conf.columns, attemptIdColumnName);
}

if (requestedIncomplete) {
Expand All @@ -192,6 +191,10 @@ $(document).ready(function() {
durationCells[i].style.display='none';
}
}
conf.order = [[ getColumnIndex(conf.columns, defaultSortColumn), "desc" ]];
conf.columnDefs = [
{"searchable": false, "targets": [getColumnIndex(conf.columns, durationColumnName)]}
];
historySummary.append(apps);
$(selector).DataTable(conf);
$('#history-summary [data-toggle="tooltip"]').tooltip();
Expand Down

0 comments on commit 0af596a

Please sign in to comment.