Sunday 12 March 2017

port blocking for multiple user requests

I have a question that nobody seems to help with. How will this be handled in a production mode with thousands of requests at the same time?

I did a simple test case:

module.exports = {
    index: function (req, res){
        if (req.param('foo') == 'bar'){
            async.series([
                function(callback){
                    for (k=0; k <= 50000; k++){
                        console.log('did something stupid a few times');
                    }

                    callback();
                }
            ], function(){
                return res.json(null);
            });


        }else{
            return res.view('homepage', {

            });
        }

    }
};

Now if I go to http://localhost:1337/?foo=bar it will obviously wait a while before it responds. So if I now open a different session (other browser or incognito, and go to http://localhost:1337/ I am expecting a result immediately. Instead it is waiting for the other request to finish and only then it will let this request go through.

Therefore it is not asynchronous and it is a huge problem if I have as much as 2 ppl at the same time operating this app. I mean this app will have drop downs coming from databases, html files being served etc...

My question is this: how does one handle such an issue??? I hear the word "promises vs callbacks" - is this some sort of a solution to this?

I know about clustering, but that only separates the requests over the amount of cpu's, ultimately you will fix it by at most allowing 8 people at the same time without being blocked. It won;t handle 100 requests at the same time...

P.S. That test was to simplify the example, but think of someone uploading a file, a web service that goes to a different server, a point of sales payment terminal waiting for a user to input the pin, someone downloading a file from the app, etc...



via Mihai Pop

No comments:

Post a Comment