From 11e5f17b20819903253238b481438d6ef15d3917 Mon Sep 17 00:00:00 2001 From: ciniao <4041990@qq.com> Date: Tue, 19 Dec 2023 17:00:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0gc=20Test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js_pm2.config.js | 4 + package-lock.json | 31 ++++++++ package.json | 1 + src/api_o2s/games/Apiheapdump.ts | 23 ++++++ src/monopoly/protocols/games/Ptlheapdump.ts | 18 +++++ src/monopoly/protocols/serviceProto.ts | 84 ++++++++++++++++----- src/setHttp.ts | 3 +- 7 files changed, 145 insertions(+), 19 deletions(-) create mode 100644 src/api_o2s/games/Apiheapdump.ts create mode 100644 src/monopoly/protocols/games/Ptlheapdump.ts diff --git a/js_pm2.config.js b/js_pm2.config.js index 0efa009..bb6f27d 100644 --- a/js_pm2.config.js +++ b/js_pm2.config.js @@ -60,6 +60,8 @@ const localApps = [ instances: instancesNum, // 传递给脚本的参数 args: '-serverType msg', + //允许强制gc + node_args: '--expose-gc', // 是否启用监控模式,默认是false。如果设置成true,当应用程序变动时,pm2会自动重载。这里也可以设置你要监控的文件。 watch: false, // 不用监听的文件 @@ -86,6 +88,8 @@ const crossApps = [ cwd: './', // 传递给脚本的参数 args: '-serverType cross', + //允许强制gc + node_args: '--expose-gc', // 是否启用监控模式,默认是false。如果设置成true,当应用程序变动时,pm2会自动重载。这里也可以设置你要监控的文件。 watch: false, // 不用监听的文件 diff --git a/package-lock.json b/package-lock.json index 824ac2d..c0fc9f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "axios": "^1.4.0", "crypto-js": "^4.1.1", "express": "^4.18.2", + "heapdump": "^0.3.15", "ioredis": "^5.3.2", "json5": "^2.2.3", "mathjs": "^11.4.0", @@ -2545,6 +2546,18 @@ "he": "bin/he" } }, + "node_modules/heapdump": { + "version": "0.3.15", + "resolved": "https://registry.npmjs.org/heapdump/-/heapdump-0.3.15.tgz", + "integrity": "sha512-n8aSFscI9r3gfhOcAECAtXFaQ1uy4QSke6bnaL+iymYZ/dWs9cqDqHM+rALfsHUwukUbxsdlECZ0pKmJdQ/4OA==", + "hasInstallScript": true, + "dependencies": { + "nan": "^2.13.2" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/http-basic": { "version": "8.1.3", "resolved": "https://registry.npmmirror.com/http-basic/-/http-basic-8.1.3.tgz", @@ -3199,6 +3212,11 @@ "integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==", "dev": true }, + "node_modules/nan": { + "version": "2.18.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.18.0.tgz", + "integrity": "sha512-W7tfG7vMOGtD30sHoZSSc/JVYiyDPEyQVso/Zz+/uQd0B0L46gtC+pHha5FFMRpil6fm/AoEcRWyOVi4+E/f8w==" + }, "node_modules/nanoid": { "version": "3.3.1", "resolved": "https://registry.npmmirror.com/nanoid/-/nanoid-3.3.1.tgz", @@ -6645,6 +6663,14 @@ "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", "dev": true }, + "heapdump": { + "version": "0.3.15", + "resolved": "https://registry.npmjs.org/heapdump/-/heapdump-0.3.15.tgz", + "integrity": "sha512-n8aSFscI9r3gfhOcAECAtXFaQ1uy4QSke6bnaL+iymYZ/dWs9cqDqHM+rALfsHUwukUbxsdlECZ0pKmJdQ/4OA==", + "requires": { + "nan": "^2.13.2" + } + }, "http-basic": { "version": "8.1.3", "resolved": "https://registry.npmmirror.com/http-basic/-/http-basic-8.1.3.tgz", @@ -7163,6 +7189,11 @@ "integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==", "dev": true }, + "nan": { + "version": "2.18.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.18.0.tgz", + "integrity": "sha512-W7tfG7vMOGtD30sHoZSSc/JVYiyDPEyQVso/Zz+/uQd0B0L46gtC+pHha5FFMRpil6fm/AoEcRWyOVi4+E/f8w==" + }, "nanoid": { "version": "3.3.1", "resolved": "https://registry.npmmirror.com/nanoid/-/nanoid-3.3.1.tgz", diff --git a/package.json b/package.json index 99faaea..2f06bdb 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "axios": "^1.4.0", "crypto-js": "^4.1.1", "express": "^4.18.2", + "heapdump": "^0.3.15", "ioredis": "^5.3.2", "json5": "^2.2.3", "mathjs": "^11.4.0", diff --git a/src/api_o2s/games/Apiheapdump.ts b/src/api_o2s/games/Apiheapdump.ts new file mode 100644 index 0000000..e4b923d --- /dev/null +++ b/src/api_o2s/games/Apiheapdump.ts @@ -0,0 +1,23 @@ +import { ApiCall } from "tsrpc"; +import { Reqheapdump, Resheapdump } from "../../monopoly/protocols/games/Ptlheapdump"; +var heapdump = require('heapdump'); + +export default async function (call: ApiCall) { + + if(call.req.act == "heapdump"){ + let name = Date.now() + '.heapsnapshot' + heapdump.writeSnapshot(name); + call.succ({ + code:200, + data:name + }) + } + + if(call.req.act == "gc"){ + global.gc(); + call.succ({ + code:200, + data:"gc..." + }) + } +} \ No newline at end of file diff --git a/src/monopoly/protocols/games/Ptlheapdump.ts b/src/monopoly/protocols/games/Ptlheapdump.ts new file mode 100644 index 0000000..bd93a7f --- /dev/null +++ b/src/monopoly/protocols/games/Ptlheapdump.ts @@ -0,0 +1,18 @@ +import { StringTypeSchema } from "tsbuffer-schema"; + +/** + * 区服初始化 + */ +export type Reqheapdump = { + act:string, + data:any +}; + + +export type Resheapdump = { + /** + * 如果发送成功 将返回 + */ + code: number + data: any; +}; \ No newline at end of file diff --git a/src/monopoly/protocols/serviceProto.ts b/src/monopoly/protocols/serviceProto.ts index 782cc14..6ca08f2 100644 --- a/src/monopoly/protocols/serviceProto.ts +++ b/src/monopoly/protocols/serviceProto.ts @@ -1,6 +1,7 @@ import { ServiceProto } from 'tsrpc-proto'; import { Reqsendemail, Ressendemail } from './email/Ptlsendemail'; import { Reqdeploy, Resdeploy } from './games/Ptldeploy'; +import { Reqheapdump, Resheapdump } from './games/Ptlheapdump'; import { Reqmetrics, Resmetrics } from './games/Ptlmetrics'; import { Reqnotification, Resnotification } from './games/Ptlnotification'; import { Reqopen, Resopen } from './games/Ptlopen'; @@ -31,6 +32,10 @@ export interface ServiceType { req: Reqdeploy, res: Resdeploy }, + "games/heapdump": { + req: Reqheapdump, + res: Resheapdump + }, "games/metrics": { req: Reqmetrics, res: Resmetrics @@ -127,96 +132,101 @@ export const serviceProto: ServiceProto = { }, { "id": 2, - "name": "games/metrics", + "name": "games/heapdump", "type": "api" }, { "id": 3, - "name": "games/notification", + "name": "games/metrics", "type": "api" }, { "id": 4, - "name": "games/open", + "name": "games/notification", "type": "api" }, { "id": 5, - "name": "games/ranking", + "name": "games/open", "type": "api" }, { "id": 6, - "name": "gift/popup", + "name": "games/ranking", "type": "api" }, { "id": 7, - "name": "gm/Pay", + "name": "gift/popup", "type": "api" }, { "id": 8, - "name": "gm/SendPrize", + "name": "gm/Pay", "type": "api" }, { "id": 9, - "name": "hdinfo/details", + "name": "gm/SendPrize", "type": "api" }, { "id": 10, - "name": "AddHuoDong", + "name": "hdinfo/details", "type": "api" }, { "id": 11, - "name": "CatAllhd", + "name": "AddHuoDong", "type": "api" }, { "id": 12, - "name": "DelHuoDong", + "name": "CatAllhd", "type": "api" }, { "id": 13, - "name": "Email", + "name": "DelHuoDong", "type": "api" }, { "id": 14, - "name": "GetLog", + "name": "Email", "type": "api" }, { "id": 15, - "name": "healthz", + "name": "GetLog", "type": "api" }, { "id": 16, - "name": "union/rename", + "name": "healthz", "type": "api" }, { "id": 17, - "name": "user/data", + "name": "union/rename", "type": "api" }, { "id": 18, - "name": "user/disable", + "name": "user/data", "type": "api" }, { "id": 19, - "name": "user/getdata", + "name": "user/disable", "type": "api" }, { "id": 20, + "name": "user/getdata", + "type": "api" + }, + { + "id": 21, "name": "user/rename", "type": "api" } @@ -367,6 +377,44 @@ export const serviceProto: ServiceProto = { } ] }, + "games/Ptlheapdump/Reqheapdump": { + "type": "Interface", + "properties": [ + { + "id": 0, + "name": "act", + "type": { + "type": "String" + } + }, + { + "id": 1, + "name": "data", + "type": { + "type": "Any" + } + } + ] + }, + "games/Ptlheapdump/Resheapdump": { + "type": "Interface", + "properties": [ + { + "id": 0, + "name": "code", + "type": { + "type": "Number" + } + }, + { + "id": 1, + "name": "data", + "type": { + "type": "Any" + } + } + ] + }, "games/Ptlmetrics/Reqmetrics": { "type": "Interface" }, diff --git a/src/setHttp.ts b/src/setHttp.ts index 6c10173..62af391 100644 --- a/src/setHttp.ts +++ b/src/setHttp.ts @@ -10,7 +10,8 @@ export async function createHttp() { json: true, cors: '*', port: G.config.httpPort, - logLevel: G.argv.logModel as LogLevel + logLevel: G.argv.logModel as LogLevel, + apiTimeout:300000, }); setHttp(G.http); await G.http.autoImplementApi(resolve(__dirname, 'api_o2s'), true);