diff options
| author | Chris Lu <chris.lu@uber.com> | 2019-03-13 23:07:24 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@uber.com> | 2019-03-13 23:07:24 -0700 |
| commit | 346541a101a06b24b7630e58cdb07353c1c0904c (patch) | |
| tree | de9ebbc5002e22d4cb22ecb71132f3534732e167 /weed | |
| parent | 99ce10daeb07227ae79ae23d3ca61351bf4771a3 (diff) | |
| download | seaweedfs-346541a101a06b24b7630e58cdb07353c1c0904c.tar.xz seaweedfs-346541a101a06b24b7630e58cdb07353c1c0904c.zip | |
print out per entry memory usage
Diffstat (limited to 'weed')
| -rw-r--r-- | weed/storage/needle/compact_map_perf_test.go | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/weed/storage/needle/compact_map_perf_test.go b/weed/storage/needle/compact_map_perf_test.go index cd21cc184..bb538bf7f 100644 --- a/weed/storage/needle/compact_map_perf_test.go +++ b/weed/storage/needle/compact_map_perf_test.go @@ -28,6 +28,7 @@ go tool pprof --alloc_space needle.test mem.out func TestMemoryUsage(t *testing.T) { var maps []*CompactMap + totalRowCount := uint64(0) startTime := time.Now() for i := 0; i < 10; i++ { @@ -35,11 +36,13 @@ func TestMemoryUsage(t *testing.T) { if ie != nil { log.Fatalln(ie) } - maps = append(maps, loadNewNeedleMap(indexFile)) + m, rowCount := loadNewNeedleMap(indexFile) + maps = append(maps, m) + totalRowCount += rowCount indexFile.Close() - PrintMemUsage() + PrintMemUsage(totalRowCount) now := time.Now() fmt.Printf("\tTaken = %v\n", now.Sub(startTime)) startTime = now @@ -47,12 +50,14 @@ func TestMemoryUsage(t *testing.T) { } -func loadNewNeedleMap(file *os.File) *CompactMap { +func loadNewNeedleMap(file *os.File) (*CompactMap, uint64) { m := NewCompactMap() bytes := make([]byte, NeedleEntrySize) + rowCount := uint64(0) count, e := file.Read(bytes) for count > 0 && e == nil { for i := 0; i < count; i += NeedleEntrySize { + rowCount++ key := BytesToNeedleId(bytes[i : i+NeedleIdSize]) offset := BytesToOffset(bytes[i+NeedleIdSize : i+NeedleIdSize+OffsetSize]) size := util.BytesToUint32(bytes[i+NeedleIdSize+OffsetSize : i+NeedleIdSize+OffsetSize+SizeSize]) @@ -67,17 +72,18 @@ func loadNewNeedleMap(file *os.File) *CompactMap { count, e = file.Read(bytes) } - return m + return m, rowCount } -func PrintMemUsage() { +func PrintMemUsage(totalRowCount uint64) { runtime.GC() var m runtime.MemStats runtime.ReadMemStats(&m) // For info on each, see: https://golang.org/pkg/runtime/#MemStats - fmt.Printf("Alloc = %v MiB", bToMb(m.Alloc)) + fmt.Printf("Each %v Bytes", m.Alloc/totalRowCount) + fmt.Printf("\tAlloc = %v MiB", bToMb(m.Alloc)) fmt.Printf("\tTotalAlloc = %v MiB", bToMb(m.TotalAlloc)) fmt.Printf("\tSys = %v MiB", bToMb(m.Sys)) fmt.Printf("\tNumGC = %v", m.NumGC) |
