questions about how many requests Nodejs can accept at the same time?
Recently learning node, read a lot of tutorials, all in praise of Nodejs asynchronous I/O, asynchronous I/O is characterized by each request received, using asynchronous calls to process the request, without waiting for results, you can continue to run other operations, that is, can continue to accept the request. So what does it take? So, I wrote a program to test, the code is as follows:
Server.js5 Seconds to process a request, 5 seconds after settimeout set responseVarhttp= Require("http");VarN= 0;http.Createserver(function (Req,Res) {N++; Settimeout (function () { Console. ( "Accept" + n + "request." Res. "test" }, 5000); listen3000
Client.jsSend a requestExports.Send= function () { Varhttp= Require(' HTTP '); VarOptions= {Host: ' localhost ',Port: ' 3000 ',Path: ‘/‘,Method: ' GET ', }; VarReq=http.Request(Options, function(Res){Exports.Counter+= 1;Res.Setencoding(' UTF8 ');Res.On(' Data ', function (C) { Console.log (c); });Res.On(' End ', function() { Exports.+= 1; console< Span class= "pun". log ( +< Span class= "PLN" > Exports. }); }); Req.}; exports.= 0
Attack.jsMake about 50,000 requests in 1 secondsVarClient= Require('./client ');VarD= 1000, T =date.while (date. Now () - T < D) { client send (); }console. ( ' end.
Run Server.js
> node server.js
Run the Atack.js initiation request (the test can issue approximately 50,000 requests per second):
> node atack.js
Results:
Accept 5request.Accept 5request.Accept 5request.Accept 5request.Accept 5request.Accept 10request.Accept 10request.Accept 10request.Accept 10request.accept 10request.accept 15request.accept 15request.accept 15request.accept 15request.accept 15request.//omit after n
As a result, you know that Server.js only accepted 5 requests in 5 seconds.
One limitation of node. JS's socket module is that it seems that the same IP cannot connect more than 5 sockets.
Give it a tryrequire(‘http‘).globalAgent.maxSockets = Infinity
Questions about how many requests Nodejs can accept at the same time? zzz