node.js - nodejs web server and simultaneous file append -


i've read nodejs event-loop, don't understand is:

  • i've created simple http-server logs whole request post-data file .
  • i used apache-ab flood 700 kb file for-each request .

i imagined each request write chunks after each other each tick in event-loop, found full post data written after each request , don't know why , , cannot understand .


i'm using this

stream = require('fs').createwritestream('path/to/log.file', {flags: 'a'}) log = function(data){    return stream.write(data) }  require('http').createserver(function(req, res) {     // or req.pipe(stream)    req.on('data', function(chunk){      log(chunk.tostring() + "\r\n")    })     req.on('end', function(){       res.end("ok")    })  }).listen(8000) 

sorry bad english :)

i edited code output chunk size , use identifiable word 'squirrel' search in log file. sent image file using curl instead of apache ab, because not have setup.

if @ output of http in terminal running it, see chunk size each chunk processed, in case 65536 (as alluded in comments should see). in text search, see word squirrel 1 time each chunk processed.

there nothing wrong code, making these changes allow see expecting see.

stream = require('fs').createwritestream('./logfile.txt', {flags: 'a'}); log = function(data){    return stream.write(data); };  require('http').createserver(function(req, res) {     // or req.pipe(stream)    req.on('data', function(chunk){      log(chunk.tostring() + "squirrel ");      console.log(chunk.length);    })     req.on('end', function(){       res.end("ok");    })  }).listen(8000) 

curl --data-binary "@imag0152.jpg" http://localhost:8000


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -