Skip to content

Commit

Permalink
fix: throttle the rate AND number of request_state msg'es from the fr…
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenbreddels committed Jan 30, 2020
1 parent 3b06c0b commit 18f0fd3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"css-loader": "^3.0.0",
"file-loader": "^4.0.0",
"npm-run-all": "^4.1.5",
"promise-semaphore": "^0.2.8",
"style-loader": "^0.23.1",
"url-loader": "^1.0.0",
"webpack": "^4.29.3",
Expand Down
12 changes: 10 additions & 2 deletions js/src/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as controls from '@jupyter-widgets/controls';
import * as PhosphorWidget from '@phosphor/widgets';

import { requireLoader } from './loader';
import { batchRateMap } from './utils';

if (typeof window !== "undefined" && typeof window.define !== "undefined") {
window.define("@jupyter-widgets/base", base);
Expand Down Expand Up @@ -117,10 +118,17 @@ export class WidgetManager extends JupyterLabManager {
async _build_models() {
const comm_ids = await this._get_comm_info();
const models = {};
const widgets_info = await Promise.all(Object.keys(comm_ids).map(async (comm_id) => {
/**
* For the classical notebook, iopub_msg_rate_limit=1000 (default)
* And for zmq, we are affected by the default ZMQ_SNDHWM setting of 1000
* See https://github.com/voila-dashboards/voila/issues/534 for a discussion
*/
const maxMessagesInTransit = 100; // really save limit compared to ZMQ_SNDHWM
const maxMessagesPerSecond = 500; // lets be on the save side, in case the kernel sends more msg'es
const widgets_info = await batchRateMap(Object.keys(comm_ids), async (comm_id) => {
const comm = await this._create_comm(this.comm_target_name, comm_id);
return this._update_comm(comm);
}));
}, {room: maxMessagesInTransit, rate: maxMessagesPerSecond});

await Promise.all(widgets_info.map(async (widget_info) => {
const state = widget_info.msg.content.data.state;
Expand Down

0 comments on commit 18f0fd3

Please sign in to comment.