Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.