k6/data module provides utilities for efficiently sharing data between VUs.
SharedArray
SharedArray is a read-only array that is shared between all VUs. Itβs useful for sharing large datasets without duplicating them in memory for each VU.Constructor
string
Unique identifier for this shared array
function
Function that returns the array data. Called only once per test run. Must be synchronous.
Usage
SharedArray instances can be accessed like regular arrays:Examples
Loading Data from JSON File
Generating Test Data
Per-VU Data Selection
Performance Benefits
SharedArray is designed to save memory when running tests with many VUs:- Without SharedArray: Each VU has its own copy of the data in memory
- With SharedArray: Data is stored once and shared across all VUs
- Without SharedArray: ~10GB total memory usage
- With SharedArray: ~10MB total memory usage