113 lines
2.0 KiB
Go
113 lines
2.0 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/474420502/focus/compare"
|
|
pqueuekey "github.com/474420502/focus/priority_queuekey"
|
|
|
|
"github.com/tecbot/gorocksdb"
|
|
)
|
|
|
|
func CreateData(gthread int, COUNT int) {
|
|
|
|
db, cfs := OpenDataBase()
|
|
|
|
wg := &sync.WaitGroup{}
|
|
wg.Add(gthread)
|
|
|
|
for i := 0; i < gthread; i++ {
|
|
go putData(wg, db, cfs, COUNT)
|
|
}
|
|
|
|
wg.Wait()
|
|
}
|
|
|
|
func queryData(wg *sync.WaitGroup, db *gorocksdb.DB, cfs []*gorocksdb.ColumnFamilyHandle, COUNT int) {
|
|
defer wg.Done()
|
|
|
|
now := time.Now().Unix()
|
|
|
|
ro := gorocksdb.NewDefaultReadOptions()
|
|
|
|
cf := cfs[len(cfs)-1]
|
|
iter := db.NewIteratorCF(ro, cf)
|
|
defer iter.Close()
|
|
|
|
iter.SeekToFirst()
|
|
// temp := make([]byte, 8)
|
|
// binary.BigEndian.PutUint64(temp, 5)
|
|
// iter.Seek(temp)
|
|
log.Println(iter.Valid())
|
|
|
|
pq := pqueuekey.New(compare.ByteArray)
|
|
|
|
for i := 0; i < COUNT && iter.Valid(); i++ {
|
|
|
|
bkey := iter.Key().Data()
|
|
bvalue := iter.Value().Data()
|
|
|
|
pq.Push(bkey, bvalue)
|
|
|
|
// key := string(bkey)
|
|
// value := string(bvalue)
|
|
|
|
// log.Println(binary.BigEndian.Uint64(bkey[0:8]), "\nkey:", key, "\n", "value:", value)
|
|
|
|
iter.Next()
|
|
}
|
|
|
|
log.Println("size:", pq.Size())
|
|
log.Println("qps:", int64(COUNT)/(time.Now().Unix()-now))
|
|
|
|
piter := pq.Iterator()
|
|
for i := 0; piter.Next() && i < 10; i++ {
|
|
println("key:", string(piter.Key().([]byte)), "value:", string(piter.Value().([]byte)))
|
|
}
|
|
|
|
}
|
|
|
|
func QueryData() {
|
|
|
|
db, cfs := OpenDataBase()
|
|
|
|
GCOUNT := 10
|
|
COUNT := 1000000
|
|
|
|
now := time.Now().Unix()
|
|
|
|
wg := &sync.WaitGroup{}
|
|
wg.Add(GCOUNT)
|
|
|
|
for i := 0; i < GCOUNT; i++ {
|
|
|
|
go queryData(wg, db, cfs, COUNT)
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
log.Println("total qps:", int64(COUNT*GCOUNT)/(time.Now().Unix()-now))
|
|
}
|
|
|
|
func main() {
|
|
|
|
QueryData()
|
|
// CreateData(50, 100000) // 10 * 10000
|
|
|
|
// db.Put(wo, []byte("foo"), []byte("bar"))
|
|
|
|
// ro := gorocksdb.NewDefaultReadOptions()
|
|
// db, err := gorocksdb.OpenDb(opts, "./.rocksdb")
|
|
// if err != nil {
|
|
// panic(err)
|
|
// }
|
|
// s, err := db.Get(ro, []byte("foo"))
|
|
// if err != nil {
|
|
// panic(err)
|
|
// }
|
|
// log.Println(string(s.Data()))
|
|
|
|
}
|