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

Make the __VU execution control var available in the init phase #889

Closed
na-- opened this issue Jan 3, 2019 · 4 comments · Fixed by #1544
Closed

Make the __VU execution control var available in the init phase #889

na-- opened this issue Jan 3, 2019 · 4 comments · Fixed by #1544
Assignees
Labels
evaluation needed proposal needs to be validated or tested before fully implementing it in k6 ux
Milestone

Comments

@na--
Copy link
Member

na-- commented Jan 3, 2019

It could probably be useful for different things, chiefly something like this:

let vuRotated = __VU % 3;
let data = JSON.parse(`./${vuRotated}.json`)

export default function () {
    console.log(`VU #${__VU} sees the following data: ` + JSON.stringify(data));
};

If we have split different static credentials in files named as 0.json, 1.json, and 2.json, each VU will take up only a third of the memory it would have consumed if all of the data was in a single file.

The evaluation needed tag is because it's unclear if there are obstacles for implementing this, or if it can have some negative consequences.

@na-- na-- added ux evaluation needed proposal needs to be validated or tested before fully implementing it in k6 labels Jan 3, 2019
@mstoykov
Copy link
Contributor

mstoykov commented Jan 4, 2019

Problems:

  • what is the value when setup/teardown is being ran ?
  • when you run k6 archive how do you know which files should be putted inside the archive?

Both are fixable - the first one could be something like -1 (0 is actual valid value so I would prefer not to use it) , and the second can be fixed with some argument to archive that says "import this files as well" and leave it to the user to do the right thing.

@na--
Copy link
Member Author

na-- commented Jan 4, 2019

The second one is an issue even now, you can use Math.random() to open different files in the init context

@na--
Copy link
Member Author

na-- commented Aug 29, 2019

Just wanted to add a note that implementing this after #1007 would be much better. That's because currently, when VUs are ramped down and then back up again, their __VU number gets reassigned. So even if we add a __VU number in the init context, that number may become different sometime down the line. As an example:

import { sleep } from "k6";

export let options = {
    stages: [
        { target: 10, duration: "5s" },
        { target: 0, duration: "5s" },
        { target: 10, duration: "5s" },
    ],
}
export default function () {
    console.log(__VU)
    sleep(3);
}

The maximum number that will be printed with k6 v0.25.1 is somewhere around 19-20, even though we only ever have 10 VUs at max. With the code from #1007, it's going to always be 10. This is because __VU is currently re-assigned with incremental values when the VU is put back into service during the second ramp-up, whereas in the new code the VU ID is assigned once and never changed.

cuonglm added a commit that referenced this issue Jan 6, 2020
The complicated handling of context in RunOnce is not necessary. Each
of the new executors handles contexts and VUs very deliberately and
precisely. We can separate the context handling to interrupt goja
runtime and the actual running user's code.

This PR introduces two new interfaces, "InitializedVU" annd "ActiveVU".

InitializedVU is what Runner.NewVU will return, and is stored in
ExecutionState.vus buffer. Whenever a InitializedVU is pull from the
buffer, caller can call InitializedVU.Activate with VUActivationParams
argument. This will return an ActiveVU, which will actually run the
user's code.

The InitializedVU.Activate will spawn a goroutine to track the context
for interrupting script execution, and calling the callback function and
return the VU to the buffer.

Fixes #889
Fixes #1283
cuonglm added a commit that referenced this issue Jan 6, 2020
The complicated handling of context in RunOnce is not necessary. Each
of the new executors handles contexts and VUs very deliberately and
precisely. We can separate the context handling to interrupt goja
runtime and the actual running user's code.

This PR introduces two new interfaces, "InitializedVU" annd "ActiveVU".

InitializedVU is what Runner.NewVU will return, and is stored in
ExecutionState.vus buffer. Whenever a InitializedVU is pull from the
buffer, caller can call InitializedVU.Activate with VUActivationParams
argument. This will return an ActiveVU, which will actually run the
user's code.

The InitializedVU.Activate will spawn a goroutine to track the context
for interrupting script execution, and calling the callback function and
return the VU to the buffer.

Fixes #889
Fixes #1283
cuonglm added a commit that referenced this issue Jan 7, 2020
The complicated handling of context in RunOnce is not necessary. Each
of the new executors handles contexts and VUs very deliberately and
precisely. We can separate the context handling to interrupt goja
runtime and the actual running user's code.

This PR introduces two new interfaces, "InitializedVU" annd "ActiveVU".

InitializedVU is what Runner.NewVU will return, and is stored in
ExecutionState.vus buffer. Whenever a InitializedVU is pull from the
buffer, caller can call InitializedVU.Activate with VUActivationParams
argument. This will return an ActiveVU, which will actually run the
user's code.

The InitializedVU.Activate will spawn a goroutine to track the context
for interrupting script execution, and calling the callback function and
return the VU to the buffer.

Fixes #889
Fixes #1283
cuonglm added a commit that referenced this issue Jan 7, 2020
The complicated handling of context in RunOnce is not necessary. Each
of the new executors handles contexts and VUs very deliberately and
precisely. We can separate the context handling to interrupt goja
runtime and the actual running user's code.

This PR introduces two new interfaces, "InitializedVU" annd "ActiveVU".

InitializedVU is what Runner.NewVU will return, and is stored in
ExecutionState.vus buffer. Whenever a InitializedVU is pull from the
buffer, caller can call InitializedVU.Activate with VUActivationParams
argument. This will return an ActiveVU, which will actually run the
user's code.

The InitializedVU.Activate will spawn a goroutine to track the context
for interrupting script execution, and calling the callback function and
return the VU to the buffer.

Fixes #889
Fixes #1283
cuonglm added a commit that referenced this issue Jan 7, 2020
The complicated handling of context in RunOnce is not necessary. Each
of the new executors handles contexts and VUs very deliberately and
precisely. We can separate the context handling to interrupt goja
runtime and the actual running user's code.

This PR introduces two new interfaces, "InitializedVU" annd "ActiveVU".

InitializedVU is what Runner.NewVU will return, and is stored in
ExecutionState.vus buffer. Whenever a InitializedVU is pull from the
buffer, caller can call InitializedVU.Activate with VUActivationParams
argument. This will return an ActiveVU, which will actually run the
user's code.

The InitializedVU.Activate will spawn a goroutine to track the context
for interrupting script execution, and calling the callback function and
return the VU to the buffer.

Fixes #889
Fixes #1283
cuonglm added a commit that referenced this issue Jan 7, 2020
The complicated handling of context in RunOnce is not necessary. Each
of the new executors handles contexts and VUs very deliberately and
precisely. We can separate the context handling to interrupt goja
runtime and the actual running user's code.

This PR introduces two new interfaces, "InitializedVU" annd "ActiveVU".

InitializedVU is what Runner.NewVU will return, and is stored in
ExecutionState.vus buffer. Whenever a InitializedVU is pull from the
buffer, caller can call InitializedVU.Activate with VUActivationParams
argument. This will return an ActiveVU, which will actually run the
user's code.

The InitializedVU.Activate will spawn a goroutine to track the context
for interrupting script execution, and calling the callback function and
return the VU to the buffer.

Fixes #889
Fixes #1283
cuonglm added a commit that referenced this issue Jan 7, 2020
The complicated handling of context in RunOnce is not necessary. Each
of the new executors handles contexts and VUs very deliberately and
precisely. We can separate the context handling to interrupt goja
runtime and the actual running user's code.

This PR introduces two new interfaces, "InitializedVU" annd "ActiveVU".

InitializedVU is what Runner.NewVU will return, and is stored in
ExecutionState.vus buffer. Whenever a InitializedVU is pull from the
buffer, caller can call InitializedVU.Activate with VUActivationParams
argument. This will return an ActiveVU, which will actually run the
user's code.

The InitializedVU.Activate will spawn a goroutine to track the context
for interrupting script execution, and calling the callback function and
return the VU to the buffer.

Fixes #889
Fixes #1283
cuonglm added a commit that referenced this issue Jan 7, 2020
The complicated handling of context in RunOnce is not necessary. Each
of the new executors handles contexts and VUs very deliberately and
precisely. We can separate the context handling to interrupt goja
runtime and the actual running user's code.

This PR introduces two new interfaces, "InitializedVU" annd "ActiveVU".

InitializedVU is what Runner.NewVU will return, and is stored in
ExecutionState.vus buffer. Whenever a InitializedVU is pull from the
buffer, caller can call InitializedVU.Activate with VUActivationParams
argument. This will return an ActiveVU, which will actually run the
user's code.

The InitializedVU.Activate will spawn a goroutine to track the context
for interrupting script execution, and calling the callback function and
return the VU to the buffer.

Fixes #889
Fixes #1283
cuonglm added a commit that referenced this issue Jan 7, 2020
The complicated handling of context in RunOnce is not necessary. Each
of the new executors handles contexts and VUs very deliberately and
precisely. We can separate the context handling to interrupt goja
runtime and the actual running user's code.

This PR introduces two new interfaces, "InitializedVU" annd "ActiveVU".

InitializedVU is what Runner.NewVU will return, and is stored in
ExecutionState.vus buffer. Whenever a InitializedVU is pull from the
buffer, caller can call InitializedVU.Activate with VUActivationParams
argument. This will return an ActiveVU, which will actually run the
user's code.

The InitializedVU.Activate will spawn a goroutine to track the context
for interrupting script execution, and calling the callback function and
return the VU to the buffer.

Fixes #889
Fixes #1283
@na--
Copy link
Member Author

na-- commented Apr 23, 2020

This should be easy enough to fix after #1368 is merged (and probably #1007 itself is merged in master): https://github.com/loadimpact/k6/pull/1368/#discussion_r413783836

@imiric imiric self-assigned this Jul 8, 2020
@na-- na-- added this to the v0.27.0 milestone Jul 8, 2020
@imiric imiric changed the title Make the __VU execution control var avavailable in the init phase Make the __VU execution control var available in the init phase Jul 8, 2020
imiric pushed a commit that referenced this issue Jul 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
evaluation needed proposal needs to be validated or tested before fully implementing it in k6 ux
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants