Skip to content

Instantly share code, notes, and snippets.

@disksing
Created December 7, 2021 04:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save disksing/9886f95480e318e252e48648976e1019 to your computer and use it in GitHub Desktop.
Save disksing/9886f95480e318e252e48648976e1019 to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"context"
"flag"
"fmt"
"log"
"math/rand"
"time"
"github.com/tikv/client-go/v2/config"
"github.com/tikv/client-go/v2/rawkv"
)
var (
pd = flag.String("pd", "127.0.0.1:44279", "address of pd")
)
func main() {
flag.Parse()
cli, err := rawkv.NewClient(context.TODO(), []string{*pd}, config.Security{})
assert(err)
const N = 10000
const L = 1024
const S1 = 50
const S2 = 5
const M = 10
log.Println("load data")
for i := 0; i < N; i++ {
err = cli.Put(context.TODO(), []byte(fmt.Sprintf("k%010d", i)), bytes.Repeat([]byte("a"), L))
assert(err)
}
log.Println("start workload1")
go func() {
for {
cli.Scan(context.TODO(), []byte(fmt.Sprintf("k%010d", rand.Intn(N))), nil, 1)
time.Sleep(S1 * time.Millisecond)
}
}()
log.Println("start workload2")
go func() {
for {
if time.Now().Unix()%300 < 45 {
cli.Scan(context.TODO(), []byte(fmt.Sprintf("k%010d", rand.Intn(N))), nil, M)
}
time.Sleep(S2 * time.Millisecond)
}
}()
select {}
}
func assert(err error) {
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment