@glimt/record 0.0.65 → 0.0.66
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/dist/record.cjs +50 -21
- package/dist/record.cjs.map +1 -1
- package/dist/record.js +50 -21
- package/dist/record.js.map +1 -1
- package/dist/record.umd.cjs +50 -21
- package/dist/record.umd.cjs.map +2 -2
- package/dist/record.umd.min.cjs +23 -23
- package/dist/record.umd.min.cjs.map +3 -3
- package/package.json +1 -1
package/dist/record.js
CHANGED
|
@@ -10325,6 +10325,49 @@ const _StormSnapshotManager = class _StormSnapshotManager2 {
|
|
|
10325
10325
|
__publicField(_StormSnapshotManager, "instance");
|
|
10326
10326
|
let StormSnapshotManager = _StormSnapshotManager;
|
|
10327
10327
|
const stormSnapshotManager = new StormSnapshotManager();
|
|
10328
|
+
class MutationRateLimiter {
|
|
10329
|
+
constructor() {
|
|
10330
|
+
__publicField(this, "mutTracker");
|
|
10331
|
+
__publicField(this, "interval", 50);
|
|
10332
|
+
__publicField(this, "limit", 150);
|
|
10333
|
+
__publicField(this, "inGlobalStorm", false);
|
|
10334
|
+
debugLog(`MutationRateLimiter, init`);
|
|
10335
|
+
this.reset();
|
|
10336
|
+
}
|
|
10337
|
+
reset() {
|
|
10338
|
+
this.mutTracker = {
|
|
10339
|
+
muts: 0,
|
|
10340
|
+
ts: -1
|
|
10341
|
+
};
|
|
10342
|
+
}
|
|
10343
|
+
isStorming(muts) {
|
|
10344
|
+
const now = Date.now();
|
|
10345
|
+
if (this.inGlobalStorm) {
|
|
10346
|
+
if (now - this.mutTracker.ts > this.interval) {
|
|
10347
|
+
this.inGlobalStorm = false;
|
|
10348
|
+
debugLog(`MutationRateLimiter, detected global storm over`);
|
|
10349
|
+
return false;
|
|
10350
|
+
}
|
|
10351
|
+
return true;
|
|
10352
|
+
}
|
|
10353
|
+
if (this.mutTracker.ts === -1) {
|
|
10354
|
+
this.mutTracker.muts = muts;
|
|
10355
|
+
} else {
|
|
10356
|
+
if (now - this.mutTracker.ts <= this.interval) {
|
|
10357
|
+
this.mutTracker.muts += muts;
|
|
10358
|
+
if (this.mutTracker.muts >= this.limit) {
|
|
10359
|
+
this.inGlobalStorm = true;
|
|
10360
|
+
this.reset();
|
|
10361
|
+
debugLog(`MutationRateLimiter, detected global rolling storm`);
|
|
10362
|
+
return true;
|
|
10363
|
+
}
|
|
10364
|
+
}
|
|
10365
|
+
}
|
|
10366
|
+
this.mutTracker.ts = now;
|
|
10367
|
+
return false;
|
|
10368
|
+
}
|
|
10369
|
+
}
|
|
10370
|
+
const mutationRateLimiter = new MutationRateLimiter();
|
|
10328
10371
|
function isNodeInLinkedList(n2) {
|
|
10329
10372
|
return "__ln" in n2;
|
|
10330
10373
|
}
|
|
@@ -10466,7 +10509,7 @@ class MutationBuffer {
|
|
|
10466
10509
|
ts: -1,
|
|
10467
10510
|
interval: 50
|
|
10468
10511
|
});
|
|
10469
|
-
__publicField(this, "handleStormMutations", (muts) => {
|
|
10512
|
+
__publicField(this, "handleStormMutations", (muts, canFinishStorm = true) => {
|
|
10470
10513
|
const time = Date.now();
|
|
10471
10514
|
if (this.stormInfo == null) {
|
|
10472
10515
|
debugLog(
|
|
@@ -10492,7 +10535,7 @@ class MutationBuffer {
|
|
|
10492
10535
|
});
|
|
10493
10536
|
}
|
|
10494
10537
|
clearTimeout(this.stormInfo.timeout);
|
|
10495
|
-
if (muts.length < this.stormSettings.batchSize) {
|
|
10538
|
+
if (canFinishStorm && muts.length < this.stormSettings.batchSize) {
|
|
10496
10539
|
this.handleStormFinish();
|
|
10497
10540
|
} else {
|
|
10498
10541
|
this.stormInfo.timeout = setTimeout(
|
|
@@ -10537,28 +10580,14 @@ class MutationBuffer {
|
|
|
10537
10580
|
JSON.parse(JSON.stringify(this.rollingMutTracker))
|
|
10538
10581
|
);
|
|
10539
10582
|
if (!overrideStorm) {
|
|
10583
|
+
const isStorming = mutationRateLimiter.isStorming(muts.length);
|
|
10584
|
+
if (isStorming) {
|
|
10585
|
+
this.handleStormMutations(muts, false);
|
|
10586
|
+
return;
|
|
10587
|
+
}
|
|
10540
10588
|
if (this.stormInfo != null || muts.length >= this.stormSettings.batchSize) {
|
|
10541
10589
|
this.handleStormMutations(muts);
|
|
10542
10590
|
}
|
|
10543
|
-
if (this.stormInfo == null) {
|
|
10544
|
-
const now = Date.now();
|
|
10545
|
-
if (this.rollingMutTracker.ts === -1) {
|
|
10546
|
-
this.rollingMutTracker.accumlativeMuts = muts.length;
|
|
10547
|
-
} else {
|
|
10548
|
-
if (now - this.rollingMutTracker.ts <= this.rollingMutTracker.interval) {
|
|
10549
|
-
this.rollingMutTracker.accumlativeMuts += muts.length;
|
|
10550
|
-
if (this.rollingMutTracker.accumlativeMuts >= this.stormSettings.batchSize) {
|
|
10551
|
-
debugLog(`Mutation storm through rolling detected.`);
|
|
10552
|
-
this.handleStormMutations(muts);
|
|
10553
|
-
this.rollingMutTracker.accumlativeMuts = 0;
|
|
10554
|
-
this.rollingMutTracker.ts = -1;
|
|
10555
|
-
}
|
|
10556
|
-
} else {
|
|
10557
|
-
this.rollingMutTracker.accumlativeMuts = 0;
|
|
10558
|
-
}
|
|
10559
|
-
}
|
|
10560
|
-
this.rollingMutTracker.ts = now;
|
|
10561
|
-
}
|
|
10562
10591
|
return;
|
|
10563
10592
|
}
|
|
10564
10593
|
for (const mut of muts) {
|