Skip to content

zzssg/grpc-k6-go

Repository files navigation

gRPC Load Testing with k6

This project demonstrates load testing of gRPC services using k6.io load testing framework. It includes test scenarios for evaluating the performance and stability of gRPC servers under various loads.

Project Structure

.
├── proto/
│   └── helloworld.proto          # gRPC service definition
├── scenarios/
│   ├── grpc-test-max.js          # Maximum performance test scenario
│   └── grpc-test-stability.js    # Stability test scenario
├── html-report-max.html          # HTML report for max performance test
├── html-report-stability.html    # HTML report for stability test
├── run-k6-max.bat                # Batch script to run max performance test
└── run-k6-stability.bat          # Batch script to run stability test

Prerequisites

  • k6 with gRPC support
  • A gRPC server implementing the helloworld service
  • (Optional) InfluxDB for metrics storage
  • (Optional) Grafana for visualization

Test Scenarios

1. Maximum Performance Test (grpc-test-max.js)

This scenario gradually increases the load to find the maximum performance point of the gRPC service:

  • Starts at 500 requests per minute
  • Gradually ramps up to 36,000 requests per minute
  • Uses ramping arrival rate executor
  • Maintains constant load at each stage for 10-20 seconds
  • Pre-allocates 15 virtual users

2. Stability Test (grpc-test-stability.js)

This scenario tests the stability of the gRPC service under sustained load:

  • Maintains 15,000 requests per minute for 11 minutes
  • Uses 15 pre-allocated virtual users
  • Designed to check for memory leaks and performance degradation over time

Service Under Test

The tests target the standard gRPC HelloWorld service defined in helloworld.proto:

service Greeter {
  rpc SayHello (HelloRequest) returns (HelloReply) {}
}

message HelloRequest {
  string name = 1;
}

message HelloReply {
  string message = 1;
}

Running the Tests

Using Batch Scripts (Windows)

Max Performance Test

run-k6-max.bat

Stability Test

run-k6-stability.bat

Manual Execution

Max Performance Test

set K6_WEB_DASHBOARD=true
set K6_WEB_DASHBOARD_EXPORT=html-report-max.html
k6 run --out influxdb=http://perfuser:perfuser12345@localhost:8086/k6 ./scenarios/grpc-test-max.js

Stability Test

set K6_WEB_DASHBOARD=true
set K6_WEB_DASHBOARD_EXPORT=html-report-stability.html
k6 run --out influxdb=http://perfuser:perfuser12345@localhost:8086/k6 ./scenarios/grpc-test-stability.js

Configuration Details

Environment Variables

  • K6_WEB_DASHBOARD: Enables the web dashboard during test execution
  • K6_WEB_DASHBOARD_EXPORT: Exports the test results to an HTML file

k6 Options

  • --out influxdb=...: Sends metrics to an InfluxDB instance for storage and analysis
  • The gRPC server is expected to run at 127.0.0.1:50051

Reports

The project includes sample HTML reports:

  • html-report-max.html: Results from the maximum performance test
  • html-report-stability.html: Results from the stability test

Additionally, there are PNG images showing Grafana dashboards with test metrics:

  • grafana-report-max.png
  • grafana-report-stability.png

Customization

To adapt this project for your own gRPC service:

  1. Replace proto/helloworld.proto with your service definition
  2. Update the service name and method calls in the scenario files
  3. Modify the load patterns in the scenario files to match your testing requirements
  4. Adjust the connection endpoint in the scenario files to match your gRPC server address
  5. Update the batch scripts if you change the InfluxDB connection details

Metrics Collected

The tests collect standard k6 metrics including:

  • Request duration
  • Request success rate
  • Virtual user count
  • Iterations per second
  • Data transfer sizes

With InfluxDB integration, these metrics can be visualized in Grafana for real-time monitoring and analysis.

Troubleshooting

  1. Ensure your gRPC server is running at 127.0.0.1:50051 before starting the tests
  2. Make sure k6 is installed and available in your PATH
  3. Check that InfluxDB is accessible if using metrics collection
  4. Verify that the proto file path is correct in the test scenarios

About

k6.io based performance test framework covering GRPC service endpoint

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages