I have seen other mentions of out of memory problems,
but these all seem to happen only on 32 bit. I am running on 64
bit.
I have this program that runs in a loop and should use a
limited amount of memory. However, 'top' says its memory usage
keeps growing. The program crashes with a "throw: out of
memory", even though 'top' says there is still plenty of memory
available.
While it's still running, I see the program pause for a few
seconds, ever couple of thousand iterations. I assume this is
when it does garbage collecting.
I have another program that is very similar that doesn't show
these problems. So now I am trying to figure out, is there
something wrong with my program, or with package mgo, or with Go
itself?
go version go1.0.1
GOARCH="amd64"
GOOS="linux"
Here is the code that causes the problem:
location, err := time.LoadLocation("Europe/Amsterdam")
session, err := mgo.Dial(servers)
cTweets := session.DB("twitter").C("tweets")
query := cTweets.Find(bson.M{"CREATED_AT_ZONE": bson.M{"$exists": false }})
count, _ := query.Count()
iter := query.Iter()
tweet := map[string]interface{}{}
for iter.Next(&tweet) { ////// THROW HAPPENS ON THIS LINE
count--
if count%100 == 0 {
fmt.Println(count)
}
// parsed date and time
t, err := time.Parse("Mon Jan 02 15:04:05 -0700 2006", tweet["created_at"].(string))
checkErr(err)
t = t.In(location)
tweet["CREATED_AT_DATE"] = fmt.Sprintf("%04d-%02d-%02d", t.Year(), t.Month(), t.Day())
tweet["CREATED_AT_TIME"] = fmt.Sprintf("%02d:%02d:%02d", t.Hour(), t.Minute(), t.Second())
tweet["CREATED_AT_YEAR"] = t.Year()
tweet["CREATED_AT_MONTH"] = t.Month()
tweet["CREATED_AT_DAY"] = t.Day()
tweet["CREATED_AT_WEEKDAY"] = t.Weekday()
tweet["CREATED_AT_HOUR"] = t.Hour()
tweet["CREATED_AT_MINUTE"] = t.Minute()
tweet["CREATED_AT_SECOND"] = t.Second()
tweet["CREATED_AT_ZONE"], _ = t.Zone()
_, e2 := cTweets.Upsert(bson.M{"id_str": tweet["id_str"]}, tweet)
if e2 != nil {
fmt.Fprintf(os.Stderr, "Update tweet %s errror: %s\n", tweet["id_str"].(string), e2)
}
}
The program that doesn't have problems doesn't get data from
mongo, but from json-files.
Here is the stack trace:
throw: out of memory
goroutine 1 [running]:
reflect.unsafe_New(0xf840060000, 0x4bcd98, 0x11, 0x4bcd98, 0x451bb1, ...)
/net/aps/64/opt/go/src/pkg/runtime/iface.c:682 +0x6d
reflect.New(0xf840060000, 0x4bcd98, 0x11, 0x4bf520, 0xfc3ff7aff0, ...)
/net/aps/64/opt/go/src/pkg/reflect/value.go:1738 +0x6c
launchpad.net/mgo/bson.(*decoder).readDocTo(0xfc3ff70100, 0x4bd248, 0xf8400534d8, 0x156)
/net/aps/64/opt/gosite/src/
launchpad.net/mgo/bson/decode.go:189 +0x78f
launchpad.net/mgo/bson.Unmarshal(0xf9a257e400, 0x36900000369, 0x4ba1a0, 0xf8400534d8, 0x0, ...)
/net/aps/64/opt/gosite/src/
launchpad.net/mgo/bson/bson.go:439 +0x113
launchpad.net/mgo.(*Iter).Next(0xf840092dd0, 0x4ba1a0, 0xf8400534d8, 0xf8400534d8, 0xfc3ff70ac0, ...)
/net/aps/64/opt/gosite/src/
launchpad.net/mgo/session.go:2020 +0x250
main.main()
/net/aistaff/kleiweg/Twitter/fixdate.go:50 +0x704
goroutine 2 [syscall]:
created by runtime.main
/net/aps/64/opt/go/src/pkg/runtime/proc.c:221
goroutine 3 [select]:
launchpad.net/mgo.(*mongoCluster).syncServersLoop(0xf840066160, 0x0)
/net/aps/64/opt/gosite/src/
launchpad.net/mgo/cluster.go:307 +0x456
created by
launchpad.net/mgo.newCluster
/net/aps/64/opt/gosite/src/
launchpad.net/mgo/cluster.go:60 +0x109
goroutine 7 [syscall]:
created by addtimer
/net/aps/64/opt/go/src/pkg/runtime/ztime_amd64.c:69
goroutine 5 [syscall]:
syscall.Syscall6()
/net/aps/64/opt/go/src/pkg/syscall/asm_linux_amd64.s:40 +0x5
syscall.EpollWait(0xf800000006, 0xf8400662d0, 0xa0000000a, 0xffffffff, 0xc, ...)
/net/aps/64/opt/go/src/pkg/syscall/zerrors_linux_amd64.go:1781 +0xa1
net.(*pollster).WaitFD(0xf8400662c0, 0xf840041f00, 0x0, 0x0, 0x0, ...)
/net/aps/64/opt/go/src/pkg/net/fd_linux.go:146 +0x110
net.(*pollServer).Run(0xf840041f00, 0x0)
/net/aps/64/opt/go/src/pkg/net/fd.go:236 +0xe4
created by net.newPollServer
/net/aps/64/opt/go/src/pkg/net/newpollserver.go:35 +0x382
goroutine 6 [runnable]:
syscall.Syscall()
/net/aps/64/opt/go/src/pkg/syscall/asm_linux_amd64.s:30 +0x4b
syscall.Read(0xf800000003, 0xf840043bd0, 0x2400000024, 0x0, 0x0, ...)
/net/aps/64/opt/go/src/pkg/syscall/zerrors_linux_amd64.go:2137 +0x78
net.(*netFD).Read(0xf840086090, 0xf840043bd0, 0x2400000024, 0x2ae400000000, 0x0, ...)
/net/aps/64/opt/go/src/pkg/net/fd.go:424 +0x107
net.(*TCPConn).Read(0xf840053248, 0xf840043bd0, 0x2400000024, 0xf840078000, 0x0, ...)
/net/aps/64/opt/go/src/pkg/net/tcpsock_posix.go:87 +0xce
launchpad.net/mgo.fill(0xf840053248, 0xf840043bd0, 0x2400000024, 0x0, 0xfc3ff52f00, ...)
/net/aps/64/opt/gosite/src/
launchpad.net/mgo/socket.go:367 +0x44
launchpad.net/mgo.(*mongoSocket).readLoop(0xf840078000, 0x0)
/net/aps/64/opt/gosite/src/
launchpad.net/mgo/socket.go:384 +0xec
created by
launchpad.net/mgo.newSocket
/net/aps/64/opt/gosite/src/
launchpad.net/mgo/socket.go:111 +0x255
goroutine 8 [finalizer wait]:
created by runtime.gc
/net/aps/64/opt/go/src/pkg/runtime/mgc0.c:882
--
Peter Kleiweg
my Go programming cookbook:
http://www.let.rug.nl/~kleiweg/go/