From
http://godoc.org/gopkg.in/mgo.v2#Dial"Dial establishes a new session to the cluster identified by the given seed
server(s). The session will enable communication with all of the servers in
the cluster, so the seed servers are used only to find out about the cluster
topology."
I have 3 replica sets on 3 servers and each replica set is a shard.
Each server has a mongos instance listening on :27017.
1. Is a mongos instance a seed server? (I'm asking because the term seed server isn't mentioned anywhere in the sharding documentation of mongodb)
2. Do I need to specify all 3 mongos at Dial() or DialWithInfo() to achieve better performance or is it enough to just have the local mongos in there?
Next,
"This method is generally called just once for a given cluster. Further
sessions to the same cluster are then established using the New or Copy
methods on the obtained session. This will make them share the underlying
cluster, and manage the pool of connections appropriately"
So I Dial() to the local mongos and receive a *mgo.Session.
mainsession, _ := mgo.Dial("") // simplified
This is a permanent connection that lasts as long as the mongos instance is up and running or the Go program ends.
Then, in some handler I call mainsession.New() or Copy()
What if meanwhile mongos gets restarted and the mainsession connection is lost?
Will New() fail, will Copy() fail?
And, can I prematurely close the mainsession connection (if New()/Copy() don't fail)?
If I understood correctly, New() or Copy() as opposed to Clone() are used so the mongodb listener doesn't block requests over a previously established, long running connection. true/false?
In the past, with 1 local mongod instance, I had a permanent connection and would send or retireve data on this connection in all handlers. However when mongod was restarted the Go program also had to be restarted, because it lost its connection. So I went to Dial()ing the local mongod on each new request in each handler. And that works with a local mongod but I'm unsure how to proceed with multiple mongos that form shards out of replica sets, 1 mongos listening on each server.
My take on it is to connect to the local mongos instance only ( since I guess it has the same info as the other instances) and call Copy() in each handler, because I have each copy of a Go program on each of the 3 servers listening on a specific port with nginx in front doing load balancing, and in the back they talk to mongodb (or 1 mongos).