0

i testing traffic on my node app in localhost using http.get(). i generate 10000 request on every 5 seconds.

the problem is when i run command npm start and after 20 to 30 seconds server crashed and with following error

events.js:136
      throw er; // Unhandled 'error' event
      ^

Error: connect EADDRNOTAVAIL localhost:8000 - Local (localhost:0)
    at Object._errnoException (util.js:999:13)
    at _exceptionWithHostPort (util.js:1020:20)
    at internalConnect (net.js:987:16)
    at net.js:1087:9
    at process._tickCallback (internal/process/next_tick.js:150:11)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! app@1.0.0 start: `node ./bin/run`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the app@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/kd/.npm/_logs/2018-03-28T08_32_26_105Z-debug.log

i using 16.04.1-Ubuntu

here is my app.js

var rob = require('./test/rob.js');
for (var i = 0; i < 10000; i++) {
    rob.init();
}

here is rob.js

var http = require('http');
module.exports = {
    init : function(){
        var pages = [
            'dashboard',
            'home',
            'login',
            'contact',
            'support',
            'about'
        ];
        setInterval(function(){
            try{
                var pg =  pages[Math.round(Math.random() * 5)];
                http.get('http://localhost:8000/' + pg,
                    res => {
                        console.log('RES =>','SUCCSESS');
                    },
                    err => {
                        console.log('ERROR','ERROR');
                    });
            }catch(err){
                console.log('ER','ERR');
            }
        },5000);
    }
}

here is run.js

var http = require('http');
var app = require('../app');

/* Create Server */
var port = 8000;
var host = '0.0.0.0';
var server = http.createServer(app);
io = module.exports = require('socket.io').listen(server, {
    pingTimeout: 7000,
    pingInterval: 10000
});
io.set("transports", ["xhr-polling","websocket","polling"]);

server.listen(port,host,function(){
    log('server is running on ' + host +':'+port);
});

how to fix this problem ?

there are any other way to check traffic ?

Kaushik Makwana
  • 2,422
  • 9
  • 31
  • 50

0 Answers0