@rsdk/gc 5.12.0-next.2
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/config/gc.config.d.ts +7 -0
- package/dist/config/gc.config.js +44 -0
- package/dist/config/gc.config.js.map +1 -0
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.js +6 -0
- package/dist/config/index.js.map +1 -0
- package/dist/gc.module.d.ts +2 -0
- package/dist/gc.module.js +22 -0
- package/dist/gc.module.js.map +1 -0
- package/dist/gc.service.d.ts +8 -0
- package/dist/gc.service.js +50 -0
- package/dist/gc.service.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/package.json +34 -0
- package/src/config/gc.config.ts +30 -0
- package/src/config/index.ts +1 -0
- package/src/gc.module.ts +10 -0
- package/src/gc.service.ts +38 -0
- package/src/index.ts +2 -0
- package/tsconfig.build.json +13 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.UtilsGCConfig = void 0;
|
|
13
|
+
const common_1 = require("@rsdk/common");
|
|
14
|
+
const core_1 = require("@rsdk/core");
|
|
15
|
+
let UtilsGCConfig = class UtilsGCConfig extends core_1.Config {
|
|
16
|
+
rssIncreasePercent;
|
|
17
|
+
checkIntervalSec;
|
|
18
|
+
forceCleanEnabled;
|
|
19
|
+
};
|
|
20
|
+
exports.UtilsGCConfig = UtilsGCConfig;
|
|
21
|
+
__decorate([
|
|
22
|
+
(0, core_1.Property)('RSS_INCREASE_PERCENT', new core_1.IntParser(), {
|
|
23
|
+
defaultValue: 10,
|
|
24
|
+
description: 'The maximum percentage of rss increase allowed before forced garbage collection occurs',
|
|
25
|
+
}),
|
|
26
|
+
__metadata("design:type", Number)
|
|
27
|
+
], UtilsGCConfig.prototype, "rssIncreasePercent", void 0);
|
|
28
|
+
__decorate([
|
|
29
|
+
(0, core_1.Property)('CHECK_INTERVAL', new core_1.TimespanParser(), {
|
|
30
|
+
defaultValue: new common_1.Timespan(1, 'minutes'),
|
|
31
|
+
description: 'Memory usage check interval',
|
|
32
|
+
}),
|
|
33
|
+
__metadata("design:type", common_1.Timespan)
|
|
34
|
+
], UtilsGCConfig.prototype, "checkIntervalSec", void 0);
|
|
35
|
+
__decorate([
|
|
36
|
+
(0, core_1.Property)('FORCE_CLEAN_ENABLED', new core_1.BoolParser(), {
|
|
37
|
+
description: 'If true, then forced memory clearing is used',
|
|
38
|
+
}),
|
|
39
|
+
__metadata("design:type", Boolean)
|
|
40
|
+
], UtilsGCConfig.prototype, "forceCleanEnabled", void 0);
|
|
41
|
+
exports.UtilsGCConfig = UtilsGCConfig = __decorate([
|
|
42
|
+
(0, core_1.ConfigSection)({ prefix: 'GC' })
|
|
43
|
+
], UtilsGCConfig);
|
|
44
|
+
//# sourceMappingURL=gc.config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gc.config.js","sourceRoot":"","sources":["../../src/config/gc.config.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAwC;AACxC,qCAOoB;AAGb,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,aAAM;IAM9B,kBAAkB,CAAU;IAM5B,gBAAgB,CAAY;IAK5B,iBAAiB,CAAW;CACtC,CAAA;AAlBY,sCAAa;AAMf;IALR,IAAA,eAAQ,EAAC,sBAAsB,EAAE,IAAI,gBAAS,EAAE,EAAE;QACjD,YAAY,EAAE,EAAE;QAChB,WAAW,EACT,wFAAwF;KAC3F,CAAC;;yDACmC;AAM5B;IAJR,IAAA,eAAQ,EAAC,gBAAgB,EAAE,IAAI,qBAAc,EAAE,EAAE;QAChD,YAAY,EAAE,IAAI,iBAAQ,CAAC,CAAC,EAAE,SAAS,CAAC;QACxC,WAAW,EAAE,6BAA6B;KAC3C,CAAC;8BAC0B,iBAAQ;uDAAC;AAK5B;IAHR,IAAA,eAAQ,EAAC,qBAAqB,EAAE,IAAI,iBAAU,EAAE,EAAE;QACjD,WAAW,EAAE,8CAA8C;KAC5D,CAAC;;wDACmC;wBAjB1B,aAAa;IADzB,IAAA,oBAAa,EAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;GACnB,aAAa,CAkBzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { UtilsGCConfig } from './gc.config';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UtilsGCConfig = void 0;
|
|
4
|
+
var gc_config_1 = require("./gc.config");
|
|
5
|
+
Object.defineProperty(exports, "UtilsGCConfig", { enumerable: true, get: function () { return gc_config_1.UtilsGCConfig; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAAnC,0GAAA,aAAa,OAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.UtilsGCModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const gc_service_1 = require("./gc.service");
|
|
12
|
+
let UtilsGCModule = class UtilsGCModule {
|
|
13
|
+
};
|
|
14
|
+
exports.UtilsGCModule = UtilsGCModule;
|
|
15
|
+
exports.UtilsGCModule = UtilsGCModule = __decorate([
|
|
16
|
+
(0, common_1.Global)(),
|
|
17
|
+
(0, common_1.Module)({
|
|
18
|
+
exports: [gc_service_1.UtilsGCService],
|
|
19
|
+
providers: [gc_service_1.UtilsGCService],
|
|
20
|
+
})
|
|
21
|
+
], UtilsGCModule);
|
|
22
|
+
//# sourceMappingURL=gc.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gc.module.js","sourceRoot":"","sources":["../src/gc.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAgD;AAEhD,6CAA8C;AAOvC,IAAM,aAAa,GAAnB,MAAM,aAAa;CAAG,CAAA;AAAhB,sCAAa;wBAAb,aAAa;IALzB,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,2BAAc,CAAC;QACzB,SAAS,EAAE,CAAC,2BAAc,CAAC;KAC5B,CAAC;GACW,aAAa,CAAG"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.UtilsGCService = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const node_v8_1 = require("node:v8");
|
|
15
|
+
const node_vm_1 = require("node:vm");
|
|
16
|
+
const config_1 = require("./config");
|
|
17
|
+
let UtilsGCService = class UtilsGCService {
|
|
18
|
+
gcConfig;
|
|
19
|
+
rss;
|
|
20
|
+
constructor(gcConfig) {
|
|
21
|
+
this.gcConfig = gcConfig;
|
|
22
|
+
this.rss = process.memoryUsage().rss;
|
|
23
|
+
}
|
|
24
|
+
onApplicationBootstrap() {
|
|
25
|
+
if (this.gcConfig.forceCleanEnabled) {
|
|
26
|
+
(0, node_v8_1.setFlagsFromString)('--expose_gc');
|
|
27
|
+
setInterval(() => {
|
|
28
|
+
this.check();
|
|
29
|
+
}, this.gcConfig.checkIntervalSec.millis());
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
check() {
|
|
33
|
+
const rss = process.memoryUsage().rss;
|
|
34
|
+
const limitRss = this.rss * (1 + this.gcConfig.rssIncreasePercent / 100);
|
|
35
|
+
if (rss < this.rss) {
|
|
36
|
+
this.rss = rss;
|
|
37
|
+
}
|
|
38
|
+
else if (rss > limitRss) {
|
|
39
|
+
const gc = (0, node_vm_1.runInNewContext)('gc');
|
|
40
|
+
gc();
|
|
41
|
+
this.rss = process.memoryUsage().rss;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
exports.UtilsGCService = UtilsGCService;
|
|
46
|
+
exports.UtilsGCService = UtilsGCService = __decorate([
|
|
47
|
+
(0, common_1.Injectable)(),
|
|
48
|
+
__metadata("design:paramtypes", [config_1.UtilsGCConfig])
|
|
49
|
+
], UtilsGCService);
|
|
50
|
+
//# sourceMappingURL=gc.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gc.service.js","sourceRoot":"","sources":["../src/gc.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,qCAA6C;AAC7C,qCAA0C;AAE1C,qCAAyC;AAGlC,IAAM,cAAc,GAApB,MAAM,cAAc;IAGI;IAFrB,GAAG,CAAS;IAEpB,YAA6B,QAAuB;QAAvB,aAAQ,GAAR,QAAQ,CAAe;QAClD,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC;IACvC,CAAC;IAED,sBAAsB;QACpB,IAAI,IAAI,CAAC,QAAQ,CAAC,iBAAiB,EAAE,CAAC;YACpC,IAAA,4BAAkB,EAAC,aAAa,CAAC,CAAC;YAClC,WAAW,CAAC,GAAG,EAAE;gBACf,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,MAAM,EAAE,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IAED,KAAK;QACH,MAAM,GAAG,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC;QACtC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,kBAAkB,GAAG,GAAG,CAAC,CAAC;QAEzE,IAAI,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACnB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACjB,CAAC;aAAM,IAAI,GAAG,GAAG,QAAQ,EAAE,CAAC;YAC1B,MAAM,EAAE,GAAG,IAAA,yBAAe,EAAC,IAAI,CAAC,CAAC;YAEjC,EAAE,EAAE,CAAC;YAEL,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC;QACvC,CAAC;IACH,CAAC;CACF,CAAA;AA9BY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;qCAI4B,sBAAa;GAHzC,cAAc,CA8B1B"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UtilsGCService = exports.UtilsGCModule = void 0;
|
|
4
|
+
var gc_module_1 = require("./gc.module");
|
|
5
|
+
Object.defineProperty(exports, "UtilsGCModule", { enumerable: true, get: function () { return gc_module_1.UtilsGCModule; } });
|
|
6
|
+
var gc_service_1 = require("./gc.service");
|
|
7
|
+
Object.defineProperty(exports, "UtilsGCService", { enumerable: true, get: function () { return gc_service_1.UtilsGCService; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAAnC,0GAAA,aAAa,OAAA;AACtB,2CAA8C;AAArC,4GAAA,cAAc,OAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rsdk/gc",
|
|
3
|
+
"version": "5.12.0-next.2",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"description": "Garbage collector for nestjs applications",
|
|
8
|
+
"repository": {
|
|
9
|
+
"url": "https://github.com/R-Vision/rsdk"
|
|
10
|
+
},
|
|
11
|
+
"license": "Apache License 2.0",
|
|
12
|
+
"main": "dist/index.js",
|
|
13
|
+
"scripts": {
|
|
14
|
+
"prepublishOnly": "npm run build"
|
|
15
|
+
},
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"@nestjs/common": "^10.4.20",
|
|
18
|
+
"@nestjs/core": "^10.4.20",
|
|
19
|
+
"@nestjs/microservices": "^10.4.20",
|
|
20
|
+
"@rsdk/actx": "*",
|
|
21
|
+
"@rsdk/autodoc.protocol": "*",
|
|
22
|
+
"@rsdk/common": "*",
|
|
23
|
+
"@rsdk/common.nestjs": "*",
|
|
24
|
+
"@rsdk/common.node": "*",
|
|
25
|
+
"@rsdk/core": "*",
|
|
26
|
+
"@rsdk/decorators": "*",
|
|
27
|
+
"@rsdk/logging": "*",
|
|
28
|
+
"@rsdk/metadata": "*",
|
|
29
|
+
"@rsdk/nest-tools": "*",
|
|
30
|
+
"reflect-metadata": "^0.1.12 || ^0.2.0",
|
|
31
|
+
"rxjs": "^7.1.0"
|
|
32
|
+
},
|
|
33
|
+
"gitHead": "6b51ee3aab82a0fe8684112b2571331da8fae4e4"
|
|
34
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Timespan } from '@rsdk/common';
|
|
2
|
+
import {
|
|
3
|
+
BoolParser,
|
|
4
|
+
Config,
|
|
5
|
+
ConfigSection,
|
|
6
|
+
IntParser,
|
|
7
|
+
Property,
|
|
8
|
+
TimespanParser,
|
|
9
|
+
} from '@rsdk/core';
|
|
10
|
+
|
|
11
|
+
@ConfigSection({ prefix: 'GC' })
|
|
12
|
+
export class UtilsGCConfig extends Config {
|
|
13
|
+
@Property('RSS_INCREASE_PERCENT', new IntParser(), {
|
|
14
|
+
defaultValue: 10,
|
|
15
|
+
description:
|
|
16
|
+
'The maximum percentage of rss increase allowed before forced garbage collection occurs',
|
|
17
|
+
})
|
|
18
|
+
readonly rssIncreasePercent!: number;
|
|
19
|
+
|
|
20
|
+
@Property('CHECK_INTERVAL', new TimespanParser(), {
|
|
21
|
+
defaultValue: new Timespan(1, 'minutes'),
|
|
22
|
+
description: 'Memory usage check interval',
|
|
23
|
+
})
|
|
24
|
+
readonly checkIntervalSec!: Timespan;
|
|
25
|
+
|
|
26
|
+
@Property('FORCE_CLEAN_ENABLED', new BoolParser(), {
|
|
27
|
+
description: 'If true, then forced memory clearing is used',
|
|
28
|
+
})
|
|
29
|
+
readonly forceCleanEnabled!: boolean;
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { UtilsGCConfig } from './gc.config';
|
package/src/gc.module.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { setFlagsFromString } from 'node:v8';
|
|
3
|
+
import { runInNewContext } from 'node:vm';
|
|
4
|
+
|
|
5
|
+
import { UtilsGCConfig } from './config';
|
|
6
|
+
|
|
7
|
+
@Injectable()
|
|
8
|
+
export class UtilsGCService {
|
|
9
|
+
private rss: number;
|
|
10
|
+
|
|
11
|
+
constructor(private readonly gcConfig: UtilsGCConfig) {
|
|
12
|
+
this.rss = process.memoryUsage().rss;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
onApplicationBootstrap(): void {
|
|
16
|
+
if (this.gcConfig.forceCleanEnabled) {
|
|
17
|
+
setFlagsFromString('--expose_gc');
|
|
18
|
+
setInterval(() => {
|
|
19
|
+
this.check();
|
|
20
|
+
}, this.gcConfig.checkIntervalSec.millis());
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
check(): void {
|
|
25
|
+
const rss = process.memoryUsage().rss;
|
|
26
|
+
const limitRss = this.rss * (1 + this.gcConfig.rssIncreasePercent / 100);
|
|
27
|
+
|
|
28
|
+
if (rss < this.rss) {
|
|
29
|
+
this.rss = rss;
|
|
30
|
+
} else if (rss > limitRss) {
|
|
31
|
+
const gc = runInNewContext('gc');
|
|
32
|
+
|
|
33
|
+
gc();
|
|
34
|
+
|
|
35
|
+
this.rss = process.memoryUsage().rss;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/index.ts
ADDED