Today when I tried to implement an example of using async/sync I/O methods
in NodeJs, I faced an strange problem. When I'm trying to send requests
with ab, I get this error in Async method:
{ [Error: EMFILE, open 'sample.txt'] errno: 20, code: 'EMFILE', path:
> 'sample.txt' }
But the same functionality in Sync mode works well, without any errors.
This is my ab command for running the test: ab -n 10000 -c 1000 -vhr
http://localhost:8080/
Here is my both codes:
*Async:*
http.createServer(function (req, res) {
> fs.readFile('sample.txt', function (err, data) {
> if(err) {
> res.writeHead(500, {'Content-Type': 'text/plain'});
> res.end();
> console.log(err);
> } else {
> res.writeHead(200, {'Content-Type': 'text/plain'});
> res.end(data);
> }
> });
> }).listen(8080, '127.0.0.1');
*Sync:*
http.createServer(function (req, res) {
> var fileOutput = fs.readFileSync('sample.txt').toString();
> if(!fileOutput) {
> res.writeHead(500, {'Content-Type': 'text/plain'});
> res.end('Error in reading the file.');
> } else {
> res.writeHead(200, {'Content-Type': 'text/plain'});
> res.end(fileOutput);
> }
> }).listen(8081, '127.0.0.1');
What's the matter? Is there any problem in using Async methods?
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.