Wednesday, April 5, 2023

gRPC request testing using Vugen Load runner | gRPC performance testing load runner

gRPC is a modern open source high performance RPC frame work that can run in any environment and it's now been around fo4 several years with a growing user base. Here is the process to create a script in vugen
  1. Start by creating a new VuGen script and selecting the "gRPC" protocol under "Web Services" in the protocol selection window.

  2. In the "Vuser_init" section of the script, add the following code to create a gRPC channel and stub

#include "grpc.h"

grpc_channel* channel;
grpc_stub* stub;

int vuser_init()
{
    channel = grpc_insecure_channel_create("localhost:50051", NULL, NULL);
    stub = grpc_stub_create(channel);
    return 0;
}
In the "Action" section of the script, add the gRPC method call code that you want to test. Here's an example using the "SayHello" method from the gRPC "helloworld" example:

#include "helloworld.grpc.pb.h"

int Action()
{
    hello::Greeter::Stub* greeter_stub = hello::Greeter::NewStub(channel);
    hello::HelloRequest request;
    hello::HelloReply reply;
    grpc::ClientContext context;

    request.set_name("world");

    grpc::Status status = greeter_stub->SayHello(&context, request, &reply);

    if (status.ok()) {
        lr_output_message("Greeting: %s", reply.message().c_str());
    } else {
        lr_output_message("RPC failed: %s", status.error_message().c_str());
    }

    return 0;
}

  1. Finally, in the "Vuser_end" section of the script, add the code to clean up the gRPC channel and stub:
int vuser_end()
{
    grpc_channel_destroy(channel);
    grpc_stub_destroy(stub);
    return 0;
}

That's it! You should now have a functional gRPC script in VuGen that you can use for load testing. Just make sure to replace the example method call with the actual gRPC method you want to test.