So I wrote a daemon in go that handles around 800k documents and i'm having an out of memory problem.
From what i saw when getting the documents from mongodb the memory usage increases with every loop.
func main() {
session, err := mgo.Dial("localhost")
if err != nil { panic(err) }
defer session.Close()
subscriptionsC = session.DB("sm").C("subscriptions")
subscriptions := []Subscription{}
for {
subscriptions = GetSubscriptions()
And the other function is:
func GetSubscriptions()([]Subscription) {
result := []Subscription{}
err := subscriptionsC.Find(nil).Prefetch(0.0).All(&result)
if err != nil { Log("signups_err", err.Error() + "
") }
return result
}
I don't know if it's redeclaring the array with each loop or what exactly happens.
Any help would be greatly appreciated.