Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
milanxiaowei authored Dec 15, 2024
1 parent b3bb260 commit f070c53
Showing 1 changed file with 97 additions and 0 deletions.
97 changes: 97 additions & 0 deletions scripts/Competition_Final_get_perf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/bin/bash

bench_file='
package test_raftstore
import (
"fmt"
"math/rand"
"strconv"
"testing"
"time"
"github.com/pingcap-incubator/tinykv/kv/config"
)
func TestReadWrite(t *testing.T) {
nservers := 3
cfg := config.NewTestConfig()
cfg.RaftLogGcCountLimit = uint64(100)
cfg.RegionMaxSize = 300
cfg.RegionSplitSize = 200
cluster := NewTestCluster(nservers, cfg)
cluster.Start()
defer cluster.Shutdown()
electionTimeout := cfg.RaftBaseTickInterval * time.Duration(cfg.RaftElectionTimeoutTicks)
// Wait for leader election
time.Sleep(2 * electionTimeout)
nclients := 16
chTasks := make(chan int, 1000)
clnts := make([]chan bool, nclients)
for i := 0; i < nclients; i++ {
clnts[i] = make(chan bool, 1)
go func(cli int) {
defer func() {
clnts[cli] <- true
}()
for {
j, more := <-chTasks
if more {
key := fmt.Sprintf("%02d%08d", cli, j)
value := "x " + strconv.Itoa(j) + " y"
cluster.MustPut([]byte(key), []byte(value))
if (rand.Int() % 1000) < 500 {
value := cluster.Get([]byte(key))
if value == nil {
t.Fatal("value is emtpy")
}
}
} else {
return
}
}
}(i)
}
start := time.Now()
duration := 3 * time.Minute
totalRequests := 0
ticker := time.NewTicker(1 * time.Second)
for {
select {
case <-ticker.C:
elapsed := time.Since(start)
if elapsed >= duration {
close(chTasks)
for cli := 0; cli < nclients; cli++ {
ok := <-clnts[cli]
if !ok {
t.Fatalf("failure")
}
}
ticker.Stop()
totalDuration := time.Since(start)
t.Logf("Total Duration: %v, Total Requests: %v", totalDuration, totalRequests)
t.Logf("QPS: %v", float64(totalRequests)/totalDuration.Seconds())
return
}
case chTasks <- totalRequests:
totalRequests++
}
}
}
'

echo "$bench_file" > kv/test_raftstore/bench_test.go
go test ./kv/test_raftstore/ -run ReadWrite -v > bench.log
score=$(grep QPS: bench.log | awk '{print $3}')
rm bench.log

if [ -z "$score" ]
then
score=0
fi

echo $score

0 comments on commit f070c53

Please sign in to comment.