I am noticing that the first command executed after connecting is very slow. Subsequent commands after the first command perform fine. If I disconnect, and then reconnect, again the first command is slow.
Here is a repository that uses the Go SDK to connect to: cosmos db, atlas and a local mongo instance. In the example I am using Ping, but I am seeing this with any command.
Connected to Cosmos DB
$ go run main.go Ping 1.549611747s Ping 65.599248ms Connected!
Connected to Atlas
$ go run main.go Ping 624.839234ms Ping 33.384318ms Connected!
Connected to local Mongo
go run main.go Ping 8.688944ms Ping 820.645µs Connected!
I believe that the Connect function in the Go SDK does not actually perform I/O. The first time I call Ping is when a connection is established.
Am I missing an optimization or using the SDK incorrectly? Any suggestions for how to improve performance on the first call would be greatly appreciated. I’m writing a command line tool that accesses mongodb and having every command take an extra second is a problem.