diff --git a/js/package.json b/js/package.json index c3516a19b..c696d4360 100644 --- a/js/package.json +++ b/js/package.json @@ -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", diff --git a/js/src/manager.js b/js/src/manager.js index 40aa79eaf..711fc3e22 100644 --- a/js/src/manager.js +++ b/js/src/manager.js @@ -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); @@ -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;