When running your Node.js application in Azure Linux App Service, you may encounter memory consumption issue.
Nodejs heapdump module provides developers a simple mechanism for producing V8 heap snapshots for later inspection. In this article, we will talk about:
npm install heapdump
For your Node.js application going to deploy to Azure App Service, we can define it in your package.json "dependencies" section like the following:
var heapdump = require('heapdump')
heapdump.writeSnapshot()
After you deployed your Node.js Application with heapdump installed and loaded, you can startup and keep your Linux App Service run as normal.
When you need to investigate a memory leak issue, we can take multiple heap snapshots in a sequence of time.
# ps aux | grep node
# kill -SIGUSR2 <node_pid>
Snapshots are written to your node application working directory (/home/site/wwwroot) with a timestamp like heapdump-xxxxxxx.xxxxxx.heapsnapshot.
var express = require('express');
var router = express.Router();
const numeral = require('numeral');
var garbage = ['g1'];
function generategarbage() {
for (let i = 0; i < 10000; i++) {
garbage.push("tVXn8LhhAn8wjjbD6wPnsb8UAKAVJHqCVXhu6ochaMI9sMnjWHw1WqMvwKyUvXzdCcU3A4dPuaWKLnI3ZTFTUgQ1BY33yGSWxGRA0RfYmqgtPkZxqp2ErjG0Uzle2npbmFWIsQeP8XTLPL3phqusfisswxvZafAx6XsKmNrPeVjSPTgoFeoe9tOUlriRxRtTOSXgXOOcGO9aWlkrA2pFI9d71R9bgn3xlpgJ7zKUMyi4lHPY2MCQxKGFAyk7DiW3sklLn5ePLEYQI0Q8Cd345lXknjsITfLBbe0UFMlzXdvdPerZpCdtnKdo4opZFy7xQOnjxQICmgxRs5J45PiKMPxOCqb5s1OBhPid2gT2pQibMWpUL6W7xGMNt4oWXpnNhQASEAnIEOt6aKhLncnrHM12pyUAdhqVXzNVmh5q7hNmFbeOL6iEoUrewuKWOTIgNdWK13n98y5kIQ69Gsqa12GKtq2pQGaP4kRkkNdc4GkAU9X9QftfAkui31WjNoaiXFFjQOgwcy70ukPQB5m180HBQr5OiyGhCG9JSmP1wkFpZNEhUsCN7XlxWWYVkh3fdcPauzS2vZtVyBlC9qupcLzOSzQVcMaHkAHDB0oHVMoVSXAnZlTB1i1TRi01grHQrNuUEWSEW7mpqdq3cVzpoU0eYNs7kydb9qaIx2UhSjzLy3zjqcw6IC7e0nMfSAce2relcYORjiIjZcwh73fYDckEVaxzhn0L5CftTXyZaZX9OmsL9gJOtBxPW5GqQjgqlCoPhh4kh3eLC9W3ZN1cF69EXMAkh6Z6YN0rjDgf5eSWxazqFCL7fWWRAlJoZadFhgPlXa6AiGtP18SeBuvnPPgsIEdowhblHBSReVrcJJBeGIIPJpebS6MF89q8y3np05jzmkPJzx4bABhaoc9tyjxJIRLm67HDiqqJkCEx6rrlG3NtgdQkmwDFItkRHHyyppMVphiL9oXRvSdQUX2EQe03wQ8lSXzANiNxSUeq");
}
}
/* GET home page. */
router.get('/', function(req, res, next) {
generategarbage();
res.status(200).send(`Array appended.`);
});
module.exports = router;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.