Created
April 23, 2014 10:05
-
-
Save pierreinglebert/11209464 to your computer and use it in GitHub Desktop.
Stress a bit sharp to show memory leak
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
var sharp = require('sharp'); | |
var async = require("async"); | |
sharp.cache(0); | |
var dlImage = function(done) { | |
var http = require('http'); | |
var fs = require('fs'); | |
if(!fs.existsSync("fixture.jpg")) { | |
var file = fs.createWriteStream("fixture.jpg"); | |
var request = http.get("http://anthropocenejournal.files.wordpress.com/2012/12/nasa-high-res-earth-at-night-dnb_land_ocean_ice-2012-13500x6750.jpg", function(response) { | |
response.pipe(file); | |
file.on('finish', function() { | |
file.close(done); | |
}); | |
}); | |
} else { | |
done(); | |
} | |
}; | |
var sizes = []; | |
for (var i = 200; i < 1000; i++) { | |
sizes.push(i); | |
}; | |
var resize = function(done) { | |
async.eachLimit(sizes, 5, | |
function(item, next) { | |
sharp("fixture.jpg").resize(item).sharpen().webp(function(err, buffer) { | |
next(err); | |
}); | |
}, | |
function(err){ | |
done(err); | |
} | |
); | |
}; | |
async.series([ | |
dlImage, | |
resize | |
], function(err) { | |
console.log("done"); | |
if(err) | |
console.log(err); | |
}); | |
setInterval(function() { | |
console.log(process.memoryUsage()); | |
}, 1000); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment