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

Document that setup data is copied per VU on it's first iteration #308

Closed
mstoykov opened this issue May 27, 2021 · 2 comments
Closed

Document that setup data is copied per VU on it's first iteration #308

mstoykov opened this issue May 27, 2021 · 2 comments
Labels
Area: OSS Content Improvements or additions to community/oss documentation Type: needsMaintainerHelp Good issue for k6 maintainers

Comments

@mstoykov
Copy link
Contributor

Also, explain a trick to delete the setup data once it has been used in cases that a VU doesn't need all the data.

import {sleep} from "k6";
export function setup () {
    var result ={
        "key1": [],
        "key2": [],
    }
    for (let i = 0; i < 10000; i++ ) {
        result.key1.push({"something": "slse", "i": i})
        result.key2.push({"something": "slse", "i": i})
    }
    return result
}
export let options = {
    stages: [
        {target: 1000, duration: "50s"},
        {target: 1000, duration: "50s"},
    ],
}
var myKeys= [];
export default function(data) {
    if (__ITER ==0) {
        for (let i = 0; i < 5; i++) {
            myKeys.push(data["key1"][Math.floor(Math.random() * data["key1"].length)])
        }
        // console.log(JSON.stringify(myKeys));
        //delete data["key1"];
        //delete data["key2"];
    }
    sleep(1);
}

this will use up 2GB with 150 VUs, but work perfectly fine if the deletes are uncommented as it will free up the memory.

It is important to note that the stages here helps as well as not all VU start at the same time letting the earlier ones having time to get the data they need from setup data and drop the ones it doesn't need.

@mstoykov mstoykov added Area: OSS Content Improvements or additions to community/oss documentation Type: Enhancement labels May 27, 2021
@mstoykov mstoykov changed the title Document that setup data is copied *per* VU Document that setup data is copied per VU on it's first iteration May 27, 2021
@na--
Copy link
Member

na-- commented May 27, 2021

I'd rather we don't document that, or even officially suggest it all that much... Once we document the current implementation details, it will tie our hands in making improvements to them in the future.

W don't copy the setup() data to every VU just because we feel like it, we do it to prevent multiple VUs modifying it and causing a data race panic... But as SharedArray has demonstrated, these days we have better options for sharing immutable data between VUs, so we should probably make the setup() result into something similar in the future... That will use even less memory.

@MattDodsonEnglish
Copy link
Contributor

The setup data being a copy was documented in #638

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: OSS Content Improvements or additions to community/oss documentation Type: needsMaintainerHelp Good issue for k6 maintainers
Projects
None yet
Development

No branches or pull requests

4 participants