k6/net/grpc module, including unary calls, client streaming, server streaming, bidirectional streaming, and server reflection.
Getting Started
The gRPC client requires loading protocol buffer definitions before making requests.The
load() method must be called in the init context (outside the default function). The reflect option allows the client to discover services without proto files.Loading Protocol Buffers
- Proto Files
- Protoset Files
- Server Reflection
Load
.proto files with optional import paths:Connection Options
Configure gRPC connections with various options:Unary Calls
Make single request-response RPC calls:Server Streaming
Receive multiple messages from the server:Client Streaming
Send multiple messages to the server:Bidirectional Streaming
Send and receive messages simultaneously:Metadata and Headers
Send metadata (headers) with gRPC requests:Status Codes
Check gRPC status codes in responses:Available Status Codes
grpc.StatusOK- Success (0)grpc.StatusCanceled- Operation cancelled (1)grpc.StatusUnknown- Unknown error (2)grpc.StatusInvalidArgument- Invalid argument (3)grpc.StatusDeadlineExceeded- Deadline exceeded (4)grpc.StatusNotFound- Not found (5)grpc.StatusAlreadyExists- Already exists (6)grpc.StatusPermissionDenied- Permission denied (7)grpc.StatusResourceExhausted- Resource exhausted (8)grpc.StatusFailedPrecondition- Failed precondition (9)grpc.StatusAborted- Aborted (10)grpc.StatusOutOfRange- Out of range (11)grpc.StatusUnimplemented- Unimplemented (12)grpc.StatusInternal- Internal error (13)grpc.StatusUnavailable- Unavailable (14)grpc.StatusDataLoss- Data loss (15)grpc.StatusUnauthenticated- Unauthenticated (16)
Response Object
The response object contains:Load Testing Example
Metrics
k6 automatically collects gRPC-specific metrics:grpc_req_duration- Request durationgrpc_streams- Number of streamsgrpc_streams_msgs_received- Messages received per streamgrpc_streams_msgs_sent- Messages sent per stream
Best Practices
- Load proto files in init context to avoid recompilation on each iteration
- Reuse client connections across iterations when possible
- Always close clients to prevent resource leaks
- Use reflection for development but prefer proto files for production
- Handle all status codes for robust error handling
- Set appropriate timeouts to prevent hanging requests
- Use metadata for authentication tokens and request tracking
- Monitor stream lifecycle events for debugging