Is golang opensearch.Client goroutine-safe?

Apologies if this is something I should easily find out, but it seems I am unable to …and I have been able to find the answer easily for other projects like olivere/elastic project:

Is an instance of opensearch.Client safe to use across goroutines?

Additional question: if it is safe to use across goroutines, then is there still any limitation to just using one instance?

Thank you for any help and I apologize if this was something I should have found.

Best,
jon

*opensearch.Client is thread safe. You can create one client at the start of your service (init function of your package, maybe) and pass it around. For Example, As every HTTP request in Go’s HTTP Server would create a new goroutine, you can use your OpenSearch client (created at the start of your service) to serve this request(s). It is unknown, the effect of multiple clients on the throughput/latency of your OpenSearch queries. However generally it not advisable to create multiple clients, as these also spawn go routines internally, and it would result in more context switching overhead for your Go Scheduler.

2 Likes