Sharing a single gRPC client between multiple VUs

As grpc can multiplex multiple channels over a single http/2 connection, is it possible to share a single grpc client between VUs? It appears that currently each VU gets its own client instance each with its own tcp connection.

Hi @jimmymartin

Sorry for the long reply.

It should be possible with something like this:

import { Client } from 'k6/net/grpc';

const client = new Client();

export default () => {
  if (__ITER == 0) {
    client.connect(GRPC_ADDR, { plaintext: true });
  }
  
 // some grpc invokation
}

Let me know if that helps!

That’s basically what I do now which effectively creates a connection per VU. What I wanted to do was to have more VUs than connections.

Thanks, Jimmy

@jimmymartin I see now, sorry that I misunderstood your need;

Unfortunately, it’s not possible right now. The connection management currently delegates to the grpc dependency that we use. We previously received a proposal for connection per VUs sharing ([Experimental] Optional gRPC connection sharing among VUs by chrismoran-mica · Pull Request #31 · grafana/xk6-grpc · GitHub), but it hasn’t reached the merged state.

I hope that explains.