Added example of debugging memory usage using Chrome/Chromium
This commit is contained in:
parent
e39fc4fb12
commit
eddc998bed
3 changed files with 57 additions and 0 deletions
13
README.md
13
README.md
|
|
@ -1,2 +1,15 @@
|
|||
# nodejs_warsaw_xxii
|
||||
|
||||
1. ```git clone git@git.techserio.com:mattiashz/nodejs_warsaw_xxii.git```
|
||||
2. ```cd nodejs_warsaw_xxii```
|
||||
3. ```npm install```
|
||||
4. ```node main.js```
|
||||
5. ```curl localhost:3000/helloworld```
|
||||
6. ```curl localhost:3000/hogger```
|
||||
5. open terminal
|
||||
6. ```ps aux | grep "node main.js"```
|
||||
7. ```kill -USR1 <process number>```
|
||||
8. Open Chrome / Chromium
|
||||
9. go to address ```chrome://inspect```
|
||||
10. Click "Open dedicated DevTools for Node"
|
||||
|
||||
|
|
|
|||
26
main.js
Normal file
26
main.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
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');
|
||||
});
|
||||
18
package.json
Normal file
18
package.json
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"name": "nodejs_warsaw_xxii",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@git.techserio.com:mattiashz/nodejs_warsaw_xxii.git"
|
||||
},
|
||||
"author": "hz",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"express": "^5.1.0"
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue