简体   繁体   English

来自 Chrome 浏览器的 GET 请求阻止 API 在 NODEJS 中接收更多请求

[英]GET requests from Chrome browser are blocking the API to receive further requests in NODEJS

I have an API "/one" written in Nodejs (version: 12.19.1) which takes 10 seconds to send a response.我有一个用Nodejs(版本:12.19.1)编写的API“/one”,发送响应需要10秒。 request Type: GET请求类型:GET

When I hit the API with Jmeter with 10 threads in one second the API is able to process all of them.当我在一秒钟内用 10 个线程点击 API 和 Jmeter 时,API 能够处理所有这些。 When I made two requests from Postman the API is able to process them both.当我从 Postman 发出两个请求时,API 能够同时处理它们。

But When I am trying to make two requests from the Chrome Browser.但是当我试图从 Chrome 浏览器发出两个请求时。 The second request is getting blocked for 10 seconds and sending the response after 20 seconds.第二个请求被阻止 10 秒并在 20 秒后发送响应。

I am not able to figure it out why it is happening only in case of Chrome Browser.我无法弄清楚为什么它仅在 Chrome 浏览器的情况下才会发生。

I know it is not blocking the event loop because I am able to access the other API '/two' without any issue.我知道它没有阻塞事件循环,因为我可以毫无问题地访问另一个 API '/two'。

Here are the APIs - The full code is here https://github.com/vnanikalyan/nodeapilimits这是 API - 完整的代码在这里https://github.com/vnanikalyan/nodeapilimits

server.js服务器.js

const express = require("express")
const app = express()
const fetch = require("node-fetch")
let cnt = 0;
app.get("/one", async (req, res) => {  
  console.log('Request received! - ', ++cnt);
  const result = await fetch("http://localhost:5000/slowrequest")
  const resJson = await result.json()
  res.json(resJson);
})
app.get("/two", (req, res) => {
  res.send("I am unblocked now")
})
app.listen(4000, () => console.log("listening on port 4000"))

slowserver.js慢服务器.js

const express = require("express")
const app = express()

let cnt = 0;

app.get("/slowrequest", (req, res) => {
  console.log('In slow server - ', ++cnt);
  setTimeout(() => res.json({ message: "sry i was late" }), 10000)
})

app.listen(5000, () => console.log("listening on port 5000"))

delay is for Stalled延迟用于停滞

在此处输入图像描述

Stalled/Blocking Time the request spent waiting before it could be sent. Stalled/Blocking 请求在发送前等待的时间。 This time is inclusive of any time spent in proxy negotiation.该时间包括在代理协商中花费的任何时间。 Additionally, this time will include when the browser is waiting for an already established connection to become available for re-use, obeying Chrome's maximum six TCP connection per origin rule此外,此时间将包括浏览器等待已建立的连接可供重新使用的时间,遵守 Chrome 的每个源规则最多六个 TCP 连接

if you send request with Ctrl + F5 not reload this page button to access to a same domains,your problem solved如果您使用Ctrl + F5发送请求而不是reload this page button以访问相同的域,您的问题解决了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM