Loading...
Loading...
Compare original and translation side by side
// 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();
});// 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;-- 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",
},
];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",
},
];undefinedundefinedundefinedundefined