externally-controlled executor allows you to control k6 execution in real-time via the REST API. You can dynamically scale VUs up or down, pause and resume execution, and adjust test parameters while the test is running.
How It Works
With externally controlled execution:- Test starts with initial
vusand runs forduration(or indefinitely if duration is 0) - VUs continuously loop through iterations
- You can control execution via the k6 REST API:
- Scale VUs up or down
- Pause and resume the test
- Update the configuration dynamically
- Test runs until duration expires or you stop it manually
Configuration
string
required
Must be
externally-controlledinteger
default:"0"
Initial number of VUs. Can be 0. Cannot be negative.
integer
default:"vus"
Maximum number of VUs that can be used during the test. Once set at test start, this cannot be decreased (only increased via API).
duration
required
Maximum test duration. Use
0 for infinite duration (test runs until manually stopped). Cannot be negative.The
gracefulStop option is NOT supported by this executor. VUs stop immediately when the test ends.Example
Basic Setup
Infinite Duration Test
Start Paused
API Control
The k6 REST API (enabled with--http-debug or environment variable) provides endpoints to control execution.
Get Current Status
Scale VUs
Pause Test
Resume Test
Scale and Adjust MaxVUs
When to Use
Use the externally controlled executor when:- You need dynamic control during test execution
- You’re integrating k6 with external monitoring/alerting systems
- You want to adjust load based on real-time application metrics
- You’re building custom load testing dashboards
- You need to manually respond to test conditions
- You want to run exploratory performance testing
- You’re implementing adaptive load testing algorithms
Behavior Details
Initial VUs and MaxVUs
At test start, k6 initializesmaxVUs and activates vus of them:
Dynamic Scaling
Via API, you can scalevus up to maxVUs:
MaxVUs Constraints
Duration Behavior
Finite duration:Pause Behavior
When paused:- Running iterations complete
- No new iterations start
- VUs remain allocated
- Test timer continues (for non-zero duration)
Not Distributable
Common Patterns
Integration with Monitoring
Manual Exploratory Testing
Dashboard Integration
Validation
Valid Configurations
Invalid Configurations
Metrics
Standard k6 metrics are emitted:iterations- Total completed iterationsiteration_duration- Time per iterationvus- Current number of active VUs (changes via API)vus_max- Current maximum VUs (matches maxVUs config)
Best Practices
- Set high maxVUs: Allow plenty of headroom for scaling
- Start low: Begin with few VUs and scale up as needed
- Monitor carefully: Watch metrics when scaling to avoid overload
- Use infinite duration for exploration:
duration: '0'for manual control - Secure the API: Restrict access to the REST API in production
- Gradual scaling: Avoid jumping directly from 10 to 1000 VUs
- Test API integration: Ensure your control logic works before production
- Have a plan: Define scaling rules/criteria before running the test
Limitations
See Also
- Ramping VUs - Programmatic VU ramping with stages
- Constant VUs - Simple fixed VU execution
- k6 REST API Documentation - Complete API reference