firestore golang package ( Firestore Client / Firestore Connection Pool )

368 views
Skip to first unread message

pete...@bavar.it

unread,
Nov 8, 2017, 1:00:26 PM11/8/17
to Firebase Google Group
Hey guys,

i am wondering if the firestore.Client of the golang package is handling querys in a concurrent way, meaning if i use the same client in a global variable, would it be capable of handling multible querys by different go funcs ?
Kind of like having a connection pool behind the client.

I right now think of it like the Session of the goRethink rethinkdb driver: https://github.com/GoRethink/gorethink

The driver uses a connection pool at all times, by default it creates and frees connections automatically. It's safe for concurrent use by multiple goroutines.
session, err = r.Connect(r.ConnectOpts{
		Address:    url,
		InitialCap: 10,
		MaxOpen:    10,
	})
My approach right now would be a global firestore.Client handling all querys, inserts,...
Like so:
var (
Firestore *firestore.Client
)

func init() {
ctx := context.TODO()
var err error
Firestore, err = firestore.NewClient(ctx, "project-id")
if err != nil {
fmt.Printf("Error %v", err)
}
}

Hiranya Jayathilaka

unread,
Nov 8, 2017, 1:43:52 PM11/8/17
to fireba...@googlegroups.com
I don't think the Client spawns new go routines for each concurrent call. But it should be safe to share the same Client instance among multiple go routines that application code has spawned. The underlying gRPC layer takes care of connection pooling. See https://github.com/GoogleCloudPlatform/google-cloud-go/issues/645 for a related discussion.

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/6729df0c-689a-484f-a688-ce2051a5bef5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Hiranya Jayathilaka | Software Engineer | h...@google.com | 650-203-0128

pete...@bavar.it

unread,
Nov 9, 2017, 3:18:32 AM11/9/17
to Firebase Google Group
Perfect, thank you, so using the same client over multiple for example http.HandleFuncs should not be running into connectivity issues ?

Hiranya Jayathilaka

unread,
Nov 9, 2017, 1:48:51 PM11/9/17
to fireba...@googlegroups.com
Yes, that should be fine.

On Wed, Nov 8, 2017 at 11:04 PM, <pete...@bavar.it> wrote:
Perfect, thank you, so using the same client over multiple for example http.HandleFuncs should not be running into connectivity issues ?
--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages