Multiple connections and connection pooling

Moved from GitHub dgo/14

Posted by u007:

hi,

does this library support for connection pooling?
do we need to initialise new client connection for every single client request?

how does transaction work? can we reuse the same connection for multiple client?

thank you

u007 commented :

do i use this on main / server,

conn, err := grpc.Dial("localhost:9080", grpc.WithInsecure())
if err != nil {
  log.Fatal(err)
}
defer conn.Close()

and initiate this client on every handler?

dgraphClient := dgo.NewDgraphClient(api.NewDgraphClient(conn))

thank you

OrlandoCo commented :

@u007 According to this link: Golang GRPC Repo

GRPC can safely use a single connection and it’s going to be multiplexed, and limited only by the HTTP/2 max concurrent connections.

An according to the graph client in the client.go code you can find the following:

// A single client is thread safe for sharing with multiple go routines.
func NewDgraphClient(clients ...api.DgraphClient) *Dgraph {
	dg := &Dgraph{
		dc: clients,
	}

	return dg
}

So its seems that you can inject the reference of client to every handler, but this can be confirmed by the contributors.

u007 commented :

what if in the future, we may have logged in user account, will this effect clients?

srfrog commented :

The original question is answered. Closing this.