@tramvai/module-request-limiter 1.84.0 → 1.89.1

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/README.md CHANGED
@@ -57,6 +57,9 @@ const provider = {
57
57
  };
58
58
  ```
59
59
 
60
+ The basic settings should work well for most applications, as there is a system built in to adapt and automatically change the parameters relative to the loads. As a result, change the settings after you have done a load test and know that the changes will definitely improve the situation
61
+
62
+
60
63
  ## Explanation
61
64
 
62
65
  After the server starts, request limiter can handle `options.limit` parallel connections.
package/lib/browser.d.ts CHANGED
@@ -1,2 +1,3 @@
1
+ export * from './tokens';
1
2
  export declare class RequestLimiterModule {
2
3
  }
package/lib/browser.js CHANGED
@@ -1,5 +1,10 @@
1
1
  import { __decorate } from 'tslib';
2
2
  import { Module } from '@tramvai/core';
3
+ import { createToken } from '@tinkoff/dippy';
4
+
5
+ const REQUESTS_LIMITER_TOKEN = createToken('requestsLimiterToken');
6
+ const REQUESTS_LIMITER_ACTIVATE_TOKEN = createToken('requestsLimiterActivateToken');
7
+ const REQUESTS_LIMITER_OPTIONS_TOKEN = createToken('requestsLimiterOptionsToken');
3
8
 
4
9
  let RequestLimiterModule = class RequestLimiterModule {
5
10
  };
@@ -9,4 +14,4 @@ RequestLimiterModule = __decorate([
9
14
  })
10
15
  ], RequestLimiterModule);
11
16
 
12
- export { RequestLimiterModule };
17
+ export { REQUESTS_LIMITER_ACTIVATE_TOKEN, REQUESTS_LIMITER_OPTIONS_TOKEN, REQUESTS_LIMITER_TOKEN, RequestLimiterModule };
package/lib/server.es.js CHANGED
@@ -80,7 +80,7 @@ class RequestLimiter {
80
80
  this.queue = new DoubleLinkedList();
81
81
  const { limit = DEFAULT_OPTIONS.limit, queue = DEFAULT_OPTIONS.queue, maxEventLoopDelay = DEFAULT_OPTIONS.maxEventLoopDelay, error = DEFAULT_OPTIONS.error, } = options;
82
82
  this.activeRequestLimit = limit;
83
- this.minimalActiveRequestLimit = Math.floor(limit / 2);
83
+ this.minimalActiveRequestLimit = Math.round(limit / 3);
84
84
  this.queueLimit = queue;
85
85
  this.error = error;
86
86
  this.maxEventLoopDelay = maxEventLoopDelay;
@@ -95,12 +95,12 @@ class RequestLimiter {
95
95
  if (Number.isNaN(this.eventLoopDelay))
96
96
  this.eventLoopDelay = Infinity;
97
97
  this.eventLoopHistogram.reset();
98
- if (this.currentActive >= this.activeRequestLimit &&
99
- this.activeRequestLimit > this.minimalActiveRequestLimit) {
98
+ if (this.currentActive >= this.activeRequestLimit) {
100
99
  if (this.eventLoopDelay <= this.maxEventLoopDelay) {
101
100
  this.activeRequestLimit++;
101
+ // We need to have minimalActiveRequestLimit
102
102
  }
103
- else {
103
+ else if (this.activeRequestLimit > this.minimalActiveRequestLimit) {
104
104
  this.activeRequestLimit--;
105
105
  }
106
106
  }
@@ -149,7 +149,7 @@ RequestLimiterModule = __decorate([
149
149
  if (featureEnable !== true) {
150
150
  return;
151
151
  }
152
- return new RequestLimiter(options);
152
+ return new RequestLimiter(options !== null && options !== void 0 ? options : {});
153
153
  },
154
154
  deps: {
155
155
  options: { token: REQUESTS_LIMITER_OPTIONS_TOKEN, optional: true },
package/lib/server.js CHANGED
@@ -88,7 +88,7 @@ class RequestLimiter {
88
88
  this.queue = new DoubleLinkedList();
89
89
  const { limit = DEFAULT_OPTIONS.limit, queue = DEFAULT_OPTIONS.queue, maxEventLoopDelay = DEFAULT_OPTIONS.maxEventLoopDelay, error = DEFAULT_OPTIONS.error, } = options;
90
90
  this.activeRequestLimit = limit;
91
- this.minimalActiveRequestLimit = Math.floor(limit / 2);
91
+ this.minimalActiveRequestLimit = Math.round(limit / 3);
92
92
  this.queueLimit = queue;
93
93
  this.error = error;
94
94
  this.maxEventLoopDelay = maxEventLoopDelay;
@@ -103,12 +103,12 @@ class RequestLimiter {
103
103
  if (Number.isNaN(this.eventLoopDelay))
104
104
  this.eventLoopDelay = Infinity;
105
105
  this.eventLoopHistogram.reset();
106
- if (this.currentActive >= this.activeRequestLimit &&
107
- this.activeRequestLimit > this.minimalActiveRequestLimit) {
106
+ if (this.currentActive >= this.activeRequestLimit) {
108
107
  if (this.eventLoopDelay <= this.maxEventLoopDelay) {
109
108
  this.activeRequestLimit++;
109
+ // We need to have minimalActiveRequestLimit
110
110
  }
111
- else {
111
+ else if (this.activeRequestLimit > this.minimalActiveRequestLimit) {
112
112
  this.activeRequestLimit--;
113
113
  }
114
114
  }
@@ -157,7 +157,7 @@ exports.RequestLimiterModule = tslib.__decorate([
157
157
  if (featureEnable !== true) {
158
158
  return;
159
159
  }
160
- return new RequestLimiter(options);
160
+ return new RequestLimiter(options !== null && options !== void 0 ? options : {});
161
161
  },
162
162
  deps: {
163
163
  options: { token: REQUESTS_LIMITER_OPTIONS_TOKEN, optional: true },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-request-limiter",
3
- "version": "1.84.0",
3
+ "version": "1.89.1",
4
4
  "description": "Enable different rendering modes for pages",
5
5
  "main": "lib/server.js",
6
6
  "module": "lib/server.es.js",
@@ -32,8 +32,8 @@
32
32
  },
33
33
  "peerDependencies": {
34
34
  "@tinkoff/dippy": "0.7.39",
35
- "@tramvai/core": "1.84.0",
36
- "@tramvai/tokens-server": "1.84.0",
35
+ "@tramvai/core": "1.89.1",
36
+ "@tramvai/tokens-server": "1.89.1",
37
37
  "express": "^4.17.1",
38
38
  "tslib": "^2.0.3"
39
39
  }