Strange GC behaviour

185 views
Skip to first unread message

aka.spin

unread,
Oct 24, 2010, 10:11:34 AM10/24/10
to golang-nuts
I recently tested the "helloworld" example of http package:

package main

import (
"http"
"io"
"log"
)

// hello world, the web server
func HelloServer(w http.ResponseWriter, req *http.Request) {
io.WriteString(w, "hello, world!\n")
}

func main() {
http.HandleFunc("/hello", HelloServer)
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Exit("ListenAndServe: ", err.String())
}
}

I run siege with file of 50000 different urls like "localhost:8080/1",
"localhost:8080/2" etc. All cool. But I see very confusing memory
usage:

- Just started - before testing: VIRT 10005, RES 2520
- After test: VIRT 31732, RES 24476

Half an hour later the value remained the same and did not decrease.
Is http caches any data?

Ibrahim M. Ghazal

unread,
Oct 24, 2010, 11:33:55 AM10/24/10
to golang-nuts
On Oct 24, 5:11 pm, "aka.spin" <aka.s...@gmail.com> wrote:
> I run siege with file of 50000 different urls like "localhost:8080/1",
> "localhost:8080/2" etc. All cool. But I see very confusing memory
> usage:
>
>   - Just started - before testing: VIRT 10005, RES 2520
>   - After test: VIRT 31732, RES 24476
>
> Half an hour later the value remained the same and did not decrease.
> Is http caches any data?

As far as I know, the current garbage collector doesn't release memory
back to the operating system.

Similar questions has appeared many times on the mailing list. I think
it's worth adding to the FAQ.

aka.spin

unread,
Oct 24, 2010, 1:03:00 PM10/24/10
to golang-nuts
Ok. Let's test:

package main

import (
"time"
"log"
)

type Big struct {
Data string
}

func biggy () {
a := &Big{}
a.Data = "Very very long string"
}

func main() {
log.Print("Prepare")
time.Sleep(10000000000)
log.Print("Trashing")
for i := 0; i<100000000; i++ {
biggy()
}
log.Print("All done")
for {
time.Sleep(1000000)
}
}

Results:

- Prepare phase: VIRT 7220, RES 940, SHR 504
- Trashing phase: VIRT 10108, RES 2216, SHR 924
- After all: VIRT 10108, RES 2216, SHR 924

Wow! It has not yet been added to the FAQ? Major developers, that with
you? Thank you all, I'm gone.

Russ Cox

unread,
Oct 24, 2010, 1:08:05 PM10/24/10
to aka.spin, golang-nuts
> Thank you all, I'm gone.

Goodbye.

Russ

Reply all
Reply to author
Forward
0 new messages