Skip to content

Improve performance of Top tables#1616

Merged
rmars merged 2 commits intomasterfrom
rmars/improve-top
Sep 10, 2018
Merged

Improve performance of Top tables#1616
rmars merged 2 commits intomasterfrom
rmars/improve-top

Conversation

@rmars
Copy link

@rmars rmars commented Sep 10, 2018

Problem
We receive a lot of websocket events from the tap server. Previously, we were processing each event as we received it, then calling setState after processing to update the tables. Each call to setState triggered a re-render of the whole table. We were rerendering multiplie times a second, causing the whole page to become unresponsive.

Solution
throttle setState for receiving websocket tap events to prevent continuous rerendering.
Store the tap events in an index outside of state, and only update the state once every specified interval (currently 500ms).

We can now view entire namespaces with Top and the page won't crash!
To verify: Go to /top and try topping a namespace

For more reading:
https://css-tricks.com/debouncing-throttling-explained-examples/
https://nolanlawson.com/2018/09/01/a-tour-of-javascript-timers-on-the-web/

Part of #1601

@rmars rmars added the area/web label Sep 10, 2018
@rmars rmars self-assigned this Sep 10, 2018
Copy link
Member

@siggy siggy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good!

not sure if related to this branch, but a moment after i hit Stop, i get a Websocket [1006] error:
screen shot 2018-09-10 at 2 17 54 pm

super(props);
this.tapResultsById = {};
this.topEventIndex = {};
this.debouncedWebsocketRecvHandler = _.throttle(this.updateTapEventIndexState, 500);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL _.debounce (and _.throttle)!

what do you think about setting leading: true, to make the initial event pop up immediately after the user hits Start?

_.throttle(this.updateTapEventIndexState, 500, {
  'leading': true,
  'trailing': false
});

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On throttle, I believe the default value for leading is true. I think the inital delay is the delay in establishing the websocket connection and sending the query.

Copy link
Contributor

@dadjeibaah dadjeibaah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty cool fix! The changes are pretty significant. 📦

@dadjeibaah
Copy link
Contributor

@siggy working on that 1006 issue. Its tracked by #1504

Copy link
Contributor

@klingerf klingerf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⭐️ This is awesome! Am going to take the same approach with the tap table.

@rmars rmars merged commit 55402da into master Sep 10, 2018
@rmars rmars deleted the rmars/improve-top branch September 10, 2018 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants