-
Notifications
You must be signed in to change notification settings - Fork 42
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
Support CPU and Network throttling #887
Comments
I support this feature, and it would be great if we could prioritise this somehow 👍🏼 One strength of using lab data is the ability to run tests in a controlled environment. Currently, we can do this in k6 browser by setting the screen size or removing certain Chrome arguments, but not the ability to configure network throttling (e.g. from 5g to 4g). I want to be able to change my network connection to see how this impacts my web vital metrics. |
Example on how Playwright can do it: microsoft/playwright#6038 (comment) |
We should look at existing tools and see how they've implemented the same feature. Playwright doesn't seem to support it as a dedicated API yet, but puppeteer does have dedicated APIs for both CPU and network. It's probably worth looking through any discussions in both tools to see whether there's any discussions around how to improve these APIs -- i'm most curious why playwright hasn't implemented it, there could be a valid reason for it. |
For the network throttling side: Here's some info why Playwright lacks the feature: microsoft/playwright#8622 (comment):
They also have a Route API that enables users to throttle requests. See: microsoft/playwright#19173 (comment). And they allow users to send CDP messages: microsoft/playwright#6038 (comment). |
We have explored this feature and we're hoping to start work on it imminently. We see value in implementing two new APIs to throttle the CPU and another to throttle the network. Many end users of websites are going to be on slower devices under poor network conditions, and to be able to test those conditions in a lab setting we need succinct APIs. The idea is to (essentially) wrap the CDP APIs in order to throttle CPU and network with a javascript API on the The proposed API is as follows: export interface Page{
...
throttleCPU(profile: CPUProfile)
throttleNetwork(profile: NetworkProfile)
}
export interface CPUProfile {
// rate as a slowdown factor (1 is no throttle, 2 is 2x slowdown, etc).
rate: number;
}
export interface NetworkProfile {
// Minimum latency from request sent to response headers received (ms).
latency: number;
// Maximal aggregated download throughput (bytes/sec). -1 disables download throttling.
download: number;
// Maximal aggregated upload throughput (bytes/sec). -1 disables upload throttling.
upload: number;
} We will provide useful network profiles such as The CDP API lacks the support of throttling websocket connections (https://crbug.com/563644). We're unlikely to resolve this soon through our own implementation. We welcome feedback on the decision we have made and comments to help fine tune the feature. |
Closing this as completed. cc: @grafana/k6-browser |
Feature Description
CPU and network throttling are useful in order to emulate specific network conditions, for example in order to emulate a mobile connection speed when actually running in a faster connection.
See Lighthouse project documentation on throttling: https://github.com/GoogleChrome/lighthouse/blob/main/docs/throttling.md
See CDP APIs in order to throttle CPU and network.
Suggested Solution (optional)
No response
Already existing or connected issues / PRs (optional)
No response
Tasks
The text was updated successfully, but these errors were encountered: