Skip to content

Commit

Permalink
v3.19.1
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 committed Nov 18, 2024
1 parent 774d751 commit cf2fb9d
Show file tree
Hide file tree
Showing 21 changed files with 354 additions and 27 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
104 changes: 104 additions & 0 deletions benchmark/compose/test-compare.mjs
Original file line number Diff line number Diff line change
@@ -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);
}
67 changes: 67 additions & 0 deletions benchmark/compose/test-new.mjs
Original file line number Diff line number Diff line change
@@ -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();
65 changes: 65 additions & 0 deletions benchmark/compose/test-original.mjs
Original file line number Diff line number Diff line change
@@ -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();
3 changes: 3 additions & 0 deletions benchmark/compose/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

node test-compare.mjs
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@
"cacheDir": ".changelog"
},
"npmClient": "npm",
"version": "3.19.0"
"version": "3.19.1"
}
2 changes: 1 addition & 1 deletion packages-legacy/task/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/axios/package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
4 changes: 2 additions & 2 deletions packages/bull-board/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion packages/bull/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/consul/package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
2 changes: 1 addition & 1 deletion packages/leoric/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/mikro/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@midwayjs/mikro",
"version": "3.19.0",
"version": "3.19.1",
"main": "dist/index.js",
"typings": "index.d.ts",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/mongoose/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/mqtt/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/otel/package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
4 changes: 2 additions & 2 deletions packages/typegoose/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -22,7 +22,7 @@
},
"license": "MIT",
"dependencies": {
"@midwayjs/mongoose": "^3.19.0"
"@midwayjs/mongoose": "^3.19.1"
},
"devDependencies": {
"@midwayjs/core": "^3.19.0",
Expand Down
Loading

0 comments on commit cf2fb9d

Please sign in to comment.