grpc
Caution
Starting on k6
v0.49, the experimental modulek6/experimental/grpchas been graduated, and its functionality is now available in thek6/net/grpcmodule. Thek6/experimental/grpcis deprecated and will be removed inv0.51.0.To migrate your scripts, replace all
k6/experimental/grpcimports withk6/net/grpc.
The k6/experimental/grpc module is an extension of the
k6/net/grpc. It provides a gRPC client for Remote Procedure Calls (RPC) over HTTP/2.
The key-difference between the two modules is new Stream class, which provides client and server streaming support. Our long-term goal is to make this module part of k6 core, and long-term to replace the
k6/net/grpc module.
Metrics
k6 takes specific measurements for gRPC requests. For the complete list, refer to the Metrics reference.
Example
import grpc from 'k6/experimental/grpc';
import { check, sleep } from 'k6';
const client = new grpc.Client();
client.load(['definitions'], 'hello.proto');
export default () => {
client.connect('grpcbin.test.k6.io:9001', {
// plaintext: false
});
const data = { greeting: 'Bert' };
const response = client.invoke('hello.HelloService/SayHello', data);
check(response, {
'status is OK': (r) => r && r.status === grpc.StatusOK,
});
console.log(JSON.stringify(response.message));
client.close();
sleep(1);
};