Skip to content

Commit d630abf

Browse files
committed
Edit for Evaluation Test
Signed-off-by: chenchanglew <chelew@student.ethz.ch>
1 parent b97ea7a commit d630abf

File tree

2 files changed

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

2 files changed

+342
-17
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
}

samples/deployment/fabric-smart-client/the-simple-testing-network/topology.go

Lines changed: 241 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func Fabric() []api.Topology {
3838
fabricTopology.EnableFPC()
3939
fabricTopology.AddFPC(config.chaincodeName, config.chaincodeImage, config.fpcOptions...)
4040

41-
fabricTopology.Templates = &topology.Templates{ConfigTx: ModifyConfigTxTemplate}
41+
fabricTopology.Templates = &topology.Templates{ConfigTx: ModifyConfigTxTemplate, Core: ModifyCoreTemplate}
4242

4343
// bring hyperledger explorer into the game
4444
// you can reach it http://localhost:8080 with admin:admin
@@ -261,11 +261,11 @@ Profiles:{{ range .Profiles }}
261261
Addresses:{{ range .Orderers }}{{ with $w.Orderer . }}
262262
- 127.0.0.1:{{ $w.OrdererPort . "Listen" }}
263263
{{- end }}{{ end }}
264-
BatchTimeout: 2s
264+
BatchTimeout: 1s
265265
BatchSize:
266-
MaxMessageCount: 10
266+
MaxMessageCount: 2
267267
AbsoluteMaxBytes: 98 MB
268-
PreferredMaxBytes: 2048 KB
268+
PreferredMaxBytes: 4096 KB
269269
Capabilities:
270270
V2_0: true
271271
{{- if eq $w.Consensus.Type "kafka" }}
@@ -350,3 +350,240 @@ Profiles:{{ range .Profiles }}
350350
{{- end }}
351351
{{ end }}
352352
`
353+
354+
const ModifyCoreTemplate = `---
355+
logging:
356+
spec: {{ .Logging.Spec }}
357+
format: {{ .Logging.Format }}
358+
359+
peer:
360+
id: {{ Peer.ID }}
361+
networkId: {{ .NetworkID }}
362+
address: 127.0.0.1:{{ .PeerPort Peer "Listen" }}
363+
addressAutoDetect: true
364+
listenAddress: 127.0.0.1:{{ .PeerPort Peer "Listen" }}
365+
chaincodeListenAddress: 127.0.0.1:{{ .PeerPort Peer "Chaincode" }}
366+
keepalive:
367+
minInterval: 60s
368+
interval: 300s
369+
timeout: 600s
370+
client:
371+
interval: 60s
372+
timeout: 600s
373+
deliveryClient:
374+
interval: 60s
375+
timeout: 20s
376+
gossip:
377+
bootstrap: 127.0.0.1:{{ .PeerPort Peer "Listen" }}
378+
endpoint: 127.0.0.1:{{ .PeerPort Peer "Listen" }}
379+
externalEndpoint: 127.0.0.1:{{ .PeerPort Peer "Listen" }}
380+
useLeaderElection: true
381+
orgLeader: false
382+
membershipTrackerInterval: 5s
383+
maxBlockCountToStore: 100
384+
maxPropagationBurstLatency: 10ms
385+
maxPropagationBurstSize: 10
386+
propagateIterations: 1
387+
propagatePeerNum: 3
388+
pullInterval: 4s
389+
pullPeerNum: 3
390+
requestStateInfoInterval: 4s
391+
publishStateInfoInterval: 4s
392+
stateInfoRetentionInterval:
393+
publishCertPeriod: 10s
394+
dialTimeout: 3s
395+
connTimeout: 2s
396+
recvBuffSize: 20
397+
sendBuffSize: 200
398+
digestWaitTime: 1s
399+
requestWaitTime: 1500ms
400+
responseWaitTime: 2s
401+
aliveTimeInterval: 5s
402+
aliveExpirationTimeout: 25s
403+
reconnectInterval: 25s
404+
election:
405+
startupGracePeriod: 15s
406+
membershipSampleInterval: 1s
407+
leaderAliveThreshold: 10s
408+
leaderElectionDuration: 5s
409+
pvtData:
410+
pullRetryThreshold: 7s
411+
transientstoreMaxBlockRetention: 1000
412+
pushAckTimeout: 3s
413+
btlPullMargin: 10
414+
reconcileBatchSize: 10
415+
reconcileSleepInterval: 10s
416+
reconciliationEnabled: true
417+
skipPullingInvalidTransactionsDuringCommit: false
418+
state:
419+
enabled: true
420+
checkInterval: 10s
421+
responseTimeout: 3s
422+
batchSize: 10
423+
blockBufferSize: 100
424+
maxRetries: 3
425+
events:
426+
address: 127.0.0.1:{{ .PeerPort Peer "Events" }}
427+
buffersize: 100
428+
timeout: 10ms
429+
timewindow: 15m
430+
keepalive:
431+
minInterval: 60s
432+
tls:
433+
enabled: true
434+
clientAuthRequired: {{ .ClientAuthRequired }}
435+
cert:
436+
file: {{ .PeerLocalTLSDir Peer }}/server.crt
437+
key:
438+
file: {{ .PeerLocalTLSDir Peer }}/server.key
439+
clientCert:
440+
file: {{ .PeerLocalTLSDir Peer }}/server.crt
441+
clientKey:
442+
file: {{ .PeerLocalTLSDir Peer }}/server.key
443+
rootcert:
444+
file: {{ .PeerLocalTLSDir Peer }}/ca.crt
445+
clientRootCAs:
446+
files:
447+
- {{ .PeerLocalTLSDir Peer }}/ca.crt
448+
authentication:
449+
timewindow: 15m
450+
fileSystemPath: filesystem
451+
BCCSP:
452+
Default: SW
453+
SW:
454+
Hash: SHA2
455+
Security: 256
456+
FileKeyStore:
457+
KeyStore:
458+
mspConfigPath: {{ .PeerLocalMSPDir Peer }}
459+
localMspId: {{ (.Organization Peer.Organization).MSPID }}
460+
deliveryclient:
461+
reconnectTotalTimeThreshold: 3600s
462+
localMspType: bccsp
463+
profile:
464+
enabled: false
465+
listenAddress: 127.0.0.1:{{ .PeerPort Peer "ProfilePort" }}
466+
handlers:
467+
authFilters:
468+
- name: DefaultAuth
469+
- name: ExpirationCheck
470+
decorators:
471+
- name: DefaultDecorator
472+
endorsers:
473+
escc:
474+
name: DefaultEndorsement
475+
validators:
476+
vscc:
477+
name: DefaultValidation
478+
{{ if .PvtTxSupport }}vscc_pvt:
479+
name: DefaultPvtValidation
480+
library: {{ end }}
481+
{{ if .MSPvtTxSupport }}vscc_mspvt:
482+
name: DefaultMSPvtValidation
483+
library: {{ end }}
484+
{{ if .FabTokenSupport }}vscc_token:
485+
name: DefaultTokenValidation
486+
library: {{ end }}
487+
validatorPoolSize:
488+
discovery:
489+
enabled: true
490+
authCacheEnabled: true
491+
authCacheMaxSize: 1000
492+
authCachePurgeRetentionRatio: 0.75
493+
orgMembersAllowedAccess: false
494+
limits:
495+
concurrency:
496+
qscc: 500
497+
498+
vm:
499+
endpoint: unix:///var/run/docker.sock
500+
docker:
501+
tls:
502+
enabled: false
503+
ca:
504+
file: docker/ca.crt
505+
cert:
506+
file: docker/tls.crt
507+
key:
508+
file: docker/tls.key
509+
attachStdout: true
510+
hostConfig:
511+
NetworkMode: host
512+
LogConfig:
513+
Type: json-file
514+
Config:
515+
max-size: "50m"
516+
max-file: "5"
517+
Memory: 2147483648
518+
519+
chaincode:
520+
builder: $(DOCKER_NS)/fabric-ccenv:$(PROJECT_VERSION)
521+
pull: false
522+
golang:
523+
runtime: $(DOCKER_NS)/fabric-baseos:$(PROJECT_VERSION)
524+
dynamicLink: false
525+
car:
526+
runtime: $(DOCKER_NS)/fabric-baseos:$(PROJECT_VERSION)
527+
java:
528+
runtime: $(DOCKER_NS)/fabric-javaenv:latest
529+
node:
530+
runtime: $(DOCKER_NS)/fabric-nodeenv:latest
531+
installTimeout: 1200s
532+
startuptimeout: 1200s
533+
executetimeout: 1200s
534+
mode: net
535+
keepalive: 0
536+
system:
537+
_lifecycle: enable
538+
cscc: enable
539+
lscc: enable
540+
qscc: enable
541+
logging:
542+
level: debug
543+
shim: debug
544+
format: '%{color}%{time:2006-01-02 15:04:05.000 MST} [%{module}] %{shortfunc} -> %{level:.4s} %{id:03x}%{color:reset} %{message}'
545+
externalBuilders: {{ range .ExternalBuilders }}
546+
- path: {{ .Path }}
547+
name: {{ .Name }}
548+
propagateEnvironment: {{ range .PropagateEnvironment }}
549+
- {{ . }}
550+
{{- end }}
551+
{{- end }}
552+
553+
ledger:
554+
blockchain:
555+
state:
556+
stateDatabase: goleveldb
557+
couchDBConfig:
558+
couchDBAddress: 127.0.0.1:5984
559+
username:
560+
password:
561+
maxRetries: 3
562+
maxRetriesOnStartup: 10
563+
requestTimeout: 35s
564+
queryLimit: 10000
565+
maxBatchUpdateSize: 1000
566+
warmIndexesAfterNBlocks: 1
567+
history:
568+
enableHistoryDatabase: true
569+
570+
operations:
571+
listenAddress: 127.0.0.1:{{ .PeerPort Peer "Operations" }}
572+
tls:
573+
enabled: false
574+
cert:
575+
file: {{ .PeerLocalTLSDir Peer }}/server.crt
576+
key:
577+
file: {{ .PeerLocalTLSDir Peer }}/server.key
578+
clientAuthRequired: {{ .ClientAuthRequired }}
579+
clientRootCAs:
580+
files:
581+
- {{ .PeerLocalTLSDir Peer }}/ca.crt
582+
metrics:
583+
provider: {{ .MetricsProvider }}
584+
statsd:
585+
network: udp
586+
address: {{ if .StatsdEndpoint }}{{ .StatsdEndpoint }}{{ else }}127.0.0.1:8125{{ end }}
587+
writeInterval: 5s
588+
prefix: {{ ReplaceAll (ToLower Peer.ID) "." "_" }}
589+
`

0 commit comments

Comments
 (0)