Skip to content

Instantly share code, notes, and snippets.

@sillyslux
Created February 16, 2018 13:00
Show Gist options
  • Save sillyslux/e79929d5209f81797fb1f57a9c166e4b to your computer and use it in GitHub Desktop.
Save sillyslux/e79929d5209f81797fb1f57a9c166e4b to your computer and use it in GitHub Desktop.
multiple threads from node stress testing the cpu
const shell = require('shelljs');
const nexec = cmd => new Promise((resolve, reject) => {
shell.exec(cmd, (code, stdout, stderr) => {
if(stderr) reject(stderr);
if(code) reject(new Error('exit code'));
if(stdout) resolve(stdout);
reject(new Error('unexpected behaviour'));
})
});
Promise.all([
nexec('stress --cpu 1 --timeout 10; echo "stress 10";'),
nexec('stress --cpu 1 --timeout 20; echo "stress 20";'),
nexec('stress --cpu 1 --timeout 30; echo "stress 30";'),
nexec('stress --cpu 1 --timeout 40; echo "stress 40";'),
nexec('stress --cpu 1 --timeout 50; echo "stress 50";'),
nexec('stress --cpu 1 --timeout 60; echo "stress 60";')
])
.then(console.log);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment