Skip to content

Instantly share code, notes, and snippets.

@Preetam
Created September 4, 2016 15:16
Show Gist options
  • Save Preetam/95bc18ed3399929a50c6c2d24d96b80d to your computer and use it in GitHub Desktop.
Save Preetam/95bc18ed3399929a50c6c2d24d96b80d to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"math/rand"
"runtime"
"time"
"github.com/Preetam/lm2"
)
func main() {
c, err := lm2.OpenCollection("/tmp/lm2/bulk.lm2")
if err != nil {
log.Fatal(err)
}
keyStream := make(chan string, 100000)
generateKeys := func() {
i := 0
for {
select {
case keyStream <- fmt.Sprintf("%019d-%019d-%019d-%019d-%019d-%019d-%019d-%019d",
rand.Int63(), rand.Int63(), rand.Int63(), rand.Int63(),
rand.Int63(), rand.Int63(), rand.Int63(), rand.Int63()):
}
i++
}
}
go generateKeys()
go generateKeys()
runtime.LockOSThread()
for {
start := time.Now()
wb := lm2.NewWriteBatch()
const batchSize = 100000
for i := 0; i < batchSize; i++ {
key := <-keyStream
wb.Set(key, key)
}
log.Println("creating batch took", time.Now().Sub(start))
start = time.Now()
if err := c.Update(wb); err != nil {
log.Fatal(err)
}
log.Println("writing batch took", time.Now().Sub(start))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment