Skip to content

Instantly share code, notes, and snippets.

@Eomm
Created August 19, 2020 12:03
Show Gist options
  • Save Eomm/6fb82fd223704959985b3ab07320a30c to your computer and use it in GitHub Desktop.
Save Eomm/6fb82fd223704959985b3ab07320a30c to your computer and use it in GitHub Desktop.
Check when your server goes out of memory
/**
* node --max-old-space-size=4048 --initial-old-space-size=4048 --max-heap-size=4048 stress-memory
* x64
* rss 3.39 GB
* heapTotal 3.74 GB
* heapUsed 3.73 GB
*/
const os = require('os')
console.log(os.arch())
Array(1e8).fill('1')
const mem = process.memoryUsage()
console.log('rss ' + human(mem.rss))
console.log('heapTotal ' + human(mem.heapTotal))
console.log('heapUsed ' + human(mem.heapUsed))
function human (size) {
var i = Math.floor(Math.log(size) / Math.log(1024))
return (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment