Skip to content

Commit 3a1a44b

Browse files
authored
Add files via upload (#462)
1 parent b3bb260 commit 3a1a44b

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

scripts/Competition_Final_get_perf.sh

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/bin/bash
2+
3+
bench_file='
4+
package test_raftstore
5+
6+
import (
7+
"fmt"
8+
"math/rand"
9+
"strconv"
10+
"testing"
11+
"time"
12+
13+
"github.com/pingcap-incubator/tinykv/kv/config"
14+
)
15+
16+
func TestReadWrite(t *testing.T) {
17+
nservers := 3
18+
cfg := config.NewTestConfig()
19+
cfg.RaftLogGcCountLimit = uint64(100)
20+
cfg.RegionMaxSize = 300
21+
cfg.RegionSplitSize = 200
22+
cluster := NewTestCluster(nservers, cfg)
23+
cluster.Start()
24+
defer cluster.Shutdown()
25+
26+
electionTimeout := cfg.RaftBaseTickInterval * time.Duration(cfg.RaftElectionTimeoutTicks)
27+
// Wait for leader election
28+
time.Sleep(2 * electionTimeout)
29+
30+
nclients := 16
31+
chTasks := make(chan int, 1000)
32+
clnts := make([]chan bool, nclients)
33+
for i := 0; i < nclients; i++ {
34+
clnts[i] = make(chan bool, 1)
35+
go func(cli int) {
36+
defer func() {
37+
clnts[cli] <- true
38+
}()
39+
for {
40+
j, more := <-chTasks
41+
if more {
42+
key := fmt.Sprintf("%02d%08d", cli, j)
43+
value := "x " + strconv.Itoa(j) + " y"
44+
cluster.MustPut([]byte(key), []byte(value))
45+
if (rand.Int() % 1000) < 500 {
46+
value := cluster.Get([]byte(key))
47+
if value == nil {
48+
t.Fatal("value is emtpy")
49+
}
50+
}
51+
} else {
52+
return
53+
}
54+
}
55+
}(i)
56+
}
57+
58+
start := time.Now()
59+
duration := 3 * time.Minute
60+
totalRequests := 0
61+
ticker := time.NewTicker(1 * time.Second)
62+
for {
63+
select {
64+
case <-ticker.C:
65+
elapsed := time.Since(start)
66+
if elapsed >= duration {
67+
close(chTasks)
68+
for cli := 0; cli < nclients; cli++ {
69+
ok := <-clnts[cli]
70+
if !ok {
71+
t.Fatalf("failure")
72+
}
73+
}
74+
ticker.Stop()
75+
totalDuration := time.Since(start)
76+
t.Logf("Total Duration: %v, Total Requests: %v", totalDuration, totalRequests)
77+
t.Logf("QPS: %v", float64(totalRequests)/totalDuration.Seconds())
78+
return
79+
}
80+
case chTasks <- totalRequests:
81+
totalRequests++
82+
}
83+
}
84+
}
85+
'
86+
87+
echo "$bench_file" > kv/test_raftstore/bench_test.go
88+
go test ./kv/test_raftstore/ -run ReadWrite -v > bench.log
89+
score=$(grep QPS: bench.log | awk '{print $3}')
90+
rm bench.log
91+
92+
if [ -z "$score" ]
93+
then
94+
score=0
95+
fi
96+
97+
echo $score

0 commit comments

Comments
 (0)