nodejs_warsaw_xxii/main.js

28 lines
No EOL
898 B
JavaScript

const express = require('express');
const app = express();
app.get('/helloworld', (req, res) => {
res.send('hello, world');
});
app.get('/hogger', (req, res) => {
let buf = Buffer.alloc(100 * 1024 * 1024); // 100 MB
for (let i = 0; i < buf.length; i += 4096) { // touch each 4KB page → real RSS
buf[i] = 1;
}
setTimeout(() => {
res.send('hog done');
buf = null;
}, 10_000);
});
setInterval(() => {
const m = process.memoryUsage();
console.log( `rss: ${(m.rss/1024/1024).toFixed(1)} MB, ` + `heapUsed: ${(m.heapUsed/1024/1024).toFixed(1)} MB, ` +
`external: ${(m.external/1024/1024).toFixed(1)} MB`);}, 1000);
app.listen(3000, () => {
console.log('Listening on http://localhost:3000');
console.log('Listening on http://localhost:3000/helloworld');
console.log('Listening on http://localhost:3000/hogger');
});