Asked what to do with concurrent requests? Isn't the request asynchronous?

interview questions are asked what makes concurrent requests? Isn"t the request asynchronous? If there are too many requests, it will naturally occur concurrently. What does this mean?

Jun.10,2022

to put it simply, you can't understand

in this way.
  • single-threaded tasks are generally called serial tasks. You cannot execute the second task until the current task is finished.
  • corresponds to parallel tasks, or simply understood as concurrent tasks, which solves the bottleneck of single-threaded task execution and improves the execution speed.

asynchronism is generally aimed at the single-threaded model. due to the bottleneck caused by the long task link, the task is split and the task time is shortened , which is completed by two or more threads, but it is still a task. It generally uses some middleware, such as kafka

.

A simple example is ajax
when async=false , it is a single-thread serial task. Due to the existence of network io, the current thread will be suspended and blocked.
when async=true , the task is split. Immediately after sending the http, the thread returns and executes the next task. After requesting the return value, another thread calls callback , which backfills the result
http2 and uses a more complex multiplexing technology to improve the overall performance. For more information, please see

concurrency and asynchronism are not related concepts. If you want to initiate two asynchronous requests at the same time, they must be initiated concurrently. If you put the second in the first callback, it will be serial. If you use await in ESnext, you need to use promise.all to achieve concurrency, because await waits for the end of the first request before moving on to the next one.
is purely a personal opinion.


  1. js is single-threaded
  2. to implement concurrent requests, you need to create another thread

use

Previous: Why do too many requests overwhelm the server?

Next: How can H5+API Reference, like Yuansheng, detect WIFI signals but do not have a network?

Menu