Skip to content

Commit

Permalink
Fixed message routing with multiple websocket clients
Browse files Browse the repository at this point in the history
  • Loading branch information
texodus committed May 27, 2019
1 parent 0e2bac9 commit a228ca5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions packages/perspective/src/js/perspective.js
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ export default function(Module) {
}
this.callbacks.push({
view: this,
orig_callback: callback,
callback: async () => {
switch (mode) {
case "cell":
Expand Down Expand Up @@ -1104,6 +1105,25 @@ export default function(Module) {
return v;
};

let meter;

function initialize_profile_thread() {
if (meter === undefined) {
let _msgs = 0;
let start = performance.now();
setTimeout(function poll() {
let now = performance.now();
console.log(`${((1000 * _msgs) / (now - start)).toFixed(2)} msgs/sec`);
_msgs = 0;
start = now;
setTimeout(poll, 5000);
}, 5000);
meter = function update(x) {
_msgs += x;
};
}
}

/**
* Updates the rows of a {@link module:perspective~table}. Updated rows are pushed down to any
* derived {@link module:perspective~view} objects.
Expand All @@ -1129,6 +1149,9 @@ export default function(Module) {
throw new Error("Overriding Arrow Schema is not supported.");
}
pdata = load_arrow_buffer(data, cols, types);
if (meter) {
meter(pdata.map(x => x.row_count).reduce((x, y) => x + y));
}
is_arrow = true;
} else if (typeof data === "string") {
if (data[0] === ",") {
Expand All @@ -1137,10 +1160,16 @@ export default function(Module) {
accessor.init(__MODULE__, papaparse.parse(data.trim(), {header: true}).data);
accessor.names = cols;
accessor.types = accessor.extract_typevec(types).slice(0, cols.length);
if (meter) {
meter(accessor.row_count);
}
} else {
accessor.init(__MODULE__, data);
accessor.names = cols;
accessor.types = accessor.extract_typevec(types).slice(0, cols.length);
if (meter) {
meter(accessor.row_count);
}
}

if (accessor.row_count === 0) {
Expand Down
2 changes: 1 addition & 1 deletion packages/perspective/src/js/perspective.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class WebSocketHost extends module.exports.Host {
return;
}
msg = JSON.parse(msg);
const compound_id = msg.id + ws.id;
const compound_id = `${msg.id}/${ws.id}`;
this.REQ_ID_MAP.set(compound_id, msg.id);
msg.id = compound_id;
this.REQS[msg.id] = {ws, msg};
Expand Down

0 comments on commit a228ca5

Please sign in to comment.