2020-03-03 19:32:07 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/binary"
|
|
|
|
"log"
|
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/Pallinder/go-randomdata"
|
|
|
|
"github.com/tecbot/gorocksdb"
|
|
|
|
)
|
|
|
|
|
2020-03-04 04:24:53 +00:00
|
|
|
func putData(wg *sync.WaitGroup, db *gorocksdb.DB, cfs []*gorocksdb.ColumnFamilyHandle, COUNT int) {
|
2020-03-03 19:32:07 +00:00
|
|
|
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))
|
2020-03-04 04:24:53 +00:00
|
|
|
keybuf = append(keybuf, temp[0:2]...)
|
2020-03-03 19:32:07 +00:00
|
|
|
keybuf = append(keybuf, '\x01')
|
|
|
|
binary.BigEndian.PutUint16(temp, uint16(level))
|
2020-03-04 04:24:53 +00:00
|
|
|
keybuf = append(keybuf, temp[0:2]...)
|
2020-03-03 19:32:07 +00:00
|
|
|
|
2020-03-04 04:24:53 +00:00
|
|
|
db.PutCF(wo, cfs[len(cfs)-1], keybuf, []byte(task))
|
2020-03-03 19:32:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
log.Println(int64(COUNT) / (time.Now().Unix() - now))
|
|
|
|
}
|