Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions docs/sources/k6/next/examples/data-parameterization.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,39 @@ export default function () {

{{< /code >}}

Or if you have a big data set and just want no VU to use any data any other VU. But you want to have a set number of VUs. In that case you can use modulo operator to get a user out of the data set for each VU so no other ones does.

This also allows us to loop over the data set while still making certain no two VUs will use the same data at the same time. Or during the test for that matter.
Comment on lines +251 to +253
Copy link
Contributor

Choose a reason for hiding this comment

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

How about:

Suggested change
Or if you have a big data set and just want no VU to use any data any other VU. But you want to have a set number of VUs. In that case you can use modulo operator to get a user out of the data set for each VU so no other ones does.
This also allows us to loop over the data set while still making certain no two VUs will use the same data at the same time. Or during the test for that matter.
If you have a large dataset and want to make sure no two VUs use the same value in the data set at the same time (while keeping a fixed number of VUs), use the modulo operator with the global iteration index. This gives you a round-robin assignment over the dataset and avoids collisions during a run.

WDYT?


{{< code >}}

```javascript
import { sleep } from 'k6';
import { SharedArray } from 'k6/data';
import { scenario } from 'k6/execution';

const users = new SharedArray('users', function () {
return JSON.parse(open('./data.json')).users;
});

const vus = 100;
export const options = {
scenarios: {
login: {
executor: 'constant-vus',
vus: vus,
duration: '1h30m',
},
},
};

export default function () {
console.log(`Users name: ${users[scenario.iterationsInTest % vus].username}`);
sleep(1);
}
```

{{< /code >}}
## Generating data using faker.js

The following articles show how to use faker.js in k6 to generate realistic data during the test execution:
Expand Down
33 changes: 33 additions & 0 deletions docs/sources/k6/v0.47.x/examples/data-parameterization.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,39 @@ export default function () {

{{< /code >}}

Or if you have a big data set and just want no VU to use any data any other VU. But you want to have a set number of VUs. In that case you can use modulo operator to get a user out of the data set for each VU so no other ones does.

This also allows us to loop over the data set while still making certain no two VUs will use the same data at the same time. Or during the test for that matter.

{{< code >}}

```javascript
import { sleep } from 'k6';
import { SharedArray } from 'k6/data';
import { scenario } from 'k6/execution';

const users = new SharedArray('users', function () {
return JSON.parse(open('./data.json')).users;
});

const vus = 100;
export const options = {
scenarios: {
login: {
executor: 'constant-vus',
vus: vus,
duration: '1h30m',
},
},
};

export default function () {
console.log(`Users name: ${users[scenario.iterationsInTest % vus].username}`);
sleep(1);
}
```

{{< /code >}}
## Generating data using faker.js

The following articles show how to use faker.js in k6 to generate realistic data during the test execution:
Expand Down
33 changes: 33 additions & 0 deletions docs/sources/k6/v0.48.x/examples/data-parameterization.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,39 @@ export default function () {

{{< /code >}}

Or if you have a big data set and just want no VU to use any data any other VU. But you want to have a set number of VUs. In that case you can use modulo operator to get a user out of the data set for each VU so no other ones does.

This also allows us to loop over the data set while still making certain no two VUs will use the same data at the same time. Or during the test for that matter.

{{< code >}}

```javascript
import { sleep } from 'k6';
import { SharedArray } from 'k6/data';
import { scenario } from 'k6/execution';

const users = new SharedArray('users', function () {
return JSON.parse(open('./data.json')).users;
});

const vus = 100;
export const options = {
scenarios: {
login: {
executor: 'constant-vus',
vus: vus,
duration: '1h30m',
},
},
};

export default function () {
console.log(`Users name: ${users[scenario.iterationsInTest % vus].username}`);
sleep(1);
}
```

{{< /code >}}
## Generating data using faker.js

The following articles show how to use faker.js in k6 to generate realistic data during the test execution:
Expand Down
33 changes: 33 additions & 0 deletions docs/sources/k6/v0.49.x/examples/data-parameterization.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,39 @@ export default function () {

{{< /code >}}

Or if you have a big data set and just want no VU to use any data any other VU. But you want to have a set number of VUs. In that case you can use modulo operator to get a user out of the data set for each VU so no other ones does.

This also allows us to loop over the data set while still making certain no two VUs will use the same data at the same time. Or during the test for that matter.

{{< code >}}

```javascript
import { sleep } from 'k6';
import { SharedArray } from 'k6/data';
import { scenario } from 'k6/execution';

const users = new SharedArray('users', function () {
return JSON.parse(open('./data.json')).users;
});

const vus = 100;
export const options = {
scenarios: {
login: {
executor: 'constant-vus',
vus: vus,
duration: '1h30m',
},
},
};

export default function () {
console.log(`Users name: ${users[scenario.iterationsInTest % vus].username}`);
sleep(1);
}
```

{{< /code >}}
## Generating data using faker.js

The following articles show how to use faker.js in k6 to generate realistic data during the test execution:
Expand Down
33 changes: 33 additions & 0 deletions docs/sources/k6/v0.50.x/examples/data-parameterization.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,39 @@ export default function () {

{{< /code >}}

Or if you have a big data set and just want no VU to use any data any other VU. But you want to have a set number of VUs. In that case you can use modulo operator to get a user out of the data set for each VU so no other ones does.

This also allows us to loop over the data set while still making certain no two VUs will use the same data at the same time. Or during the test for that matter.

{{< code >}}

```javascript
import { sleep } from 'k6';
import { SharedArray } from 'k6/data';
import { scenario } from 'k6/execution';

const users = new SharedArray('users', function () {
return JSON.parse(open('./data.json')).users;
});

const vus = 100;
export const options = {
scenarios: {
login: {
executor: 'constant-vus',
vus: vus,
duration: '1h30m',
},
},
};

export default function () {
console.log(`Users name: ${users[scenario.iterationsInTest % vus].username}`);
sleep(1);
}
```

{{< /code >}}
## Generating data using faker.js

The following articles show how to use faker.js in k6 to generate realistic data during the test execution:
Expand Down
33 changes: 33 additions & 0 deletions docs/sources/k6/v0.51.x/examples/data-parameterization.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,39 @@ export default function () {

{{< /code >}}

Or if you have a big data set and just want no VU to use any data any other VU. But you want to have a set number of VUs. In that case you can use modulo operator to get a user out of the data set for each VU so no other ones does.

This also allows us to loop over the data set while still making certain no two VUs will use the same data at the same time. Or during the test for that matter.

{{< code >}}

```javascript
import { sleep } from 'k6';
import { SharedArray } from 'k6/data';
import { scenario } from 'k6/execution';

const users = new SharedArray('users', function () {
return JSON.parse(open('./data.json')).users;
});

const vus = 100;
export const options = {
scenarios: {
login: {
executor: 'constant-vus',
vus: vus,
duration: '1h30m',
},
},
};

export default function () {
console.log(`Users name: ${users[scenario.iterationsInTest % vus].username}`);
sleep(1);
}
```

{{< /code >}}
## Generating data using faker.js

The following articles show how to use faker.js in k6 to generate realistic data during the test execution:
Expand Down
33 changes: 33 additions & 0 deletions docs/sources/k6/v0.52.x/examples/data-parameterization.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,39 @@ export default function () {

{{< /code >}}

Or if you have a big data set and just want no VU to use any data any other VU. But you want to have a set number of VUs. In that case you can use modulo operator to get a user out of the data set for each VU so no other ones does.

This also allows us to loop over the data set while still making certain no two VUs will use the same data at the same time. Or during the test for that matter.

{{< code >}}

```javascript
import { sleep } from 'k6';
import { SharedArray } from 'k6/data';
import { scenario } from 'k6/execution';

const users = new SharedArray('users', function () {
return JSON.parse(open('./data.json')).users;
});

const vus = 100;
export const options = {
scenarios: {
login: {
executor: 'constant-vus',
vus: vus,
duration: '1h30m',
},
},
};

export default function () {
console.log(`Users name: ${users[scenario.iterationsInTest % vus].username}`);
sleep(1);
}
```

{{< /code >}}
## Generating data using faker.js

The following articles show how to use faker.js in k6 to generate realistic data during the test execution:
Expand Down
33 changes: 33 additions & 0 deletions docs/sources/k6/v0.53.x/examples/data-parameterization.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,39 @@ export default function () {

{{< /code >}}

Or if you have a big data set and just want no VU to use any data any other VU. But you want to have a set number of VUs. In that case you can use modulo operator to get a user out of the data set for each VU so no other ones does.

This also allows us to loop over the data set while still making certain no two VUs will use the same data at the same time. Or during the test for that matter.

{{< code >}}

```javascript
import { sleep } from 'k6';
import { SharedArray } from 'k6/data';
import { scenario } from 'k6/execution';

const users = new SharedArray('users', function () {
return JSON.parse(open('./data.json')).users;
});

const vus = 100;
export const options = {
scenarios: {
login: {
executor: 'constant-vus',
vus: vus,
duration: '1h30m',
},
},
};

export default function () {
console.log(`Users name: ${users[scenario.iterationsInTest % vus].username}`);
sleep(1);
}
```

{{< /code >}}
## Generating data using faker.js

The following articles show how to use faker.js in k6 to generate realistic data during the test execution:
Expand Down
33 changes: 33 additions & 0 deletions docs/sources/k6/v0.54.x/examples/data-parameterization.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,39 @@ export default function () {

{{< /code >}}

Or if you have a big data set and just want no VU to use any data any other VU. But you want to have a set number of VUs. In that case you can use modulo operator to get a user out of the data set for each VU so no other ones does.

This also allows us to loop over the data set while still making certain no two VUs will use the same data at the same time. Or during the test for that matter.

{{< code >}}

```javascript
import { sleep } from 'k6';
import { SharedArray } from 'k6/data';
import { scenario } from 'k6/execution';

const users = new SharedArray('users', function () {
return JSON.parse(open('./data.json')).users;
});

const vus = 100;
export const options = {
scenarios: {
login: {
executor: 'constant-vus',
vus: vus,
duration: '1h30m',
},
},
};

export default function () {
console.log(`Users name: ${users[scenario.iterationsInTest % vus].username}`);
sleep(1);
}
```

{{< /code >}}
## Generating data using faker.js

The following articles show how to use faker.js in k6 to generate realistic data during the test execution:
Expand Down
33 changes: 33 additions & 0 deletions docs/sources/k6/v0.55.x/examples/data-parameterization.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,39 @@ export default function () {

{{< /code >}}

Or if you have a big data set and just want no VU to use any data any other VU. But you want to have a set number of VUs. In that case you can use modulo operator to get a user out of the data set for each VU so no other ones does.

This also allows us to loop over the data set while still making certain no two VUs will use the same data at the same time. Or during the test for that matter.

{{< code >}}

```javascript
import { sleep } from 'k6';
import { SharedArray } from 'k6/data';
import { scenario } from 'k6/execution';

const users = new SharedArray('users', function () {
return JSON.parse(open('./data.json')).users;
});

const vus = 100;
export const options = {
scenarios: {
login: {
executor: 'constant-vus',
vus: vus,
duration: '1h30m',
},
},
};

export default function () {
console.log(`Users name: ${users[scenario.iterationsInTest % vus].username}`);
sleep(1);
}
```

{{< /code >}}
## Generating data using faker.js

The following articles show how to use faker.js in k6 to generate realistic data during the test execution:
Expand Down
Loading
Loading