Skip to content

Instantly share code, notes, and snippets.

@jsign
Created August 15, 2019 01:04
Show Gist options
  • Save jsign/6df2de9eb6ef7534744d4f95692fa771 to your computer and use it in GitHub Desktop.
Save jsign/6df2de9eb6ef7534744d4f95692fa771 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"os"
"runtime"
"runtime/pprof"
"strings"
"github.com/prologic/bitcask"
)
func main() {
s, err := bitcask.Open("hello.db")
if err != nil {
log.Fatalf("error while opening the database: %v", err)
}
totalVolumeSize := 800 << 20
valueSize := 4 << 10
value := []byte(strings.Repeat(" ", valueSize))
for i := 1; i <= totalVolumeSize/valueSize; i++ {
key := fmt.Sprintf("%32v", i)
s.Put([]byte(key), value)
}
f, err := os.Create("heap.out")
if err != nil {
log.Fatal("memory profile file: ", err)
}
defer f.Close()
runtime.GC()
pprof.WriteHeapProfile(f)
s.Close()
os.RemoveAll("hello.db")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment