package main import ( "encoding/binary" "log" "sync" "time" "github.com/Pallinder/go-randomdata" "github.com/tecbot/gorocksdb" ) func putData(wg *sync.WaitGroup, db *gorocksdb.DB, cfs []*gorocksdb.ColumnFamilyHandle, COUNT int) { defer wg.Done() now := time.Now().Unix() wo := gorocksdb.NewDefaultWriteOptions() for i := 0; i < COUNT; i++ { temp := make([]byte, 8) name := make([]byte, 8) binary.BigEndian.PutUint64(name, uint64(i)) name = append(name, '-') name = append(name, []byte(randomdata.FirstName(-1))...) name = append(name, '-') name = append(name, []byte(randomdata.FullName(-1))...) name = append(name, '-') binary.BigEndian.PutUint64(temp, uint64(randomdata.Number(0, 10000000))) name = append(name, temp...) age := randomdata.Number(0, 105) level := randomdata.Number(0, 10) task := randomdata.Email() + randomdata.Adjective() + randomdata.City() // tx.Exec("insert into user(name, age,level, task, attr, taskid) values(?, ?, ?, ?, ?, ?)", name, age, level, task, attr, taskid) putbuf := name keybuf := append(putbuf, '\x01') binary.BigEndian.PutUint16(temp, uint16(age)) keybuf = append(keybuf, temp[0:2]...) keybuf = append(keybuf, '\x01') binary.BigEndian.PutUint16(temp, uint16(level)) keybuf = append(keybuf, temp[0:2]...) db.PutCF(wo, cfs[len(cfs)-1], keybuf, []byte(task)) } log.Println(int64(COUNT) / (time.Now().Unix() - now)) }