This page goes over some common best practices for scripting ## [[Making load testing scripts more realistic|Make your script more realistic]] ## Exclude Third Party Content [k6](https://k6.io/docs/cloud/analyzing-results/performance-insights/#third-party-content) Review the requests made by your script for resources that are hosted by domains you may not own. Common examples of these resources are social media scripts, fonts, analytics tracking scripts, ads, and assets hosted by a content delivery network (CDN). Common examples - google-analytics.com - Facebook social media requests - ads - analytics - fonts Running a load test including third-party resources may be in violation of the terms of service of third-party providers, and they may throttle your requests, skewing response times. You may also incur increased costs from your CDN as a result of load testing their servers. #### Recommendations - In your script, remove requests for resources hosted on the domains listed above. You may safely ignore this recommendation for domains that you own and if you are intentionally testing your CDN. ### Too Many URLs %%![Current implementation of this alert](images/performance-insights/perf_alert-too_many_urls.png) [Docs](https://k6.io/docs/cloud/analyzing-results/performance-insights/#too-many-urls) [Sample run triggering this alert](https://app.k6.io/runs/979628) %% Redirects, dynamic parameters (such as those for token, resources, or session IDs), [third-party content](https://k6.io/docs/cloud/analyzing-results/performance-insights/#third-party-content), and programmatically creating requests with different [name tags](https://k6.io/docs/using-k6/http-requests#url-grouping) may cause a high number of unique URLs to be generated. Requesting too many URLs may make it more difficult to aggregate, display, and analyze your test results. #### Recommendations - Use [URL grouping](https://k6.io/docs/using-k6/http-requests/#url-grouping) to collect similar requests. - Consider removing requests to third-party domains that you do not control. - Avoid adding dynamically generated `name` tags. If you want to track what a certain user is doing, use `console.log()` in your script to output information to the log instead. ### Too Many Groups %%![Current implementation of this alert](images/performance-insights/perf_alert-too_many_groups.png) [Docs](https://k6.io/docs/cloud/analyzing-results/performance-insights/#too-many-groups) [Sample test run triggering this alert](https://app.k6.io/runs/979604)%% Having many request groups may unnecessarily complicate your code and make your tests more difficult to interpret and analyze. #### Recommendations Reconsider your usage of request groups. Instead: - Use [URL grouping](https://k6.io/docs/using-k6/http-requests/#url-grouping) for dynamic URLs. - [Add a name tag](https://k6.io/docs/using-k6/http-requests/#http-request-tags) to your requests. - Create functions to better organize your script or create [local JavaScript modules](https://k6.io/docs/using-k6/modules#local-filesystem-modules) for a more modular approach. - Use [scenarios](https://k6.io/docs/using-k6/scenarios) to model advanced user patterns. ### Too Many Metrics %%![Current implementation of this alert](images/performance-insights/perf_alert-too_many_metrics.png) [Docs](https://k6.io/docs/cloud/analyzing-results/performance-insights/#too-many-metrics) [Sample run triggering this alert](https://app.k6.io/runs/979918) %% Using too many [custom metrics](https://k6.io/docs/javascript-api/k6-metrics), especially for scripts with a high number of requests, may significantly increase the CPU or memory utilization of your load generators and make your results less accurate. They can also make it more difficult to aggregate, display, and analyze your test results. #### Recommendations - Review the [built-in metrics](https://k6.io/docs/using-k6/metrics) and see if any of them already meet your needs. - Avoid dynamically generating custom metrics using loops and counter variables. - Use [URL grouping](https://k6.io/docs/using-k6/http-requests/#url-grouping) to aggregate metrics as well as requests.