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

[Feat] add example to split logic across VUs #1179

Merged
merged 17 commits into from
May 17, 2023
Merged

Conversation

MattDodsonEnglish
Copy link
Contributor

The idea is to provide a quick set of examples to solve a common question.

@github-actions
Copy link
Contributor

There's a version of the docs published here:

https://mdr-ci.staging.k6.io/docs/refs/pull/1179/merge

It will be deleted automatically in 30 days.

Copy link
Collaborator

@ppcano ppcano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I shared a quick high-level review.

}
```

### Tip: reduce scenario boilerplate with `new`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For simplicity and less info overhead, I'd consider removing this section with the Tip.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think this will probably be better off in the scenario docs or at least to be collapsed by default.

Also related to grafana/k6#974

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, now I see that this section distorts the docs purpose: show ways to split logic.

It's also more about general JavaScript practices, and I realized that the docs always trust that the reader can write tests according to their preferred JavaScript techniques. This is definitely a fair assumption, but, given that many k6 users don't otherwise use JavaScript in their daily operations, perhaps it'd be nice to have a blog post showing ways to use es6 tricks to refactor test scripts.



To view granular results for a specific scenario, you can filter results by the built in scenario [tag](/using-k6/tags-and-groups).
For example, this command uses `jq` to filter only data points for the scenario with the name "news".
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The jq instruction seems out of context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think either delete it entirely or move it to the end of the scenarios section.


For a more sophisticated example of randomizing, read this [forum post](https://community.k6.io/t/how-to-distribute-vus-across-different-scenarios-with-k6/49/17).

## Inspect results by behavior
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section could include a little more explanations. For example:

  • Mention that when splitting across scenarios, the Scenario assign automatically the scenario tag to built-in metrics.
  • Provide or point an alternative for the other options/examples.



One way to distribute traffic is to use scenarios to schedule different workloads for different functions.
1. Define multiple scenarios in your `options.scenarios` object.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will probably nto call it an object but will link to the configuraiton docs

}
```

### Tip: reduce scenario boilerplate with `new`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think this will probably be better off in the scenario docs or at least to be collapsed by default.

Also related to grafana/k6#974

Comment on lines 103 to 104
contactWorkload,
newsWorkload,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would guess most people will find this syntax confusing, so using "contact": contactWorkload is likely better idea.

Also you don't really need a constructor and using new to be honest - you can just have a function (which you do).

Copy link
Contributor Author

@MattDodsonEnglish MattDodsonEnglish May 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't really need a constructor and using new to be honest - you can just have a function (which you do)

I'm going to remove this section, as I commented https://github.com/grafana/k6-docs/pull/1179/files#r1196400374 ,

But as an aside, my understanding is that new is never necessary, but it helps make behavior more explicit. That's how I understand this page, https://javascript.info/constructor-new .

And I've seen new used in a few modern JS libraries so I assumed it was considered good practice.

@MattDodsonEnglish MattDodsonEnglish requested a review from ppcano May 17, 2023 13:12
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

Successfully merging this pull request may close these issues.

Doc needed: how to split logic across VUs
3 participants