Skip to main content
The 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
For example, with 1000 VUs and a 10MB dataset:
  • Without SharedArray: ~10GB total memory usage
  • With SharedArray: ~10MB total memory usage

Important Notes

SharedArray must be created in the init context (outside the default function).
The callback function must be synchronous. Async functions are not supported.
SharedArray is read-only. You cannot modify the data once created.