Skip to content

Commit

Permalink
Removed nodes delta buffering code.
Browse files Browse the repository at this point in the history
  • Loading branch information
fbarl committed Jul 3, 2017
1 parent ca699d6 commit dc985dc
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 142 deletions.
49 changes: 3 additions & 46 deletions client/app/scripts/actions/app-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import {
resourceViewAvailableSelector,
} from '../selectors/topology';

import { NODES_DELTA_BUFFER_SIZE_LIMIT } from '../constants/limits';
import { NODES_DELTA_BUFFER_FEED_INTERVAL } from '../constants/timer';
import {
GRAPH_VIEW_MODE,
TABLE_VIEW_MODE,
Expand All @@ -41,8 +39,6 @@ import {

const log = debug('scope:app-actions');

// TODO: This shouldn't be exposed here as a global variable.
let nodesDeltaBufferUpdateTimer = null;

export function showHelp() {
return { type: ActionTypes.SHOW_HELP };
Expand Down Expand Up @@ -76,11 +72,6 @@ export function sortOrderChanged(sortedBy, sortedDesc) {
};
}

function resetNodesDeltaBuffer() {
clearInterval(nodesDeltaBufferUpdateTimer);
return { type: ActionTypes.CLEAR_NODES_DELTA_BUFFER };
}


//
// Networks
Expand Down Expand Up @@ -217,7 +208,6 @@ export function changeTopologyOption(option, value, topologyId, addOrRemove) {
});
updateRoute(getState);
// update all request workers with new options
dispatch(resetNodesDeltaBuffer());
const state = getState();
getTopologies(state, dispatch);
updateWebsocketChannel(state, dispatch);
Expand Down Expand Up @@ -376,8 +366,6 @@ function updateTopology(dispatch, getState) {
getResourceViewNodesSnapshot(state, dispatch);
}
updateRoute(getState);
// update all request workers with new options
dispatch(resetNodesDeltaBuffer());
// NOTE: This is currently not needed for our static resource
// view, but we'll need it here later and it's simpler to just
// keep it than to redo the nodes delta updating logic.
Expand Down Expand Up @@ -560,23 +548,11 @@ export function receiveNodesDelta(delta) {
setTimeout(() => dispatch({ type: ActionTypes.SET_RECEIVED_NODES_DELTA }), 0);

const state = getState();
const movingInTime = state.get('timeTravelTransitioning');
const hasChanges = delta.add || delta.update || delta.remove;

// When moving in time, we will consider the transition complete
// only when the first batch of nodes delta has been received. We
// do that because we want to keep the previous state blurred instead
// of transitioning over an empty state like when switching topologies.
if (state.get('timeTravelTransitioning')) {
dispatch({ type: ActionTypes.FINISH_TIME_TRAVEL_TRANSITION });
}

if (hasChanges || movingInTime) {
if (hasChanges) {
if (isPausedSelector(state)) {
if (state.get('nodesDeltaBuffer').size >= NODES_DELTA_BUFFER_SIZE_LIMIT) {
dispatch({ type: ActionTypes.CONSOLIDATE_NODES_DELTA_BUFFER });
}
dispatch({ type: ActionTypes.BUFFER_NODES_DELTA, delta });
// dispatch({ type: ActionTypes.BUFFER_NODES_DELTA, delta });
} else {
dispatch({
type: ActionTypes.RECEIVE_NODES_DELTA,
Expand All @@ -587,35 +563,16 @@ export function receiveNodesDelta(delta) {
};
}

function updateFromNodesDeltaBuffer(dispatch, state) {
const isPaused = isPausedSelector(state);
const isBufferEmpty = state.get('nodesDeltaBuffer').isEmpty();

if (isPaused || isBufferEmpty) {
dispatch(resetNodesDeltaBuffer());
} else {
dispatch(receiveNodesDelta(state.get('nodesDeltaBuffer').first()));
dispatch({ type: ActionTypes.POP_NODES_DELTA_BUFFER });
}
}

export function clickResumeUpdate() {
return (dispatch, getState) => {
return (dispatch) => {
dispatch({
type: ActionTypes.RESUME_TIME_FROM_NOW
});
// Periodically merge buffered nodes deltas until the buffer is emptied.
nodesDeltaBufferUpdateTimer = setInterval(
() => updateFromNodesDeltaBuffer(dispatch, getState()),
NODES_DELTA_BUFFER_FEED_INTERVAL,
);
};
}

export function clickTimeTravel() {
return (dispatch) => {
stopPolling();
teardownWebsockets();
dispatch({
type: ActionTypes.START_TIME_TRAVEL
});
Expand Down
1 change: 0 additions & 1 deletion client/app/scripts/components/time-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class TimeControl extends React.Component {
layout: this.props.topologyViewMode,
topologyId: currentTopology && currentTopology.get('id'),
parentTopologyId: currentTopology && currentTopology.get('parentId'),
nodesDeltaBufferSize: this.props.updateCount,
});
this.props.clickResumeUpdate();
}
Expand Down
4 changes: 0 additions & 4 deletions client/app/scripts/constants/action-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import { zipObject } from 'lodash';
const ACTION_TYPES = [
'ADD_QUERY_FILTER',
'BLUR_SEARCH',
'BUFFER_NODES_DELTA',
'CACHE_ZOOM_STATE',
'CHANGE_INSTANCE',
'CHANGE_TOPOLOGY_OPTION',
'CLEAR_CONTROL_ERROR',
'CLEAR_NODES_DELTA_BUFFER',
'CLICK_BACKGROUND',
'CLICK_CLOSE_DETAILS',
'CLICK_CLOSE_TERMINAL',
Expand All @@ -23,7 +21,6 @@ const ACTION_TYPES = [
'START_TIME_TRAVEL',
'CLICK_TOPOLOGY',
'CLOSE_WEBSOCKET',
'CONSOLIDATE_NODES_DELTA_BUFFER',
'DEBUG_TOOLBAR_INTERFERING',
'DESELECT_NODE',
'DO_CONTROL_ERROR',
Expand All @@ -42,7 +39,6 @@ const ACTION_TYPES = [
'PIN_METRIC',
'PIN_NETWORK',
'PIN_SEARCH',
'POP_NODES_DELTA_BUFFER',
'RECEIVE_API_DETAILS',
'RECEIVE_CONTROL_NODE_REMOVED',
'RECEIVE_CONTROL_PIPE_STATUS',
Expand Down
1 change: 0 additions & 1 deletion client/app/scripts/constants/limits.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@

export const NODE_DETAILS_DATA_ROWS_DEFAULT_LIMIT = 5;
export const NODES_DELTA_BUFFER_SIZE_LIMIT = 100;
1 change: 0 additions & 1 deletion client/app/scripts/constants/timer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* Intervals in ms */
export const API_REFRESH_INTERVAL = 30000;
export const TOPOLOGY_REFRESH_INTERVAL = 5000;
export const NODES_DELTA_BUFFER_FEED_INTERVAL = 1000;

export const TOPOLOGY_LOADER_DELAY = 100;

Expand Down
27 changes: 1 addition & 26 deletions client/app/scripts/reducers/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
isResourceViewModeSelector,
} from '../selectors/topology';
import { activeTopologyZoomCacheKeyPathSelector } from '../selectors/zooming';
import { consolidateNodesDeltas } from '../utils/nodes-delta-utils';
import { applyPinnedSearches } from '../utils/search-utils';
import {
findTopologyById,
Expand Down Expand Up @@ -58,7 +57,6 @@ export const initialState = makeMap({
mouseOverNodeId: null,
nodeDetails: makeOrderedMap(), // nodeId -> details
nodes: makeOrderedMap(), // nodeId -> node
nodesDeltaBuffer: makeList(),
nodesLoaded: false,
// nodes cache, infrequently updated, used for search & resource view
nodesByTopology: makeMap(), // topologyId -> nodes
Expand Down Expand Up @@ -400,29 +398,6 @@ export function rootReducer(state = initialState, action) {
return state.set('websocketClosed', true);
}

//
// nodes delta buffer
//

case ActionTypes.CLEAR_NODES_DELTA_BUFFER: {
return state.update('nodesDeltaBuffer', buffer => buffer.clear());
}

case ActionTypes.CONSOLIDATE_NODES_DELTA_BUFFER: {
const firstDelta = state.getIn(['nodesDeltaBuffer', 0]);
const secondDelta = state.getIn(['nodesDeltaBuffer', 1]);
const deltaUnion = consolidateNodesDeltas(firstDelta, secondDelta);
return state.update('nodesDeltaBuffer', buffer => buffer.shift().set(0, deltaUnion));
}

case ActionTypes.POP_NODES_DELTA_BUFFER: {
return state.update('nodesDeltaBuffer', buffer => buffer.shift());
}

case ActionTypes.BUFFER_NODES_DELTA: {
return state.update('nodesDeltaBuffer', buffer => buffer.push(action.delta));
}

//
// networks
//
Expand Down Expand Up @@ -597,7 +572,7 @@ export function rootReducer(state = initialState, action) {
}

case ActionTypes.RECEIVE_NODES_DELTA: {
// Freeze nodes updates after the first load when paused.
// Ignore periodic nodes updates after the first load when paused.
if (state.get('nodesLoaded') && state.get('pausedAt')) {
return state;
}
Expand Down
60 changes: 0 additions & 60 deletions client/app/scripts/utils/nodes-delta-utils.js

This file was deleted.

6 changes: 3 additions & 3 deletions client/app/scripts/utils/web-api-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function getSerializedTimeTravelTimestamp(state) {
// The timestamp parameter will be used only if it's in the past.
if (!isPausedSelector(state)) return null;

return state.get('pausedAt').toISOString();
return state.get('pausedAt').utc().toISOString();
}

export function buildUrlQuery(params = makeMap(), state) {
Expand Down Expand Up @@ -243,7 +243,7 @@ export function getTopologies(state, dispatch, initialPoll = false) {
doRequest({
url,
success: (res) => {
if (continuePolling && !state.get('pausedAt')) {
if (continuePolling) {
dispatch(receiveTopologies(res));
topologyTimer = setTimeout(() => {
getTopologies(state, dispatch);
Expand All @@ -254,7 +254,7 @@ export function getTopologies(state, dispatch, initialPoll = false) {
log(`Error in topology request: ${req.responseText}`);
dispatch(receiveError(url));
// Only retry in stand-alone mode
if (continuePolling && !state.get('pausedAt')) {
if (continuePolling) {
topologyTimer = setTimeout(() => {
getTopologies(state, dispatch);
}, TOPOLOGY_REFRESH_INTERVAL);
Expand Down

0 comments on commit dc985dc

Please sign in to comment.