Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jeffpreussner opened this issue May 13, 2024 · 3 comments
Open

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

jeffpreussner opened this issue May 13, 2024 · 3 comments

Comments

@jeffpreussner
Copy link

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
Copy link
Member

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
Copy link
Author

jeffpreussner commented May 14, 2024

@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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants