Before this PR, server.js created a new peer connection for every new registered publisher/subscriber. This was intentional, to allow multiple devices to simultaneously register to the robot's video stream (e.g., to test latency). However, this also means that throughout the course of the meal, more and more peer connections are created, which hugely increases the CPU utilization of server.js (we saw it go up to 500%).
This PR addresses that by only allowing one publisher and subscriber per topic at a time. (Note: in theory this should allow for a different subscriber per IP, but in practice all the IPs end up being the same -- unclear why -- resulting in this only allowing one publisher/subscriber per topic at once.)
Testing: On lovelace:
[x] Start server.js
[x] Start/restart start_robot_browser.js several times. Verify that CPU utilization for server.js stays roughly the same.
[x] Load the web app on another device. Load and reload a video stream (e.g., refreshing the bite selection page). Verify that CPU utilization for server.js stays roughly the same.
[x] Open a new tab on that device. Verify that the old tab stops updating but the new tab keeps updating.
[FAIL] Load the web app on a different device. Verify that both media streams are updating.
Before this PR,
server.js
created a new peer connection for every new registered publisher/subscriber. This was intentional, to allow multiple devices to simultaneously register to the robot's video stream (e.g., to test latency). However, this also means that throughout the course of the meal, more and more peer connections are created, which hugely increases the CPU utilization ofserver.js
(we saw it go up to 500%).This PR addresses that by only allowing one publisher and subscriber per topic at a time. (Note: in theory this should allow for a different subscriber per IP, but in practice all the IPs end up being the same -- unclear why -- resulting in this only allowing one publisher/subscriber per topic at once.)
Testing: On lovelace:
server.js
start_robot_browser.js
several times. Verify that CPU utilization forserver.js
stays roughly the same.server.js
stays roughly the same.