func doPut(db *gorocksdb.DB, from int, to int) <-chan putStat { var totalTime time.Duration var maxTime time.Duration putCount := 0 loopCount := 100000 putStatCh := make(chan putStat) wo := gorocksdb.NewDefaultWriteOptions() go func() { for { key := []byte(uuid.NewV4().String()) value := randBytes(from, to) start := time.Now() err := db.Put(wo, key, value) if err != nil { fmt.Println("dbPut error : ", err) os.Exit(1) } delta := time.Since(start) if delta > maxTime { maxTime = delta } totalTime += delta putCount++ if (putCount % loopCount) == 0 { avgTime := totalTime / time.Duration(loopCount) putStatCh <- putStat{maxTime, avgTime} maxTime = 0 totalTime = 0 } } }() return putStatCh }
func doPut(db *gorocksdb.DB, from int, to int) <-chan putStat { var totalTime time.Duration var maxTime time.Duration putCount := 0 loopCount := 100000 putStatCh := make(chan putStat) wo := gorocksdb.NewDefaultWriteOptions() createDBEntry := func(key string) { value := randBytes(from, to) start := time.Now() err := db.Put(wo, key, value) if err != nil { fmt.Println("dbPut error : ", err) os.Exit(1) } delta := time.Since(start) if delta > maxTime { maxTime = delta } totalTime += delta putCount++ if (putCount % loopCount) == 0 { avgTime := totalTime / time.Duration(loopCount) putStatCh <- putStat{maxTime, avgTime} maxTime = 0 totalTime = 0 } } go func() { for i, key := range filenames { createDBEntry(key) } close(putStatCh) }() return putStatCh }