Skip to content

Commit

Permalink
Track delta of msg processed by worker vs main
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-liang committed Jul 11, 2024
1 parent f28fde6 commit 574e720
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/systems/core/mqtt.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { ARENA_EVENTS, ACTIONS } from '../../constants';
const warn = AFRAME.utils.debug('ARENA:MQTT:warn');
// const error = AFRAME.utils.debug('ARENA:MQTT:error');

let lastMetricTick = new Date().getTime();

AFRAME.registerSystem('arena-mqtt', {
schema: {
mqttHost: { type: 'string', default: ARENA.defaults.mqttHost },
Expand Down Expand Up @@ -139,6 +141,12 @@ AFRAME.registerSystem('arena-mqtt', {
* @param {object} message
*/
onSceneMessageArrived(message) {
const now = new Date().getTime();
if (now - lastMetricTick > 1000) {
console.log(`Worker message delay: ${now - message.workerTimestamp}ms`);
lastMetricTick = now;
}
delete message.workerTimestamp;
const theMessage = message.payloadObj; // This will be given as json

if (!theMessage) {
Expand Down
1 change: 1 addition & 0 deletions src/systems/core/workers/mqtt-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class MQTTWorker {
const topicCategory = topic.split('/')[1];
const handler = this.messageHandlers[topicCategory];
if (handler) {
message.workerTimestamp = new Date().getTime();
handler(message);
}
}
Expand Down

0 comments on commit 574e720

Please sign in to comment.