got icon indicating copy to clipboard operation
got copied to clipboard

timeout and timings are not working?

Open ryohetoy opened this issue 3 years ago β€’ 3 comments

Describe the bug

  • Node.js version: v16.13.1
  • OS & version: macOS 12.6

When I send many get requests, timeout and response.timings are not working as expected.

Actual behavior

I send around 500 get requests to different urls concurrently by using promise, timings.dns of each request is increasing.

Expected behavior

timings.dns should show actual time.

Code to reproduce

const got = require("got");

console.time('total');
const urlList = [
  "https://devblogs.microsoft.com/landingpage/", 
  "https://it.impress.co.jp/list/feed/rss", 
  "https://uxmilk.jp/feed",
  ... more 500 urls
];
const pList = urlList.map(function(url) {
    return got(url, {timeout: {request: 60000, }, retry: {limit: 0}}).then((result) => {
        const phases = result.timings.phases;
        const paheseResult = [url, phases.wait, phases.dns, phases.tcp, phases.tls, phases.request, phases.firstByte, phases.download, phases.total];
        console.log(paheseResult.join(","));
    }).catch((e) => {
        return null;
    });
});

Promise.all(pList).then((result) => {
    console.timeEnd('total');
}).catch((e) => {
    console.log('error: ' + e);
});

This is the graph which I made from each url's response.timings. dns is increasing, so if I set timeout to 30s, most of requests fails.

γ‚Ήγ‚―γƒͺγƒΌγƒ³γ‚·γƒ§γƒƒγƒˆ 2022-11-07 21 31 40

Sorry if this is my misunderstanding because I'm new to node, thanks in advance!

Checklist

  • [x] I have read the documentation.
  • [x] I have tried my code with the latest version of Node.js and Got.

ryohetoy avatar Nov 07 '22 12:11 ryohetoy

It's unlikely that the timings are wrong. Can you try https://github.com/sindresorhus/got/blob/main/documentation/2-options.md#dnscache

szmarczak avatar Nov 07 '22 23:11 szmarczak

@szmarczak Thank you for reply, but it's not changed. I tried this. got(url, {timeout: {request: 60000, dnsCache: true}, retry: {limit: 0}})

It looks like some connections are waiting for other connections to finish. Is there any connection limit setting?

ryohetoy avatar Nov 08 '22 05:11 ryohetoy

You could try passing a custom agent. Also please try HTTP/2

szmarczak avatar Nov 08 '22 10:11 szmarczak