ECONNRESET in Express.js (Node.js) with multiple requests

前端 未结 1 1659
隐瞒了意图╮
隐瞒了意图╮ 2021-01-06 07:22

Given a standard Express.js setup

const express = require(\'express\');
const app = express();
const router = express.Router();

router.get(\'/test/:id\', (r         


        
相关标签:
1条回答
  • 2021-01-06 07:29

    One of the reasons you see this is because you make the calls in "parallel" . You do start the calls one after the other , but the loops will end probably before the first results returned from the server. The loop continues until the end , making the call stack filled with 1000 async requests to the server .

    Your'e are hitting hardware/software limits and nothing is wrong with the code. if you did want to build a server which can handle 1k (and much more) requests concurrently I would take a look into the "cluster" module of node .

    Please notice that when doing network job between server , it's acceptable to use a concurrency limit . (for example: up to 4 requests concurrently)

    but you can always scale your server beyond one machine and handle much more traffic .

    0 讨论(0)
提交回复
热议问题