> Malg is the function the allocates a new goroutine.
> Perhaps you have goroutines that are deadlocked,
> never finish running, and pile up. A destructive way
> to see the goroutines in your program is to run
>
> killall -ABRT yourprogram
>
> In the ensuing crash, you'll get a stack trace for
> every goroutine in the program. I think you'll find
> there are more than you expected.
>
> Russ
I've done more tests, with server and client written in Go. I've run
the same amount of client sessions sequentially and in parallel
executing the same code as a goroutine.
From the profiler output the heap of the server increases sensibly if
I run the clients as goroutines while it is steady if the clients are
run sequentially:
- Sequential client runs
initial server heap: 1.0MB
server heap after 200 client services: 1.5MB (of which malg 1.0MB)
- Parallel client runs
initial server heap: 1.0MB
server heap after 200 client services: 103.5MB (of which malg 100.5MB)
When I kill the server, in the stack trace there are only 2
goroutines:
SIGABRT: abort
Faulting address: 0x1816
PC=0x805367b
futex+0x1f /home/silvia/go/src/pkg/runtime/linux/386/sys.s:108
futex()
futexsleep+0x4f /home/silvia/go/src/pkg/runtime/linux/thread.c:50
futexsleep(0x80e72a8, 0x0, 0x3)
futexlock+0x81 /home/silvia/go/src/pkg/runtime/linux/thread.c:118
futexlock(0x80e72a8, 0x3)
notesleep+0x26 /home/silvia/go/src/pkg/runtime/linux/thread.c:203
notesleep(0x80e72a8, 0x1)
nextgandunlock+0x117 /home/silvia/go/src/pkg/runtime/proc.c:339
nextgandunlock()
scheduler+0xdd /home/silvia/go/src/pkg/runtime/proc.c:492
scheduler()
mstart+0x66 /home/silvia/go/src/pkg/runtime/proc.c:385
mstart()
_rt0_386+0x88 /home/silvia/go/src/pkg/runtime/386/asm.s:75
_rt0_386()
goroutine 29 [4]:
gosched+0x66 /home/silvia/go/src/pkg/runtime/proc.c:513
gosched()
runfinq+0x3e /home/silvia/go/src/pkg/runtime/mgc0.c:344
runfinq()
goexit /home/silvia/go/src/pkg/runtime/proc.c:145
goexit()
goroutine 2 [3]:
runtime.entersyscall+0x5d /home/silvia/go/src/pkg/runtime/proc.c:534
runtime.entersyscall()
syscall.Syscall6+0x5 /home/silvia/go/src/pkg/syscall/asm_linux_386.s:
40
syscall.Syscall6()
syscall.EpollWait+0x71 /home/silvia/go/src/pkg/syscall/
zsyscall_linux_386.go:132
syscall.EpollWait(0x100, 0x6, 0x8d970590, 0x1, 0xffffffff, ...)
net.*pollster·WaitFD+0x111 /home/silvia/go/src/pkg/net/fd_linux.go:116
net.*pollster·WaitFD(0x6, 0x8d970590, 0x1, 0x1, 0xffffffff, ...)
net.*pollServer·Run+0xc9 /home/silvia/go/src/pkg/net/fd.go:232
net.*pollServer·Run(0x110990, 0x0)
goexit /home/silvia/go/src/pkg/runtime/proc.c:145
goexit()
goroutine 1 [4]:
gosched+0x66 /home/silvia/go/src/pkg/runtime/proc.c:513
gosched()
chanrecv+0x15c /home/silvia/go/src/pkg/runtime/chan.c:362
chanrecv(0x115d70, 0x15ca80, 0x1, 0x807d11b)
runtime.chanrecv1+0x37 /home/silvia/go/src/pkg/runtime/chan.c:435
runtime.chanrecv1(0x115d40, 0x11bd50)
net.*pollServer·WaitRead+0x4d /home/silvia/go/src/pkg/net/fd.go:272
net.*pollServer·WaitRead(0x115d40, 0x118f00, 0x0)
net.*netFD·accept+0x2b3 /home/silvia/go/src/pkg/net/fd.go:508
net.*netFD·accept(0x15c900, 0x118f00, 0x0, 0x0, 0xb, ...)
net.*TCPListener·AcceptTCP+0x53 /home/silvia/go/src/pkg/net/tcpsock.go:
253
net.*TCPListener·AcceptTCP(0x118f00, 0x8084076, 0x8, 0x0)
net.*TCPListener·Accept+0x36 /home/silvia/go/src/pkg/net/tcpsock.go:
263
net.*TCPListener·Accept(0x1109e8, 0x11bee0, 0x0, 0x0,
0x2026e158, ...)
http.Serve+0x6b /home/silvia/go/src/pkg/http/server.go:551
http.Serve(0x1109e8, 0x0, 0x0, 0x0, 0x0, ...)
http.ListenAndServe+0x84 /home/silvia/go/src/pkg/http/server.go:595
http.ListenAndServe(0x15ca20, 0x1109e8, 0x15ca40, 0x110828,
0x15ca20, ...)
main.main+0x105 /home/silvia/Desktop/go/src/cs/http-test/server/
httpserv.go:273
main.main()
mainstart+0xf /home/silvia/go/src/pkg/runtime/386/asm.s:83
mainstart()
goexit /home/silvia/go/src/pkg/runtime/proc.c:145
goexit()
eax 0xfffffffc
ebx 0x80e72a8
ecx 0x0
edx 0x3
edi 0x0
esi 0x80d7d30
ebp 0x0
esp 0xbf879f78
eip 0x805367b
eflags 0x292
cs 0x73
fs 0x0
g536)
I think this is a memory leak problem.
Is there something else I can do to solve it?
Silvia