Skip to content
Snippets Groups Projects

Implement new SkRateLimiterServer with Leaky Bucket rate limits (resolves #592)

Merged Hazelnoot requested to merge fEmber/Sharkey:lab/new-rate-limits into develop
2 files
+ 7
7
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -95,7 +95,7 @@ export class SkRateLimiterService {
if (limit.minInterval < 0) throw new Error(`Invalid rate limit ${limit.key}: minInterval is negative (${limit.minInterval})`);
const counter = await this.getLimitCounter(limit, actor, 'min');
const minInterval = Math.max(Math.ceil(limit.minInterval / factor), 0);
const minInterval = Math.max(Math.ceil(limit.minInterval * factor), 0);
// Update expiration
if (counter.c > 0) {
@@ -132,7 +132,7 @@ export class SkRateLimiterService {
if (limit.dripSize != null && limit.dripSize < 1) throw new Error(`Invalid rate limit ${limit.key}: dripSize is less than 1 (${limit.dripSize})`);
const counter = await this.getLimitCounter(limit, actor, 'bucket');
const bucketSize = Math.max(Math.ceil(limit.size * factor), 1);
const bucketSize = Math.max(Math.ceil(limit.size / factor), 1);
const dripRate = Math.ceil(limit.dripRate ?? 1000);
const dripSize = Math.ceil(limit.dripSize ?? 1);
Loading