Skip to content

Commit 9358024

Browse files
committed
Edit for Evaluation Test
1 parent 28a262b commit 9358024

File tree

2 files changed

+343
-18
lines changed
  • samples
    • application/secret-keeper-cli-go
    • deployment/fabric-smart-client/the-simple-testing-network

2 files changed

+343
-18
lines changed

samples/application/secret-keeper-cli-go/main.go

Lines changed: 101 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ SPDX-License-Identifier: Apache-2.0
88
package main
99

1010
import (
11+
"encoding/csv"
1112
"fmt"
13+
"log"
1214
"os"
15+
"path/filepath"
16+
"runtime"
1317
"strconv"
1418
"time"
1519

@@ -54,24 +58,108 @@ func initConfig() *pkg.Config {
5458
return config
5559
}
5660

57-
func main() {
61+
func clientSend(client *pkg.Client, sendNum int, keyPrefix string, finish chan string, data chan []string, latency chan time.Duration) {
62+
numOpRep := 2
63+
numKey := sendNum / numOpRep
5864

59-
config := initConfig()
65+
latencyArr := make([]string, sendNum)
66+
totalDuration := 0 * time.Second
67+
for i := 0; i < sendNum; i++ {
68+
keyIndex := i
69+
if keyIndex >= numKey {
70+
keyIndex -= numKey
71+
}
72+
key := keyPrefix + "_" + strconv.Itoa(keyIndex) + "RequiredLongPostfixHereToMatchRequirement"
73+
start := time.Now()
74+
if (i/numKey)%(2) == 0 {
75+
// put state: value = key
76+
_ = client.Invoke("put_state", key, key+"_"+strconv.Itoa(i))
77+
// fmt.Println("> " + res)
78+
} else {
79+
// get state: expect value = key
80+
_ = client.Invoke("get_state", key)
81+
// fmt.Println("> " + res)
82+
}
83+
runDuration := time.Since(start)
84+
latencyArr[i] = fmt.Sprintf("%d", runDuration.Milliseconds())
85+
totalDuration += runDuration
86+
}
87+
avgLatency := totalDuration / time.Duration(sendNum)
88+
89+
finish <- keyPrefix
90+
latency <- avgLatency
91+
data <- latencyArr
92+
}
6093

61-
client := pkg.NewClient(config)
62-
// res := client.Invoke("initSecretKeeper")
63-
// fmt.Println("> " + res)
94+
func runExperiment(config *pkg.Config, clientNum int, numReqEach int, filename string) {
95+
clientSet := make([]*pkg.Client, clientNum)
6496

65-
res := client.Query("revealSecret", "Alice")
66-
fmt.Println("> " + res)
97+
for i := 0; i < clientNum; i++ {
98+
clientSet[i] = pkg.NewClient(config)
99+
}
100+
fmt.Println("clientset:", clientSet)
67101

68-
res = client.Invoke("LockSecret", "Bob", "NewSecret2")
69-
fmt.Println("> " + res)
102+
finishChan := make(chan string, 1)
103+
dataChan := make(chan []string, 1)
104+
latencyChan := make(chan time.Duration, 1)
70105

71106
start := time.Now()
72-
for i := 0; i < 10; i++ {
73-
res = client.Invoke("revealSecret", "Alice")
74-
fmt.Println("> " + res)
107+
for i := 0; i < clientNum; i++ {
108+
keyPrefix := "c" + strconv.Itoa(i)
109+
go clientSend(clientSet[i], numReqEach, keyPrefix, finishChan, dataChan, latencyChan)
110+
}
111+
112+
collect := 0
113+
for collect < clientNum {
114+
select {
115+
case <-finishChan:
116+
collect += 1
117+
case <-time.After(30 * time.Second):
118+
fmt.Println("Still waiting for completion, has run:", time.Since(start))
119+
}
120+
}
121+
totalDuration := time.Since(start)
122+
fmt.Println("Finish", clientNum*numReqEach, "of requests, duration:", totalDuration)
123+
124+
collect = 0
125+
totalLatency := 0 * time.Millisecond
126+
for collect < clientNum {
127+
latency := <-latencyChan
128+
totalLatency += latency
129+
collect += 1
130+
}
131+
fmt.Printf("Throughput(Txn/s): %4f, Avglatency(ms/req): %v\n", float32(clientNum*numReqEach*1000)/float32(totalDuration.Milliseconds()), totalLatency/time.Duration(clientNum))
132+
133+
file, err := os.Create(filename)
134+
if err != nil {
135+
log.Fatal(err)
136+
}
137+
defer file.Close()
138+
139+
writer := csv.NewWriter(file)
140+
defer writer.Flush()
141+
142+
collect = 0
143+
for collect < clientNum {
144+
clientData := <-dataChan
145+
writer.Write(clientData)
146+
collect += 1
147+
}
148+
149+
}
150+
151+
func main() {
152+
config := initConfig()
153+
solution := "SKVS"
154+
repeatTime := 3
155+
clientNum := 2
156+
numReqEach := 700
157+
for i := 0; i < repeatTime; i++ {
158+
filename := fmt.Sprintf("%s_latency_%d_%d_%d.csv", solution, clientNum, numReqEach, i)
159+
filepath := filepath.Join("/Users/lew/Desktop/fpc-notes/misc/latencyExp/", filename)
160+
runExperiment(config, clientNum, numReqEach, filepath)
161+
time.Sleep(3 * time.Second)
162+
runtime.GC()
163+
time.Sleep(3 * time.Second)
75164
}
76-
fmt.Println(time.Since(start))
77165
}

0 commit comments

Comments
 (0)