Roger Pau Monné
2010-04-03 16:13:11 UTC
Hello,
I've wrote to this list a few days ago, about a Bittorrent client I'm trying
to develop in Go, but I came across a problem about memory usage in Go. I
will try to explain what my program does in an easy way, my English is not
very good, so let's hope it is still understandable.
Every peer is formed of 3 goroutines, 1 goroutine that reads from a channel
and writes to a socket, another one that reads from a socket and writes to a
channel, an a goroutine that manages the queue (has 1 incoming and 1
outgoing channels and a map[int] *message to store messages). When a peer
dies, the 3 goroutines return, and every element in the map is set to nil,
false, and the whole map to nil. All this goroutines are methods of a type
Peer or PeerQueue, in the case of the goroutine that manages the queue.
Also in another struct I have a list of all pieces requested to a specific
peer, in the form of "peers map[addr]map[uint64]int64", which is also
cleaned using "peers[peer_addr][piece_ref] = 0, false", and if the peer is
no longer available I do a "peers[peer_addr] = nil, false".
The problem is that if I was connected to 50 peers, and all of them closed
the connection, so I'm no longer connected to anyone, the memory used by my
program is not reduced, and if then I receive 50 new peers from the tracker
and connect to them the memory increases again, but never reduces, although I
try to free everything after it's no longer used. I've created a specific
log file for every peer, to check that all processes associated with it are
finished, and everything looks fine, but the problem is still there. You can
take a look at the full code here: http://github.com/royger/wgo
Do I have to do any specific thing to release memory? I even tried to call
runtime.GC() manually every 30s, but it has no effect. I also finish the
goroutines using return, do I have to use runtime.Goexit()? Is there any
problem if goroutines are methods of a struct? Any clue is welcome, since I
haven't got much experience with GC languages, and I've been trying to
resolve this for some days now.
Thanks, Roger.
I've wrote to this list a few days ago, about a Bittorrent client I'm trying
to develop in Go, but I came across a problem about memory usage in Go. I
will try to explain what my program does in an easy way, my English is not
very good, so let's hope it is still understandable.
Every peer is formed of 3 goroutines, 1 goroutine that reads from a channel
and writes to a socket, another one that reads from a socket and writes to a
channel, an a goroutine that manages the queue (has 1 incoming and 1
outgoing channels and a map[int] *message to store messages). When a peer
dies, the 3 goroutines return, and every element in the map is set to nil,
false, and the whole map to nil. All this goroutines are methods of a type
Peer or PeerQueue, in the case of the goroutine that manages the queue.
Also in another struct I have a list of all pieces requested to a specific
peer, in the form of "peers map[addr]map[uint64]int64", which is also
cleaned using "peers[peer_addr][piece_ref] = 0, false", and if the peer is
no longer available I do a "peers[peer_addr] = nil, false".
The problem is that if I was connected to 50 peers, and all of them closed
the connection, so I'm no longer connected to anyone, the memory used by my
program is not reduced, and if then I receive 50 new peers from the tracker
and connect to them the memory increases again, but never reduces, although I
try to free everything after it's no longer used. I've created a specific
log file for every peer, to check that all processes associated with it are
finished, and everything looks fine, but the problem is still there. You can
take a look at the full code here: http://github.com/royger/wgo
Do I have to do any specific thing to release memory? I even tried to call
runtime.GC() manually every 30s, but it has no effect. I also finish the
goroutines using return, do I have to use runtime.Goexit()? Is there any
problem if goroutines are methods of a struct? Any clue is welcome, since I
haven't got much experience with GC languages, and I've been trying to
resolve this for some days now.
Thanks, Roger.