I'm trying to make some API calls in parallel using Promise.all
in node.js
. I'm getting the correct output as a result. I want to check if my API calls are actually being made in parallel and not in series. Where can I find the order (or rather visualise) in which calls are being made and the response is being received? Are there any tools (VSCode extensions) available to check the same?
Asked
Active
Viewed 24 times
0

VLAZ
- 26,331
- 9
- 49
- 67

Ayush Jain
- 316
- 4
- 11
-
Time the requests. If each request takes 0.1 seconds and 10 requests take 1 second then they are made in series. However if 10 requests take around 0.25 seconds then they're probably made in parallel. Do note though that bits going out of your modem/router to the internet and coming back from the internet to your ethernet/wifi card are sent in series, not parallel. So at some point the messages are queued in series at the hardware level. The only thing parallel requests improve is time wasted waiting in software – slebetman Sep 21 '22 at 07:47
-
This may be helpful [Is Node.js native Promise.all processing in parallel or sequentially?](https://stackoverflow.com/a/30823708/12615886) – Mordor1110 Sep 21 '22 at 07:50
1 Answers
1
Node doesn't include the equivalent of the "Network" tab in dev tools. Some options are
- Use a debug proxy like mitmproxy
- Use
nock
to record requests - Instrument your request function
Debug proxy (mitmproxy)
mitmproxy, Burp Suite, Fiddler, Charles will probably suit you more on the visualisation front.
In node, you might need to configure a http agent to proxy requests depending on what http client library is in use.
Some libraries will respect HTTP_PROXY
/HTTPS_PROXY
set in the environments
nock
Nock has a recorder mode which can print or store all requests/responses that use node http
(fetch
is not supported yet)
nock.recorder.rec({ output_objects: true, dont_print: true, })
To get the captured array of requests/responses:
const requests = nock.recorder.play()
Code Instrumentation
You could also add the timing data to your request handler
async function get(path) {
start = Date.now()
const response = await request(path)
end = Date.now()
return {
start,
response
end,
}
}
For investigation on the other side of the Promise.all
.

Matt
- 68,711
- 7
- 155
- 158