README
¶
Metrics Stress Test Example
This example provides a stress testing tool for generating metrics data by invoking functions at high concurrency.
Overview
The stress test function allows you to:
- Invoke a target function multiple times concurrently
- Run the test for a specified duration
- Generate a variety of metrics data for analysis
- Test the performance and reliability of your functions under load
This is particularly useful for:
- Testing how your functions perform under load
- Generating metrics data to visualize in the dashboard
- Identifying performance bottlenecks
- Validating error handling
How to Use
Deploy the Function
serverless deploy -f metrics-stress-test
Run a Stress Test
# Basic usage with defaults (5 concurrent workers, 60 seconds, targeting custom-metrics)
serverless invoke -f metrics-stress-test
# Custom configuration
serverless invoke -f metrics-stress-test -d '{
"concurrency": 10,
"duration": 120,
"target_function": "my-function"
}'
Parameters
concurrency
: Number of concurrent workers (default: 5)duration
: Duration of the test in seconds (default: 60)target_function
: Name of the function to invoke (default: "custom-metrics")
Monitoring the Test
While the stress test is running, you can:
-
View logs to see real-time progress:
serverless logs -f metrics-stress-test -t
-
Open the metrics dashboard to visualize the metrics:
serverless invoke -f metrics-dashboard
Example Workflow
A typical workflow for using the stress test:
-
Deploy the custom-metrics example function:
serverless deploy -f custom-metrics
-
Start the metrics dashboard:
serverless invoke -f metrics-dashboard
-
Run a stress test against the custom-metrics function:
serverless invoke -f metrics-stress-test -d '{ "concurrency": 8, "duration": 120, "target_function": "custom-metrics" }'
-
Watch the metrics dashboard to see the metrics change in real-time
How It Works
The stress test function:
- Starts multiple concurrent workers (goroutines)
- Each worker repeatedly invokes the target function
- Workers use random operations to generate diverse metrics
- The test runs for the specified duration
- Workers track success and error counts
- Results are logged when the test completes
Code Explanation
The key components of the stress test:
- Worker Pool: Uses Go's goroutines and wait groups to manage concurrent workers
- Random Operations: Generates different types of operations to create varied metrics
- Controlled Duration: Runs for a specified time period then gracefully shuts down
- Result Tracking: Counts successes and errors for each worker
Integration with Other Examples
This stress test works well with:
- Custom Metrics Example: Target this function to generate custom metrics
- Metrics Dashboard: Visualize the metrics generated by the stress test
By combining these examples, you can create a complete metrics testing and visualization workflow.
Documentation
¶
There is no documentation for this package.