We are trying to serve as much requests as possible, and write one file per request. With small payload works fine, but on high payload scenarios while the synchronous version still working fine, the asynchronous version (fs.writeFile) hangs. Node stops serving requests and leave most of the files with 0-size (most of them neither get created).
There is no error in v0.6.6
In v.0.4.7 we got:
{ stack: [Getter/Setter],
arguments: undefined,
type: undefined,
message: 'EMFILE, Too many open files \'aw_1031\'',
errno: 24,
code: 'EMFILE',
path: 'aw_1031' }
Same behaviour in Ubuntu(VM) and Mac Osx.
This is the example script we are currently running with:
ab -n 30000 -c 500 http://HOST:8000/
filetest.js
var http = require('http');
var fs = require('fs');
var util = require ('util');
var i=0;
function writeALot(req, res){
fs.writeFile("filetest"+i, "Just a try: "+i,
function(err){
if(err) console.log(util.inspect(err));
});
i++;
res.writeHead(200);
res.end();
}
http.createServer(writeALot).listen(8000);
How can we manage the max number of concurrent fd? Any advice?
Thanks in advance.
Well the number of file descriptors are limited(http connections are file descriptors too). Here with every connection, one file would be written, which will be 1000 file descriptors at 500 concurrency. And probably your
ulimit -nis 1024. You can increase the limit actually, which I’ve seen people doing for production high concurrency servers. Beside that you can make a queue with a concurrency less than 500. I did this in one of my apps usingasyncmodule. Putting a cap on every request I make. This will hold the file descriptors that I’m making, but not the incoming connections.Then later on, if I want to make a request or open a file,
There is also this way: http://nodebits.org/distilled-patterns
But the example of batch processing is not nice as using a queue.