Add performance regression detection: indexes, timing middleware, benchmark script
Nightshift-Task: perf-regression Nightshift-Ref: https://github.com/marcus/nightshift
This commit is contained in:
21
server/src/middleware/timing.js
Normal file
21
server/src/middleware/timing.js
Normal file
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
const SLOW_THRESHOLD_MS = 200;
|
||||
|
||||
function timingMiddleware(req, res, next) {
|
||||
const start = Date.now();
|
||||
|
||||
res.on('finish', () => {
|
||||
const duration = Date.now() - start;
|
||||
const msg = `${req.method} ${req.path} ${res.statusCode} ${duration}ms`;
|
||||
if (duration >= SLOW_THRESHOLD_MS) {
|
||||
console.warn(`[SLOW] ${msg}`);
|
||||
} else {
|
||||
console.log(`[timing] ${msg}`);
|
||||
}
|
||||
});
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
module.exports = timingMiddleware;
|
||||
Reference in New Issue
Block a user