backend-latency-profiler-helper
Backend Latency Profiler Helper
Find and fix API performance bottlenecks.
Slow Endpoint Detection
// 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();
});
Top Slow Endpoints
-- 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;
Suspected Causes
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",
},
];
Fix Roadmap
# 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
Output Checklist
- Slow endpoints identified
- Causes analyzed
- Fix roadmap created
- Monitoring configured ENDFILE
More from monkey1sai/openai-cli
multi-tenant-safety-checker
Ensures tenant isolation at query and policy level using Row Level Security, automated testing, and security audits. Prevents data leakage between tenants. Use for "multi-tenancy", "tenant isolation", "RLS", or "data security".
10modal-drawer-system
Implements accessible modals and drawers with focus trap, ESC to close, scroll lock, portal rendering, and ARIA attributes. Includes sample implementations for common use cases like edit forms, confirmations, and detail views. Use when building "modals", "dialogs", "drawers", "sidebars", or "overlays".
10eslint-prettier-config
Configures ESLint and Prettier for consistent code quality with TypeScript, React, and modern best practices. Use when users request "ESLint setup", "Prettier config", "linting configuration", "code formatting", or "lint rules".
9api-security-hardener
Hardens API security with rate limiting, input validation, authentication, and protection against common attacks. Use when users request "API security", "secure API", "rate limiting", "input validation", or "API protection".
9secure-headers-csp-builder
Implements security headers and Content Security Policy with safe rollout strategy (report-only → enforce), testing, and compatibility checks. Use for "security headers", "CSP", "HTTP headers", or "XSS protection".
9security-incident-playbook-generator
Creates response procedures for security incidents with containment steps, communication templates, and evidence collection. Use for "incident response", "security playbook", "breach response", or "IR plan".
9