@resolveio/server-lib 20.14.14 → 20.14.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/managers/subscription.manager.d.ts +1 -0
- package/managers/subscription.manager.js +41 -5
- package/managers/subscription.manager.js.map +1 -1
- package/managers/worker-dispatcher.manager.d.ts +12 -0
- package/managers/worker-dispatcher.manager.js +15 -0
- package/managers/worker-dispatcher.manager.js.map +1 -1
- package/package.json +1 -1
- package/server-app.d.ts +3 -0
- package/server-app.js +21 -0
- package/server-app.js.map +1 -1
|
@@ -48,6 +48,7 @@ export declare class SubscriptionManager {
|
|
|
48
48
|
private _latencyFlushPending;
|
|
49
49
|
private readonly LATENCY_UPDATE_INTERVAL;
|
|
50
50
|
private readonly LATENCY_UPDATE_THRESHOLD_MS;
|
|
51
|
+
private readonly LATENCY_DEBUG_THRESHOLD_MS;
|
|
51
52
|
private _invalidationDebounceTimers;
|
|
52
53
|
private _invalidationPendingTimestamps;
|
|
53
54
|
private _pendingInvalidations;
|
|
@@ -159,6 +159,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
159
159
|
this.LATENCY_UPDATE_INTERVAL = 60000;
|
|
160
160
|
// Minimum time difference between two latency updates for the same user
|
|
161
161
|
this.LATENCY_UPDATE_THRESHOLD_MS = 30000;
|
|
162
|
+
this.LATENCY_DEBUG_THRESHOLD_MS = 1000;
|
|
162
163
|
// private currentPerfomanceMonitor: CurrentPerformanceMonitor[] = [];
|
|
163
164
|
// private idPerformance: number = 0;
|
|
164
165
|
// private performanceThread;
|
|
@@ -667,20 +668,55 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
667
668
|
};
|
|
668
669
|
// Throttled `loggedInLatency` method
|
|
669
670
|
SubscriptionManager.prototype.loggedInLatency = function (ws) {
|
|
670
|
-
var
|
|
671
|
-
if (!loggedInUser)
|
|
672
|
-
return;
|
|
671
|
+
var _a, _b, _c, _d;
|
|
673
672
|
var now = new Date();
|
|
674
|
-
var existingEntry = this.latencyBuffer.get(ws['id_socket']);
|
|
675
673
|
var newLatency = ws['latency'];
|
|
674
|
+
var socketId = ws['id_socket'];
|
|
675
|
+
var loggedInUser = this._loggedInUsers.find(function (a) { return a.id_ws === socketId; });
|
|
676
|
+
if (!loggedInUser) {
|
|
677
|
+
if (typeof newLatency === 'number' && newLatency >= this.LATENCY_DEBUG_THRESHOLD_MS) {
|
|
678
|
+
var lastRoute = this._lastRouteBySocket.get(socketId);
|
|
679
|
+
var workerDispatcher = (_b = (_a = resolveio_server_app_1.ResolveIOServer.getMainServer()) === null || _a === void 0 ? void 0 : _a.getWorkerDispatcherManager) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
680
|
+
var workerSnapshot = workerDispatcher && typeof workerDispatcher.getQueueSnapshot === 'function'
|
|
681
|
+
? workerDispatcher.getQueueSnapshot()
|
|
682
|
+
: null;
|
|
683
|
+
console.log(new Date(), '[Latency Spike]', {
|
|
684
|
+
latencyMs: (0, common_1.round)(newLatency),
|
|
685
|
+
id_user: ws['id_user'] || null,
|
|
686
|
+
user: ws['user'] || null,
|
|
687
|
+
id_ws: socketId,
|
|
688
|
+
lastRoute: (lastRoute === null || lastRoute === void 0 ? void 0 : lastRoute.route) || null,
|
|
689
|
+
lastRouteAgeMs: lastRoute ? (Date.now() - lastRoute.dateMs) : null,
|
|
690
|
+
worker: workerSnapshot
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
var existingEntry = this.latencyBuffer.get(socketId);
|
|
676
696
|
// Throttle updates: only update if time threshold has passed or latency has significantly changed
|
|
677
697
|
if (!existingEntry ||
|
|
678
698
|
(now.getTime() - existingEntry.lastUpdate.getTime() >= this.LATENCY_UPDATE_THRESHOLD_MS) ||
|
|
679
699
|
(Math.abs(newLatency - existingEntry.latency) > 100) // Optional: log only significant changes
|
|
680
700
|
) {
|
|
701
|
+
if (typeof newLatency === 'number' && newLatency >= this.LATENCY_DEBUG_THRESHOLD_MS) {
|
|
702
|
+
var lastRoute = this._lastRouteBySocket.get(socketId);
|
|
703
|
+
var workerDispatcher = (_d = (_c = resolveio_server_app_1.ResolveIOServer.getMainServer()) === null || _c === void 0 ? void 0 : _c.getWorkerDispatcherManager) === null || _d === void 0 ? void 0 : _d.call(_c);
|
|
704
|
+
var workerSnapshot = workerDispatcher && typeof workerDispatcher.getQueueSnapshot === 'function'
|
|
705
|
+
? workerDispatcher.getQueueSnapshot()
|
|
706
|
+
: null;
|
|
707
|
+
console.log(new Date(), '[Latency Spike]', {
|
|
708
|
+
latencyMs: (0, common_1.round)(newLatency),
|
|
709
|
+
id_user: loggedInUser.id_user,
|
|
710
|
+
user: loggedInUser.user,
|
|
711
|
+
id_ws: socketId,
|
|
712
|
+
lastRoute: (lastRoute === null || lastRoute === void 0 ? void 0 : lastRoute.route) || null,
|
|
713
|
+
lastRouteAgeMs: lastRoute ? (Date.now() - lastRoute.dateMs) : null,
|
|
714
|
+
worker: workerSnapshot
|
|
715
|
+
});
|
|
716
|
+
}
|
|
681
717
|
// Update in-memory and buffer
|
|
682
718
|
loggedInUser.date = now;
|
|
683
|
-
this.latencyBuffer.set(
|
|
719
|
+
this.latencyBuffer.set(socketId, { latency: newLatency, lastUpdate: now });
|
|
684
720
|
}
|
|
685
721
|
};
|
|
686
722
|
// Method to flush buffered latency updates in bulk
|