Skip to content

Instantly share code, notes, and snippets.

@koron
Created March 12, 2020 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koron/baaca48e007102aed46d18a82cb1b363 to your computer and use it in GitHub Desktop.
Save koron/baaca48e007102aed46d18a82cb1b363 to your computer and use it in GitHub Desktop.
a program to check minimum VSZ limitation to start
package main
import (
"crypto/rand"
"fmt"
"io"
"os"
"runtime"
"time"
"github.com/dustin/go-humanize"
)
func memStat(w io.Writer, n int) {
var m runtime.MemStats
runtime.ReadMemStats(&m)
//fmt.Fprintf(w, "Sys=%s Alloc=%s\n", humanize.IBytes(m.Sys), humanize.IBytes(m.Alloc))
fmt.Fprintf(w, "Sys=%s - Heap=%s Stack=%s MSpan=%s MCache=%s BuckHash=%s GC=%s Other=%s\n",
humanize.IBytes(m.Sys),
humanize.IBytes(m.HeapSys),
humanize.IBytes(m.StackSys),
humanize.IBytes(m.MSpanSys),
humanize.IBytes(m.MCacheSys),
humanize.IBytes(m.BuckHashSys),
humanize.IBytes(m.GCSys),
humanize.IBytes(m.OtherSys),
)
}
func main() {
memStat(os.Stdout, 0)
var foo [][]byte
for i := 0; i < 10; i++ {
time.Sleep(2 * time.Second)
bar := make([]byte, 128*1024*1024)
rand.Read(bar)
foo = append(foo, bar)
memStat(os.Stdout, i+1)
}
fmt.Printf("len(foo)=%d\n", len(foo))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment