Questions about how many requests Nodejs can accept at the same time? zzz

Source: Internet
Author: User
Tags node server

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.