Overview
Load pattern shapes control how the load is distributed over time during a benchmark. While the default behavior is a simple ramp-up, custom shapes enable more sophisticated testing scenarios like step increases, spike testing, and custom patterns.Default Behavior (Ramp-Up)
When no shape is specified, Chainbench uses a linear ramp-up pattern:- Ramp-up phase: Users are added at the spawn rate until the target number is reached
- Steady state: The target number of users is maintained for the remaining test duration
- 0-10s: Ramping from 0 to 100 users (10 users/second)
- 10s-10m: Maintaining 100 users
Available Shapes
Step Shape
The step shape increases load in discrete steps, allowing you to observe system behavior at different load levels.How It Works
- Number of steps: Calculated as
users / spawn_rate - Step duration:
test_time / number_of_steps - Users per step: Increases by
spawn_rateeach step
Usage
Example Calculation
With--users 100, --spawn-rate 20, --test-time 10m:
- Number of steps: 100 / 20 = 5 steps
- Step duration: 10m / 5 = 2 minutes per step
- User progression: 20 → 40 → 60 → 80 → 100
Use Cases
Performance Plateau Detection
Performance Plateau Detection
Identify at which load level your infrastructure begins to degrade by observing metrics at each step.
Resource Scaling Validation
Resource Scaling Validation
Test auto-scaling behavior by observing how your infrastructure responds to each step increase.
Capacity Planning
Capacity Planning
Determine the maximum sustainable load by incrementally increasing users until performance degrades.
Implementation
Spike Shape
The spike shape simulates sudden traffic surges to test infrastructure resilience and recovery.How It Works
The spike pattern has three phases:- Baseline (40% of test time): 10% of target users
- Spike (20% of test time): 100% of target users
- Recovery (40% of test time): Back to 10% of target users
Usage
Example Timeline
With--users 200 and --test-time 10m:
- 0-4m: 20 users (10% of 200)
- 4-6m: 200 users (100% - spike)
- 6-10m: 20 users (10% - recovery)
Use Cases
Resilience Testing
Resilience Testing
Verify that your infrastructure can handle sudden traffic spikes without failing or degrading significantly.
Recovery Validation
Recovery Validation
Ensure systems properly recover after a spike and don’t remain in a degraded state.
Circuit Breaker Testing
Circuit Breaker Testing
Test rate limiting, circuit breakers, and other protective mechanisms during sudden load increases.
Cache Invalidation
Cache Invalidation
Observe how caching systems behave when suddenly overwhelmed and during recovery.
Implementation
Listing Available Shapes
To see all available shapes in your Chainbench installation:chainbench/shapes/ directory.
Creating Custom Shapes
You can create custom load shapes by extending Locust’sLoadTestShape class.
Basic Structure
Example: Wave Pattern
Create a shape that oscillates between low and high load:Adding Custom Shapes
- Create your shape file in the
chainbench/shapes/directory:
-
Implement your
LoadTestShapeclass -
Use it with the
--shapeflag:
Shape Parameters
Common Options
Whenuse_common_options = True, shapes automatically use:
Target number of users from
--users flagSpawn rate from
--spawn-rate flagTotal test duration from
--test-time flagCustom Options
Shapes can define custom command-line options:Combining Shapes with Other Features
With Monitors
With Batch Mode
With Custom Profiles
Best Practices
Choose the Right Shape
Choose the Right Shape
- Default (ramp-up): General performance testing and baseline metrics
- Step: Capacity planning and identifying performance thresholds
- Spike: Resilience testing and auto-scaling validation
- Custom: Specific scenarios matching your production traffic patterns
Duration Considerations
Duration Considerations
- Step shape: Ensure each step duration is long enough to observe steady-state behavior (typically 2-5 minutes per step)
- Spike shape: Test duration should be at least 10 minutes to capture full baseline-spike-recovery cycle
- Custom shapes: Consider monitoring and metric collection intervals
Resource Planning
Resource Planning
- Higher peak loads require more worker processes
- Monitor client machine resources during spike tests
- Consider distributed load generation for large-scale spike tests
- Account for network latency in shape timing
Analysis and Metrics
Analysis and Metrics
- Correlate shape timing with performance metrics
- Look for lag in system response during phase transitions
- Compare baseline vs. peak performance
- Validate recovery time after spikes
Troubleshooting
Shape Not Found
If you receive a “shape not found” error:- Verify the shape name:
chainbench list shapes - Check the file exists in
chainbench/shapes/ - Ensure the file has a
.pyextension - Verify the class inherits from
LoadTestShape
Unexpected Load Pattern
If the load doesn’t match expectations:- Check spawn rate is appropriate for the shape
- Verify test duration is long enough for the pattern
- Monitor worker process logs for issues
- Ensure sufficient system resources on the load generator
Performance During Transitions
If you see issues during shape transitions:- Adjust spawn rate for smoother transitions
- Increase step duration in step shapes
- Monitor both client and server resources
- Check for network saturation during rapid ramp-ups
Examples
Step Load Test for Capacity Planning
Spike Resilience Test
Custom Wave Pattern (Advanced)
Createchainbench/shapes/wave.py with the wave implementation above, then: