Skip to content

Instantly share code, notes, and snippets.

@jessetane
Last active December 10, 2015 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jessetane/4450228 to your computer and use it in GitHub Desktop.
Save jessetane/4450228 to your computer and use it in GitHub Desktop.
excessive memory usage on large incoming http request?
// run this locally: node <gist.js>
// then POST a big (>300mb) file to it with cURL:
// curl -X POST -d @"/path/to/big.file" localhost:8080
var http = require('http')
var PORT = 8080
var peak = 0
// watch mem usage
setInterval(function () {
peak = Math.max(peak, process.memoryUsage().rss)
console.log('memory usage ' + (peak / 1000000).toFixed(2) + 'mb')
}, 500)
// http server
http.createServer(function (req, res) {
// create a destination
var dest = http.request({
port: 8080,
method: 'POST',
hostname: 'remote.server.com' // a running instance of https://gist.github.com/4449811
}, function (resp) {
resp.pipe(process.stdout)
})
dest.on('finish', function () {
console.log('request ended')
res.end('all done\n')
})
// pipe incoming data to dest
req.pipe(dest)
}).listen(PORT, function () {
console.log('server listening on ' + PORT)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment