Skip to content

Instantly share code, notes, and snippets.

@gamlerhart
Created July 24, 2016 14:50
Show Gist options
  • Save gamlerhart/5582bce62cfea2ea4aad57956df2a7b5 to your computer and use it in GitHub Desktop.
Save gamlerhart/5582bce62cfea2ea4aad57956df2a7b5 to your computer and use it in GitHub Desktop.
bad-container-example
FROM node
RUN mkdir /demo
COPY io-wasting.js /demo/
CMD ["/usr/local/bin/node", "/demo/io-wasting.js"]
// Hacked together example container. Goes off and wastes tons of IO cycles.
var fs = require('fs');
someObscureLibrary();
function someObscureLibrary() {
var file = '/tmp/io-file-' + Math.random();
var buffer = 'Hello Node.js: ' + Math.random();
fs.open(file, 'a+', function (err, fd) {
if (err) {
console.error("Failed to write: " + file + " " + err);
closeDelete(fd, file);
} else {
fs.write(fd, buffer, 0, buffer.length, function (err) {
if (err) {
console.error("Failed to write: " + file + " " + err);
closeDelete(fd, file);
} else {
fs.fsync(fd, function (err) {
if (err) {
console.error("Failed to write: " + file + " " + err);
}
closeDelete(fd, file);
})
}
})
}
someObscureLibrary();
});
}
function closeDelete(fd, file) {
fs.close(fd, function () {
fs.unlink(file, function () {
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment