mcpField
B
backend-latency-profiler-helper

backend-latency-profiler-helper

github.com/patricio0312rev开发63263 次安装41 周前更新
代码仓库

关于 backend-latency-profiler-helper

这项技能用于定位并处理后端 API 延迟瓶颈,涵盖端点测量、基于日志的分析、原因评估和分级修复计划。

主要功能

  1. 01测量请求延迟
  2. 02根据日志排列慢端点
  3. 03评估可能的瓶颈原因
  4. 04制定优先级修复路线图
  5. 05配置性能监控

适用场景

  1. 01发现超过延迟阈值的端点
  2. 02根据请求日志比较端点性能
  3. 03规划数据库索引及 N+1 查询修复

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/patricio0312rev/skills --skill backend-latency-profiler-helper

安装后在 Claude Code 中输入/backend-latency-profiler-helper确认已加载。

详细介绍

后端延迟分析助手

发现并修复 API 性能瓶颈。

慢速端点检测

// Middleware to track latency
app.use((req, res, next) => {
  const start = Date.now();

  res.on("finish", () => {
    const duration = Date.now() - start;

    if (duration > 1000) {
      logger.warn(
        {
          endpoint: req.path,
          method: req.method,
          duration_ms: duration,
          userId: req.user?.id,
        },
        "Slow request detected"
      );
    }
  });

  next();
});

最慢的端点

-- Query from logs
SELECT
  endpoint,
  AVG(duration_ms) as avg_ms,
  MAX(duration_ms) as max_ms,
  COUNT(*) as requests
FROM request_logs
WHERE created_at > NOW() - INTERVAL '1 day'
GROUP BY endpoint
HAVING AVG(duration_ms) > 500
ORDER BY avg_ms DESC
LIMIT 10;

疑似原因

interface PerformanceBottleneck {
  endpoint: string;
  avgLatency: number;
  suspectedCauses: string[];
  fixPriority: "high" | "medium" | "low";
}

const bottlenecks: PerformanceBottleneck[] = [
  {
    endpoint: "GET /api/users/:id",
    avgLatency: 2500,
    suspectedCauses: [
      "N+1 query fetching user orders",
      "No database index on user_id",
      "Expensive JSON serialization",
    ],
    fixPriority: "high",
  },
];

修复路线图

# Performance Fix Roadmap

## Week 1: Quick Wins

- [ ] Add database indexes
- [ ] Enable response caching
- [ ] Fix N+1 queries

## Week 2: Medium Effort

- [ ] Optimize slow database queries
- [ ] Implement Redis caching
- [ ] Add connection pooling

## Week 3: Long-term

- [ ] Database query optimization
- [ ] Service decomposition
- [ ] CDN integration

输出检查清单

  • 已识别慢速端点
  • 已分析原因
  • 已制定修复路线图
  • 已配置监控 ENDFILE

评论

支持 Markdown