From cf2fb9d4990bab9e8d28b034f31f242d510ce873 Mon Sep 17 00:00:00 2001 From: Harry Chen Date: Mon, 18 Nov 2024 23:03:35 +0800 Subject: [PATCH] v3.19.1 --- CHANGELOG.md | 27 +++++ benchmark/compose/test-compare.mjs | 104 +++++++++++++++++++ benchmark/compose/test-new.mjs | 67 ++++++++++++ benchmark/compose/test-original.mjs | 65 ++++++++++++ benchmark/compose/test.sh | 3 + lerna.json | 2 +- packages-legacy/task/package.json | 2 +- packages/axios/package.json | 2 +- packages/bull-board/package.json | 4 +- packages/bull/package.json | 2 +- packages/consul/package.json | 2 +- packages/leoric/package.json | 2 +- packages/mikro/package.json | 2 +- packages/mongoose/package.json | 2 +- packages/mqtt/package.json | 2 +- packages/otel/package.json | 2 +- packages/typegoose/package.json | 4 +- packages/version/index.js | 2 +- packages/version/package.json | 2 +- packages/version/versions/3_19_0-3_19_0.json | 55 ++++++++-- scripts/rollback/rollback-3.19.1.sh | 28 +++++ 21 files changed, 354 insertions(+), 27 deletions(-) create mode 100644 benchmark/compose/test-compare.mjs create mode 100644 benchmark/compose/test-new.mjs create mode 100644 benchmark/compose/test-original.mjs create mode 100755 benchmark/compose/test.sh create mode 100644 scripts/rollback/rollback-3.19.1.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 54ab7eac293f..295409141703 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,33 @@ # Change Log +## v3.19.1 (2024-11-18) + +#### :bug: Bug Fix +* `leoric` + * [#4192](https://github.com/midwayjs/midway/pull/4192) fix(leoric): keep multiple datasources from conflicting base model ([@cyjake](https://github.com/cyjake)) + +#### :package: Dependencies +* `otel` + * [#4193](https://github.com/midwayjs/midway/pull/4193) chore(deps): update dependency @opentelemetry/sdk-node to v0.55.0 ([@renovate[bot]](https://github.com/apps/renovate)) +* Other + * [#4191](https://github.com/midwayjs/midway/pull/4191) chore(deps): update dependency @vercel/ncc to v0.38.3 ([@renovate[bot]](https://github.com/apps/renovate)) +* `mqtt` + * [#4190](https://github.com/midwayjs/midway/pull/4190) fix(deps): update dependency mqtt to v5.10.2 - autoclosed ([@renovate[bot]](https://github.com/apps/renovate)) +* `bull` + * [#4189](https://github.com/midwayjs/midway/pull/4189) fix(deps): update dependency bull to v4.16.4 ([@renovate[bot]](https://github.com/apps/renovate)) +* `mongoose`, `typegoose` + * [#4185](https://github.com/midwayjs/midway/pull/4185) chore(deps): update dependency mongoose to v8.8.1 ([@renovate[bot]](https://github.com/apps/renovate)) +* `mikro` + * [#4188](https://github.com/midwayjs/midway/pull/4188) chore(deps): update mikro-orm monorepo to v6.4.0 ([@renovate[bot]](https://github.com/apps/renovate)) +* `axios`, `consul` + * [#4187](https://github.com/midwayjs/midway/pull/4187) chore(deps): update dependency nock to v13.5.6 ([@renovate[bot]](https://github.com/apps/renovate)) + +#### Committers: 1 +- Chen Yangjian ([@cyjake](https://github.com/cyjake)) + + + ## v3.19.0 (2024-11-08) #### :rocket: New Feature diff --git a/benchmark/compose/test-compare.mjs b/benchmark/compose/test-compare.mjs new file mode 100644 index 000000000000..1c72af3059b2 --- /dev/null +++ b/benchmark/compose/test-compare.mjs @@ -0,0 +1,104 @@ +import { spawn } from 'child_process'; +import { createInterface } from 'readline'; + +async function runTest(scriptPath, label) { + return new Promise((resolve, reject) => { + const results = []; + const process = spawn('node', ['--expose-gc', scriptPath]); + const rl = createInterface({ input: process.stdout }); + + console.log(`开始运行${label}...`); + + rl.on('line', (line) => { + // 只捕获性能相关的数据 + if (line.includes('本轮耗时') || + line.includes('平均每次') || + line.includes('总计耗时') || + line.includes('heapUsed')) { + results.push(line.trim()); + } + }); + + process.stderr.on('data', (data) => { + console.error(`${label} 错误: ${data}`); + }); + + process.on('close', (code) => { + resolve(results); + }); + + process.on('error', (err) => { + reject(err); + }); + }); +} + +console.log('=== Compose 性能对比测试 ===\n'); + +function formatResults(original, newVer, diff) { + // 格式化数值,左对齐 + const format = (value, unit) => `${value.toFixed(2)}${unit}`.padEnd(10); + + const formatLine = (label, orig, origUnit, next, nextUnit, diffVal) => { + const col1 = label.padEnd(20); // 第一列:标签 + const col2 = `${format(orig, origUnit)} (旧)`.padEnd(20); // 第二列:旧值 + const col3 = `${format(next, nextUnit)} (新)`.padEnd(20); // 第三列:新值 + const col4 = `[提升: ${diffVal}%]`; // 第四列:提升 + return `${col1}${col2}${col3}${col4}`; + }; + + return [ + formatLine('本轮耗时', original.roundTime, 'ms', newVer.roundTime, 'ms', diff.roundTime), + formatLine('平均每次', original.avgTime, 'ms', newVer.avgTime, 'ms', diff.avgTime), + formatLine('总计耗时', original.totalTime, 'ms', newVer.totalTime, 'ms', diff.totalTime), + formatLine('堆内存', original.heapUsed, 'MB', newVer.heapUsed, 'MB', diff.heapUsed) + ].join('\n'); +} + +try { + const [originalResults, newResults] = await Promise.all([ + runTest('./test-original.mjs', '原始版本'), + runTest('./test-new.mjs', '新版本') + ]); + + console.log('\n=== 性能对比结果 ===\n'); + + const minLength = Math.min( + originalResults.length - (originalResults.length % 4), + newResults.length - (newResults.length % 4) + ); + + for (let i = 0; i < minLength; i += 4) { + const checkpoint = (i / 4 + 1) * 10000; + console.log(`\n检查点 ${checkpoint.toLocaleString()} 次:`); + + // 解析原始数据 + const original = { + roundTime: parseFloat(originalResults[i].match(/[\d.]+/)[0]), + avgTime: parseFloat(originalResults[i + 1].match(/[\d.]+/)[0]), + totalTime: parseFloat(originalResults[i + 2].match(/[\d.]+/)[0]), + heapUsed: parseFloat(originalResults[i + 3].match(/[\d.]+/)[0]) + }; + + // 解析新版本数据 + const newVer = { + roundTime: parseFloat(newResults[i].match(/[\d.]+/)[0]), + avgTime: parseFloat(newResults[i + 1].match(/[\d.]+/)[0]), + totalTime: parseFloat(newResults[i + 2].match(/[\d.]+/)[0]), + heapUsed: parseFloat(newResults[i + 3].match(/[\d.]+/)[0]) + }; + + // 计算性能差异 + const diff = { + roundTime: ((original.roundTime - newVer.roundTime) / original.roundTime * 100).toFixed(2), + avgTime: ((original.avgTime - newVer.avgTime) / original.avgTime * 100).toFixed(2), + totalTime: ((original.totalTime - newVer.totalTime) / original.totalTime * 100).toFixed(2), + heapUsed: ((original.heapUsed - newVer.heapUsed) / original.heapUsed * 100).toFixed(2) + }; + + console.log(formatResults(original, newVer, diff)); + } + +} catch (error) { + console.error('测试执行出错:', error); +} \ No newline at end of file diff --git a/benchmark/compose/test-new.mjs b/benchmark/compose/test-new.mjs new file mode 100644 index 000000000000..587bf12ea618 --- /dev/null +++ b/benchmark/compose/test-new.mjs @@ -0,0 +1,67 @@ +// 测试重构版本 +function dispatch(i, middlewareArr) { + if (i === middlewareArr.length) return Promise.resolve(); + const fn = middlewareArr[i]; + return Promise.resolve( + fn({}, () => dispatch(i + 1, middlewareArr)) + ); +} + +function createNewCompose() { + return (context, next) => { + // 创建100个中间件 + const newMiddlewareArr = Array(100).fill(null).map(() => + async (ctx, next) => { + await next(); + } + ); + + return dispatch(0, newMiddlewareArr); + }; +} +// 格式化内存数据 +function formatMemory(bytes) { + return (bytes / 1024 / 1024).toFixed(2) + ' MB'; +} + +// 格式化内存使用情况 +function formatMemoryUsage(memoryUsage) { + return { + heapUsed: formatMemory(memoryUsage.heapUsed), // 实际使用的堆内存 + heapTotal: formatMemory(memoryUsage.heapTotal), // 总堆内存 + rss: formatMemory(memoryUsage.rss), // 常驻集大小 + external: formatMemory(memoryUsage.external) // V8 外部内存 + }; +} + +const compose = createNewCompose(); + +console.log('\n=== 重构版本测试 ==='); +console.log('初始内存使用情况:'); +console.table(formatMemoryUsage(process.memoryUsage())); + +let count = 0; +const startTime = process.hrtime.bigint(); +let lastTime = startTime; + +async function run() { + while (count < 100000) { + await compose({}); + count++; + + if (count % 10000 === 0) { + const currentTime = process.hrtime.bigint(); + const totalTime = Number(currentTime - startTime) / 1e6; // 转换为毫秒 + const intervalTime = Number(currentTime - lastTime) / 1e6; + lastTime = currentTime; + + console.log(`\n执行 ${count.toLocaleString()} 次后的性能数据:`); + console.log(`本轮耗时: ${intervalTime.toFixed(2)}ms`); + console.log(`平均每次: ${(intervalTime / 10000).toFixed(3)}ms`); + console.log(`总计耗时: ${totalTime.toFixed(2)}ms`); + console.table(formatMemoryUsage(process.memoryUsage())); + } + } +} + +run(); \ No newline at end of file diff --git a/benchmark/compose/test-original.mjs b/benchmark/compose/test-original.mjs new file mode 100644 index 000000000000..91e1ec2315bd --- /dev/null +++ b/benchmark/compose/test-original.mjs @@ -0,0 +1,65 @@ +// 测试原始版本 +function createOriginalCompose() { + return (context, next) => { + // 创建100个中间件 + const newMiddlewareArr = Array(100).fill(null).map(() => + async (ctx, next) => { + await next(); + } + ); + + function dispatch(i) { + if (i === newMiddlewareArr.length) return Promise.resolve(); + const fn = newMiddlewareArr[i]; + return Promise.resolve(fn({}, () => dispatch(i + 1))); + } + + return dispatch(0); + }; +} +// 格式化内存数据 +function formatMemory(bytes) { + return (bytes / 1024 / 1024).toFixed(2) + ' MB'; +} + +// 格式化内存使用情况 +function formatMemoryUsage(memoryUsage) { + return { + heapUsed: formatMemory(memoryUsage.heapUsed), + heapTotal: formatMemory(memoryUsage.heapTotal), + rss: formatMemory(memoryUsage.rss), + external: formatMemory(memoryUsage.external) + }; +} + +const compose = createOriginalCompose(); + +console.log('\n=== 原始版本测试 ==='); +console.log('初始内存使用情况:'); +console.table(formatMemoryUsage(process.memoryUsage())); + +let count = 0; +const startTime = process.hrtime.bigint(); +let lastTime = startTime; + +async function run() { + while (count < 100000) { + await compose({}); + count++; + + if (count % 10000 === 0) { + const currentTime = process.hrtime.bigint(); + const totalTime = Number(currentTime - startTime) / 1e6; // 转换为毫秒 + const intervalTime = Number(currentTime - lastTime) / 1e6; + lastTime = currentTime; + + console.log(`\n执行 ${count.toLocaleString()} 次后的性能数据:`); + console.log(`本轮耗时: ${intervalTime.toFixed(2)}ms`); + console.log(`平均每次: ${(intervalTime / 10000).toFixed(3)}ms`); + console.log(`总计耗时: ${totalTime.toFixed(2)}ms`); + console.table(formatMemoryUsage(process.memoryUsage())); + } + } +} + +run(); \ No newline at end of file diff --git a/benchmark/compose/test.sh b/benchmark/compose/test.sh new file mode 100755 index 000000000000..e48233dcfb2b --- /dev/null +++ b/benchmark/compose/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +node test-compare.mjs \ No newline at end of file diff --git a/lerna.json b/lerna.json index be62cc8f7871..929305b788f8 100644 --- a/lerna.json +++ b/lerna.json @@ -47,5 +47,5 @@ "cacheDir": ".changelog" }, "npmClient": "npm", - "version": "3.19.0" + "version": "3.19.1" } diff --git a/packages-legacy/task/package.json b/packages-legacy/task/package.json index ad86a3fe61cd..42ff00b5107a 100644 --- a/packages-legacy/task/package.json +++ b/packages-legacy/task/package.json @@ -1,6 +1,6 @@ { "name": "@midwayjs/task", - "version": "3.19.0", + "version": "3.19.1", "private": true, "description": "midway component for task and schedule", "main": "dist/index.js", diff --git a/packages/axios/package.json b/packages/axios/package.json index 771afb778805..7afc9540a65c 100644 --- a/packages/axios/package.json +++ b/packages/axios/package.json @@ -1,7 +1,7 @@ { "name": "@midwayjs/axios", "description": "midway http client with axios", - "version": "3.19.0", + "version": "3.19.1", "main": "dist/index.js", "typings": "index.d.ts", "files": [ diff --git a/packages/bull-board/package.json b/packages/bull-board/package.json index aec36dd107e1..5d92ec446995 100644 --- a/packages/bull-board/package.json +++ b/packages/bull-board/package.json @@ -1,6 +1,6 @@ { "name": "@midwayjs/bull-board", - "version": "3.19.0", + "version": "3.19.1", "description": "midway component for bull", "main": "dist/index.js", "typings": "index.d.ts", @@ -32,7 +32,7 @@ "dependencies": { "@bull-board/api": "5.23.0", "@bull-board/ui": "5.23.0", - "@midwayjs/bull": "^3.19.0", + "@midwayjs/bull": "^3.19.1", "ejs": "3.1.10" }, "engines": { diff --git a/packages/bull/package.json b/packages/bull/package.json index 18aa16aebae5..8b05ad815ed3 100644 --- a/packages/bull/package.json +++ b/packages/bull/package.json @@ -1,6 +1,6 @@ { "name": "@midwayjs/bull", - "version": "3.19.0", + "version": "3.19.1", "description": "midway component for bull", "main": "dist/index.js", "typings": "index.d.ts", diff --git a/packages/consul/package.json b/packages/consul/package.json index abecb9b8c36b..427dd9a06d99 100644 --- a/packages/consul/package.json +++ b/packages/consul/package.json @@ -1,7 +1,7 @@ { "name": "@midwayjs/consul", "description": "midway consul", - "version": "3.19.0", + "version": "3.19.1", "main": "dist/index.js", "typings": "index.d.ts", "files": [ diff --git a/packages/leoric/package.json b/packages/leoric/package.json index 804ac1e51767..bc80e913cef0 100644 --- a/packages/leoric/package.json +++ b/packages/leoric/package.json @@ -1,6 +1,6 @@ { "name": "@midwayjs/leoric", - "version": "3.19.0", + "version": "3.19.1", "description": "Leoric as a Midway model component", "main": "dist/index.js", "typings": "index.d.ts", diff --git a/packages/mikro/package.json b/packages/mikro/package.json index cb4c2c320e48..e3f8d0a67c0b 100644 --- a/packages/mikro/package.json +++ b/packages/mikro/package.json @@ -1,6 +1,6 @@ { "name": "@midwayjs/mikro", - "version": "3.19.0", + "version": "3.19.1", "main": "dist/index.js", "typings": "index.d.ts", "files": [ diff --git a/packages/mongoose/package.json b/packages/mongoose/package.json index 4d0d6e8e7367..000dc3bb7942 100644 --- a/packages/mongoose/package.json +++ b/packages/mongoose/package.json @@ -1,6 +1,6 @@ { "name": "@midwayjs/mongoose", - "version": "3.19.0", + "version": "3.19.1", "description": "Midway Component for mongoose", "main": "dist/index.js", "typings": "index.d.ts", diff --git a/packages/mqtt/package.json b/packages/mqtt/package.json index 4af23a3966d5..02862230150c 100644 --- a/packages/mqtt/package.json +++ b/packages/mqtt/package.json @@ -1,6 +1,6 @@ { "name": "@midwayjs/mqtt", - "version": "3.19.0", + "version": "3.19.1", "description": "Midway Framework for mqtt", "main": "dist/index.js", "typings": "index.d.ts", diff --git a/packages/otel/package.json b/packages/otel/package.json index c02b2b9e2191..1ecd363118ef 100644 --- a/packages/otel/package.json +++ b/packages/otel/package.json @@ -1,7 +1,7 @@ { "name": "@midwayjs/otel", "description": "midway open telemetry component", - "version": "3.19.0", + "version": "3.19.1", "main": "dist/index.js", "typings": "index.d.ts", "files": [ diff --git a/packages/typegoose/package.json b/packages/typegoose/package.json index 1b8e6397d4f4..bd75934b451e 100644 --- a/packages/typegoose/package.json +++ b/packages/typegoose/package.json @@ -1,6 +1,6 @@ { "name": "@midwayjs/typegoose", - "version": "3.19.0", + "version": "3.19.1", "description": "Midway Component for typegoose", "main": "dist/index.js", "typings": "index.d.ts", @@ -22,7 +22,7 @@ }, "license": "MIT", "dependencies": { - "@midwayjs/mongoose": "^3.19.0" + "@midwayjs/mongoose": "^3.19.1" }, "devDependencies": { "@midwayjs/core": "^3.19.0", diff --git a/packages/version/index.js b/packages/version/index.js index e70c49fe414d..98cc240b09e5 100644 --- a/packages/version/index.js +++ b/packages/version/index.js @@ -1,5 +1,5 @@ module.exports = { "decorator": "3.19.0", "core": "3.19.0", - "timestamp": 1731080046133 + "timestamp": 1731942208288 }; diff --git a/packages/version/package.json b/packages/version/package.json index 5d8e1c5cef6d..b8ebe831dc16 100644 --- a/packages/version/package.json +++ b/packages/version/package.json @@ -1,6 +1,6 @@ { "name": "@midwayjs/version", - "version": "3.19.0", + "version": "3.19.1", "description": "Midway Package Version Manager", "main": "index.js", "scripts": { diff --git a/packages/version/versions/3_19_0-3_19_0.json b/packages/version/versions/3_19_0-3_19_0.json index 223a992b2d16..d8d9062e1a91 100644 --- a/packages/version/versions/3_19_0-3_19_0.json +++ b/packages/version/versions/3_19_0-3_19_0.json @@ -3,10 +3,19 @@ "@midwayjs/fc-starter": "3.19.0", "@midwayjs/serverless-http-parser": "3.14.0", "@midwayjs/async-hooks-context-manager": "3.19.0", - "@midwayjs/axios": "3.19.0", + "@midwayjs/axios": [ + "3.19.0", + "3.19.1" + ], "@midwayjs/bootstrap": "3.19.0", - "@midwayjs/bull": "3.19.0", - "@midwayjs/bull-board": "3.19.0", + "@midwayjs/bull": [ + "3.19.0", + "3.19.1" + ], + "@midwayjs/bull-board": [ + "3.19.0", + "3.19.1" + ], "@midwayjs/busboy": "3.19.0", "@midwayjs/cache-manager": "3.19.0", "@midwayjs/captcha": "3.19.0", @@ -14,7 +23,10 @@ "@midwayjs/casbin-redis-adapter": "3.19.0", "@midwayjs/casbin-typeorm-adapter": "3.19.0", "@midwayjs/code-dye": "3.19.0", - "@midwayjs/consul": "3.19.0", + "@midwayjs/consul": [ + "3.19.0", + "3.19.1" + ], "@midwayjs/core": "3.19.0", "@midwayjs/cos": "3.19.0", "@midwayjs/cron": "3.19.0", @@ -29,13 +41,28 @@ "@midwayjs/info": "3.19.0", "@midwayjs/jwt": "3.19.0", "@midwayjs/kafka": "3.19.0", - "@midwayjs/leoric": "3.19.0", - "@midwayjs/mikro": "3.19.0", + "@midwayjs/leoric": [ + "3.19.0", + "3.19.1" + ], + "@midwayjs/mikro": [ + "3.19.0", + "3.19.1" + ], "@midwayjs/mock": "3.19.0", - "@midwayjs/mongoose": "3.19.0", - "@midwayjs/mqtt": "3.19.0", + "@midwayjs/mongoose": [ + "3.19.0", + "3.19.1" + ], + "@midwayjs/mqtt": [ + "3.19.0", + "3.19.1" + ], "@midwayjs/oss": "3.19.0", - "@midwayjs/otel": "3.19.0", + "@midwayjs/otel": [ + "3.19.0", + "3.19.1" + ], "@midwayjs/passport": "3.19.0", "@midwayjs/process-agent": "3.19.0", "@midwayjs/prometheus": "3.19.0", @@ -51,11 +78,17 @@ "@midwayjs/tablestore": "3.19.0", "@midwayjs/tags": "3.19.0", "@midwayjs/tenant": "3.19.0", - "@midwayjs/typegoose": "3.19.0", + "@midwayjs/typegoose": [ + "3.19.0", + "3.19.1" + ], "@midwayjs/typeorm": "3.19.0", "@midwayjs/upload": "3.19.0", "@midwayjs/validate": "3.19.0", - "@midwayjs/version": "3.19.0", + "@midwayjs/version": [ + "3.19.0", + "3.19.1" + ], "@midwayjs/view": "3.19.0", "@midwayjs/view-ejs": "3.19.0", "@midwayjs/view-nunjucks": "3.19.0", diff --git a/scripts/rollback/rollback-3.19.1.sh b/scripts/rollback/rollback-3.19.1.sh new file mode 100644 index 000000000000..9c9b0928d122 --- /dev/null +++ b/scripts/rollback/rollback-3.19.1.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# timestamp: 1731942174671 + +npm dist-tag add @midwayjs/axios@3.19.0 latest +npm dist-tag add @midwayjs/bull@3.19.0 latest +npm dist-tag add @midwayjs/bull-board@3.19.0 latest +npm dist-tag add @midwayjs/consul@3.19.0 latest +npm dist-tag add @midwayjs/leoric@3.19.0 latest +npm dist-tag add @midwayjs/mikro@3.19.0 latest +npm dist-tag add @midwayjs/mongoose@3.19.0 latest +npm dist-tag add @midwayjs/mqtt@3.19.0 latest +npm dist-tag add @midwayjs/otel@3.19.0 latest +npm dist-tag add @midwayjs/typegoose@3.19.0 latest +npm dist-tag add @midwayjs/version@3.19.0 latest + +# Changes: + +# - @midwayjs/axios: 3.19.0 => 3.19.1 +# - @midwayjs/bull: 3.19.0 => 3.19.1 +# - @midwayjs/bull-board: 3.19.0 => 3.19.1 +# - @midwayjs/consul: 3.19.0 => 3.19.1 +# - @midwayjs/leoric: 3.19.0 => 3.19.1 +# - @midwayjs/mikro: 3.19.0 => 3.19.1 +# - @midwayjs/mongoose: 3.19.0 => 3.19.1 +# - @midwayjs/mqtt: 3.19.0 => 3.19.1 +# - @midwayjs/otel: 3.19.0 => 3.19.1 +# - @midwayjs/typegoose: 3.19.0 => 3.19.1 +# - @midwayjs/version: 3.19.0 => 3.19.1