Skip to content

Conversation

@2ooom
Copy link
Contributor

@2ooom 2ooom commented Jul 30, 2017

What changes were proposed in this pull request?

As described in JIRA ticket, History page is taking ~1min to load for cases when amount of jobs is 10k+.
Most of the time is currently being spent on DOM manipulations and all additional costs implied by this (browser repaints and reflows).
PR's goal is not to change any behavior but to optimize time of History UI rendering:

  1. The most costly operation is setting innerHTML for duration column within a loop, which is extremely unperformant. Refactoring this helped to get time down to 10-15s

  2. Second big gain bringing page load time down to 4s was was achieved by detaching table's DOM before parsing it with DataTables jQuery plugin.

  3. Another chunk of improvements (1, 2, 3) was focused on removing unnecessary DOM manipulations that in total contributed ~250ms to page load time.

How was this patch tested?

Tested by existing Selenium tests in org.apache.spark.deploy.history.HistoryServerSuite. Version of HtmlUnitDriver had a bug that was preventing rendering the full table and making test ajax rendered relative links are prefixed with uiRoot (spark.ui.proxyBase) constantly fail.

Changes were also tested on Criteo's spark-2.1 fork with 20k+ number of rows in the table, reducing load time to 4s.

2ooom and others added 6 commits July 30, 2017 22:32
…ssing

Currently all the DOM manipulations are handled in a loop after Mustache
template is parsed. This causes severe performance issues especially within
loops iteration over thousands of (attempt/application) records and causing
all kinds of unnecessary browser work: reflow, repaint, etc.

This could be easily fixed by preparing a DOM node beforehand and doing all
manipulations within the loops on detached node, reattaching it to the document
only after the work is done.

The most costly operation in this case was setting innerHTML for `duration`
column within a loop, which is extremely unperformant:

https://jsperf.com/jquery-append-vs-html-list-performance/24

While duration parsing could be done before mustache-template processing without
any additional DOM alteratoins.
Check whether to display pagination or not on large data sets (10-20k rows)
was taking up to 50ms because it was iterating over all rows. This could be
easily done by testing length of array before passing it to mustache.
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)
Refactoring incomplete requests filter behavior due to inefficency in DOM
manipulations. We were traversing DOM 2 more times just to hide columns
that we could have avoided rendering in mustache. Factoring this logic in
mustache template (`showCompletedColumn`) saves 70-80ms on 10k+ rows.
…essing

Detaching history table wrapper from document before parsing it with DataTables plugin
and reattaching back right after plugin has processed nested DOM. This allows to avoid
huge amount of browser repaints and reflows, reducing initial page load time in Chrome
from 15s to 4s for 20k+ rows
@AmplabJenkins
Copy link

Can one of the admins verify this patch?

@2ooom 2ooom closed this Jul 31, 2017
@2ooom 2ooom deleted the history-ui-perf-fix-upstream-2.1 branch August 6, 2017 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants