sitespeedio / throttle

Throttle your network connection [Linux/Mac OS X]
MIT License
336 stars 26 forks source link

Doesn't seem to throttle on some machines. #87

Open jeffpreussner opened 5 months ago

jeffpreussner commented 5 months ago

Throttle works on some machines and not others. Could this be due to IPv4 vs IPv6 connection issue? Running the command from documentation throttle --profile 3gslow and running a speed test I can see my connection speed is slowed way down but when a colleague runs the same command they do not get the same result. Are there system or network level settings that can break this functionality?

soulgalore commented 5 months ago

Hi @jeffpreussner yes maybe. Can you share how you and your colleague test? I can try to make a fix, but I need help to verify that it works on both Linux/Mac with both ipv4 and ipv6?

jeffpreussner commented 5 months ago

@soulgalore I wrote a node script that starts throttle then runs lighthouse, I have confirmed they have an IPv6 connection and I am on a IPv4 connection. The same results are testable using the CLI command. What other information can i provide for you?

Here is my code:

await throttle.start(throttleOptions[opts.platform] ? throttleOptions[opts.platform] : throttleOptions.mobile);
try {
let audits = [
['Run #', 'Performance', 'Accessibility', 'Best Practices', 'SEO', '']];
let perf: number[] = [];
let seo: number[] = [];
let a11y: number[] = [];
let bprac: number[] = [];
for (let test = 0; test < Number(opts.runs); test++) {
        // Do your thing and then stop;
        console.log("Throttling computer connection...");
        const chrome = await chromeLauncher.launch({ chromeFlags: ['--headless'] });
        const flags = { logLevel: 'info', output: 'html', port: chrome.port };
        console.log(`Starting lighthouse audit ${test + 1}`);
        console.log(`URL: ${urlToAudit}`);
        console.log(`CPU Throttle Multiplier: ${multiplier}x`);
        const runnerResult = await lighthouse(urlToAudit, flags, { extends: 'lighthouse:default', settings: { throttlingMethod: "devtools", throttling: { cpuSlowdownMultiplier: multiplier, requestLatencyMs: 0, downloadThroughputKbps: 0, uploadThroughputKbps: 0 } } });

        // `.report` is the HTML report as a string
        const reportHtml = runnerResult.report;
        const dir = `./audits/${slugify(new Date().toLocaleDateString())}`;
        const fileName = `${slugify(urlToAudit)}-run${test + 1}.html`;
        const filePath = path.join(dir, fileName);

        if (!fs.existsSync(dir)) {
          fs.mkdirSync(dir, { recursive: true });
        }

        fs.writeFileSync(filePath, reportHtml);
        if (opts.open) {
          open(`file://${path.resolve(process.cwd(), filePath)}`)
        }
        console.log(`Report for run ${test + 1} is ready: file://${path.resolve(process.cwd(), filePath)}`);

        perf = [...perf, Math.round(runnerResult.lhr.categories.performance.score * 100)];
        a11y = [...a11y, Math.round(runnerResult.lhr.categories.accessibility.score * 100)];
        bprac = [...bprac, Math.round(runnerResult.lhr.categories["best-practices"].score * 100)];
        seo = [...seo, runnerResult.lhr.categories.seo.score * 100];

        audits = [...audits,
        [
          test + 1,
          String(Math.round(runnerResult.lhr.categories.performance.score * 100)),
          String(Math.round(runnerResult.lhr.categories.accessibility.score * 100)),
          String(Math.round(runnerResult.lhr.categories["best-practices"].score * 100)),
          String(Math.round(runnerResult.lhr.categories.seo.score * 100)),
          filePath
        ]
        ]

        await chrome.kill();
        await throttle.stop();
        console.log("stopped");
      }
      console.log(table([
        ...audits,
        ["average", calculateAverage(perf), calculateAverage(a11y), calculateAverage(bprac), calculateAverage(seo), ""]]));

    } catch (err) {
      console.log(err);
      await throttle.stop();
      console.log("stopped");
    }
soulgalore commented 5 months ago

Ok. Do you run on Mac or Linux? I added branch yesterday with a hack for ipv6 but I haven't able to test it, can your colleague do that? I tried to get my Mac using ipv6 but I could get it to work. The branch is https://github.com/sitespeedio/throttle/tree/ipv6. If you can clone the repo and switch to that branch and test? If you cloned the repo you can start throttle with bin/index.js