mgo – query performance seems consistently slow (500-650ms)

.. is there anything obvious that would suggest why my queriers are averaging 500-650ms? Yes, there is. You are calling mgo.Dial() before executing each query. mgo.Dial() has to connect to the MongoDB server every time, which you close right after the query. The connection may very likely take hundreds of milliseconds to estabilish, including authentication, … Read more

Best practice to maintain a mgo session

I suggest not using a global session like that. Instead, you can create a type that is responsible for all the database interaction. For example: type DataStore struct { session *mgo.Session } func (ds *DataStore) ucol() *mgo.Collection { … } func (ds *DataStore) UserExist(user string) bool { … } There are many benefits to that … Read more