@tramvai/module-request-limiter 7.26.9 → 7.27.3
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/lib/requestLimiter.d.ts +2 -0
- package/lib/requestLimiter.es.js +6 -2
- package/lib/requestLimiter.js +6 -2
- package/lib/server.es.js +8 -1
- package/lib/server.js +7 -0
- package/package.json +5 -5
package/lib/requestLimiter.d.ts
CHANGED
|
@@ -42,6 +42,7 @@ export declare class RequestLimiter {
|
|
|
42
42
|
private maxEventLoopDelay;
|
|
43
43
|
private eventLoopHistogram;
|
|
44
44
|
private metrics;
|
|
45
|
+
private timer;
|
|
45
46
|
constructor(options: RequestLimiterOptions, metrics: RequestsLimiterMetrics);
|
|
46
47
|
onResponse(): void;
|
|
47
48
|
private updateCurrentActiveRequests;
|
|
@@ -50,6 +51,7 @@ export declare class RequestLimiter {
|
|
|
50
51
|
add(request: RequestLimiterRequest): void;
|
|
51
52
|
private loop;
|
|
52
53
|
private run;
|
|
54
|
+
stop(): void;
|
|
53
55
|
}
|
|
54
56
|
declare module 'fastify' {
|
|
55
57
|
interface FastifyPluginOptions {
|
package/lib/requestLimiter.es.js
CHANGED
|
@@ -22,6 +22,7 @@ class RequestLimiter {
|
|
|
22
22
|
maxEventLoopDelay;
|
|
23
23
|
eventLoopHistogram;
|
|
24
24
|
metrics;
|
|
25
|
+
timer;
|
|
25
26
|
constructor(options, metrics) {
|
|
26
27
|
const { limit, queue, maxEventLoopDelay, error } = options;
|
|
27
28
|
this.activeRequestLimit = limit;
|
|
@@ -33,8 +34,8 @@ class RequestLimiter {
|
|
|
33
34
|
this.metrics.collectQueueLimit(this.queueLimit);
|
|
34
35
|
this.eventLoopHistogram = monitorEventLoopDelay({ resolution });
|
|
35
36
|
this.eventLoopHistogram.enable();
|
|
36
|
-
|
|
37
|
-
timer.unref();
|
|
37
|
+
this.timer = setInterval(() => this.nextTick(), 1000);
|
|
38
|
+
this.timer.unref();
|
|
38
39
|
}
|
|
39
40
|
onResponse() {
|
|
40
41
|
this.updateCurrentActiveRequests(this.currentActive - 1);
|
|
@@ -97,6 +98,9 @@ class RequestLimiter {
|
|
|
97
98
|
});
|
|
98
99
|
next();
|
|
99
100
|
}
|
|
101
|
+
stop() {
|
|
102
|
+
clearInterval(this.timer);
|
|
103
|
+
}
|
|
100
104
|
}
|
|
101
105
|
const fastifyRequestsLimiter = fp(async (fastify, { requestsLimiter }) => {
|
|
102
106
|
fastify.addHook('onRequest', (req, res, next) => {
|
package/lib/requestLimiter.js
CHANGED
|
@@ -31,6 +31,7 @@ class RequestLimiter {
|
|
|
31
31
|
maxEventLoopDelay;
|
|
32
32
|
eventLoopHistogram;
|
|
33
33
|
metrics;
|
|
34
|
+
timer;
|
|
34
35
|
constructor(options, metrics) {
|
|
35
36
|
const { limit, queue, maxEventLoopDelay, error } = options;
|
|
36
37
|
this.activeRequestLimit = limit;
|
|
@@ -42,8 +43,8 @@ class RequestLimiter {
|
|
|
42
43
|
this.metrics.collectQueueLimit(this.queueLimit);
|
|
43
44
|
this.eventLoopHistogram = perf_hooks.monitorEventLoopDelay({ resolution });
|
|
44
45
|
this.eventLoopHistogram.enable();
|
|
45
|
-
|
|
46
|
-
timer.unref();
|
|
46
|
+
this.timer = setInterval(() => this.nextTick(), 1000);
|
|
47
|
+
this.timer.unref();
|
|
47
48
|
}
|
|
48
49
|
onResponse() {
|
|
49
50
|
this.updateCurrentActiveRequests(this.currentActive - 1);
|
|
@@ -106,6 +107,9 @@ class RequestLimiter {
|
|
|
106
107
|
});
|
|
107
108
|
next();
|
|
108
109
|
}
|
|
110
|
+
stop() {
|
|
111
|
+
clearInterval(this.timer);
|
|
112
|
+
}
|
|
109
113
|
}
|
|
110
114
|
const fastifyRequestsLimiter = fp__default["default"](async (fastify, { requestsLimiter }) => {
|
|
111
115
|
fastify.addHook('onRequest', (req, res, next) => {
|
package/lib/server.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __decorate } from 'tslib';
|
|
2
|
-
import { Module, provide, Scope } from '@tramvai/core';
|
|
2
|
+
import { Module, provide, Scope, commandLineListTokens } from '@tramvai/core';
|
|
3
3
|
import { METRICS_MODULE_TOKEN } from '@tramvai/tokens-metrics';
|
|
4
4
|
import { ENV_USED_TOKEN, ENV_MANAGER_TOKEN } from '@tramvai/tokens-common';
|
|
5
5
|
import { WEB_FASTIFY_APP_LIMITER_TOKEN } from '@tramvai/tokens-server-private';
|
|
@@ -74,6 +74,13 @@ RequestLimiterModule = __decorate([
|
|
|
74
74
|
featureEnable: { token: REQUESTS_LIMITER_ACTIVATE_TOKEN, optional: true },
|
|
75
75
|
},
|
|
76
76
|
}),
|
|
77
|
+
provide({
|
|
78
|
+
provide: commandLineListTokens.close,
|
|
79
|
+
useFactory: ({ requestsLimiter }) => () => requestsLimiter.stop(),
|
|
80
|
+
deps: {
|
|
81
|
+
requestsLimiter: REQUESTS_LIMITER_TOKEN,
|
|
82
|
+
},
|
|
83
|
+
}),
|
|
77
84
|
provide({
|
|
78
85
|
provide: REQUESTS_LIMITER_METRICS_TOKEN,
|
|
79
86
|
scope: Scope.SINGLETON,
|
package/lib/server.js
CHANGED
|
@@ -76,6 +76,13 @@ exports.RequestLimiterModule = tslib.__decorate([
|
|
|
76
76
|
featureEnable: { token: tokens.REQUESTS_LIMITER_ACTIVATE_TOKEN, optional: true },
|
|
77
77
|
},
|
|
78
78
|
}),
|
|
79
|
+
core.provide({
|
|
80
|
+
provide: core.commandLineListTokens.close,
|
|
81
|
+
useFactory: ({ requestsLimiter }) => () => requestsLimiter.stop(),
|
|
82
|
+
deps: {
|
|
83
|
+
requestsLimiter: tokens.REQUESTS_LIMITER_TOKEN,
|
|
84
|
+
},
|
|
85
|
+
}),
|
|
79
86
|
core.provide({
|
|
80
87
|
provide: tokens.REQUESTS_LIMITER_METRICS_TOKEN,
|
|
81
88
|
scope: core.Scope.SINGLETON,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/module-request-limiter",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.27.3",
|
|
4
4
|
"description": "Enable different rendering modes for pages",
|
|
5
5
|
"main": "lib/server.js",
|
|
6
6
|
"module": "lib/server.es.js",
|
|
@@ -24,15 +24,15 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@tinkoff/errors": "0.8.1",
|
|
27
|
-
"@tramvai/tokens-metrics": "7.
|
|
27
|
+
"@tramvai/tokens-metrics": "7.27.3",
|
|
28
28
|
"fastify-plugin": "^5.1.0",
|
|
29
29
|
"on-finished": "^2.3.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"@tinkoff/dippy": "^1.0.0",
|
|
33
|
-
"@tramvai/core": "7.
|
|
34
|
-
"@tramvai/tokens-common": "7.
|
|
35
|
-
"@tramvai/tokens-server-private": "7.
|
|
33
|
+
"@tramvai/core": "7.27.3",
|
|
34
|
+
"@tramvai/tokens-common": "7.27.3",
|
|
35
|
+
"@tramvai/tokens-server-private": "7.27.3",
|
|
36
36
|
"fastify": "^5.6.2",
|
|
37
37
|
"tslib": "^2.4.0"
|
|
38
38
|
}
|