Commit 21de152f by caigua Committed by GitHub

fix: 避免日志记录触发递归日志风暴,排除日志模型的性能监控中间件 (#5910)

初始慢操作触发日志写入,增加系统负载;日志写入因负载过高变缓,被判定为新的慢操作,进而触发更多日志;持续升高的负载让所有操作进一步变慢,生成更多日志。最终形成“越慢越写、越写越慢”的自我强化正反馈循环,即便初始高并发业务流量结束,循环仍会持续耗尽系统资源,直至服务崩溃。

修复方案:
- 对日志模型(Log)跳过 addCommonMiddleware 中间件注册
- 避免日志写入操作被自身监控逻辑拦截,从源头切断循环触发条件
- 不影响业务模型的慢操作监控功能,仅豁免日志自身的性能统计
parent fa163a54
......@@ -112,7 +112,7 @@ export const getMongoModel = <T>(name: string, schema: mongoose.Schema) => {
export const getMongoLogModel = <T>(name: string, schema: mongoose.Schema) => {
if (connectionLogMongo.models[name]) return connectionLogMongo.models[name] as Model<T>;
console.log('Load model======', name);
addCommonMiddleware(schema);
// addCommonMiddleware(schema);
const model = connectionLogMongo.model<T>(name, schema);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment