seaweedfs/weed/storage/compact_map_perf_test.go

44 lines
849 B
Go
Raw Normal View History

package storage
import (
2013-01-17 16:56:56 +08:00
"log"
"os"
2013-02-10 19:09:26 +08:00
"weed/util"
"testing"
)
func TestMemoryUsage(t *testing.T) {
2013-01-17 16:56:56 +08:00
indexFile, ie := os.OpenFile("sample.idx", os.O_RDWR|os.O_RDONLY, 0644)
if ie != nil {
log.Fatalln(ie)
}
LoadNewNeedleMap(indexFile)
}
func LoadNewNeedleMap(file *os.File) CompactMap {
2013-01-17 16:56:56 +08:00
m := NewCompactMap()
bytes := make([]byte, 16*1024)
count, e := file.Read(bytes)
if count > 0 {
fstat, _ := file.Stat()
log.Println("Loading index file", fstat.Name(), "size", fstat.Size())
}
for count > 0 && e == nil {
for i := 0; i < count; i += 16 {
key := util.BytesToUint64(bytes[i : i+8])
offset := util.BytesToUint32(bytes[i+8 : i+12])
size := util.BytesToUint32(bytes[i+12 : i+16])
if offset > 0 {
m.Set(Key(key), offset, size)
} else {
//delete(m, key)
}
}
2013-01-17 16:56:56 +08:00
count, e = file.Read(bytes)
}
return m
}