Created
July 24, 2016 14:50
-
-
Save gamlerhart/5582bce62cfea2ea4aad57956df2a7b5 to your computer and use it in GitHub Desktop.
bad-container-example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM node | |
RUN mkdir /demo | |
COPY io-wasting.js /demo/ | |
CMD ["/usr/local/bin/node", "/demo/io-wasting.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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