Skip to content

Commit

Permalink
wip: agents clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Diaz authored and gdiazlo committed Mar 6, 2019
1 parent 7159599 commit d665abd
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 105 deletions.
92 changes: 92 additions & 0 deletions tests/qedmanager
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/usr/bin/env bash

# Copyright 2018 Banco Bilbao Vizcaya Argentaria, S.A.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

certs="$HOME/.ssh"
qed="go run $GOPATH/src/github.com/bbva/qed/main.go"
service="go run $GOPATH/src/github.com/bbva/qed/tests/gossip/test_service.go"


apikey() { echo "--apikey test_key"; }
nodeId() { echo "--node-id ${FUNCNAME[1]}_$1";}
path() { echo "--path $1";}
log() { echo "--log $1";}
keyPath() { echo "--keypath $certs/id_ed25519"; }
httpAddr() { echo "--http-addr 127.0.0.1:88`printf '%02d' $1`"; }
mgmtAddr() { echo "--mgmt-addr 127.0.0.1:87`printf '%02d' $1`"; }
metricsAddr() { echo "--metris-addr 127.0.0.1:86`printf '%02d' $1`";}
raftAddr() { echo "--raft-addr 127.0.0.1:85`printf '%02d' $1`"; }
gossipAddr() { echo "--gossip-addr 127.0.0.1:84`printf '%02d' $1`"; }
joinAddr() { echo "--join-addr 127.0.0.1:8700"; }
gossipJoinAddr() { echo "--gossip-join-addr 127.0.0.1:8400"; }
profiling() { echo "--profiling"; }
cert() { echo "--certificate $certs/server.crt"; }
certKey() { echo "--certificate-key $certs/server.key"; }
tempDir() { mktemp -d -p "/var/tmp"; }

bindAddr() { echo "--bind 127.0.0.1:8`printf '%d%02d' $1 $2`"; }
alertsUrls() { echo "--alertsUrls http://127.0.0.1:8888"; }
qedUrls() { echo "--qedUrls http://127.0.0.1:8800"; }
pubUrls() { echo "--pubUrl http://127.0.0.1:8888"; }

qedLeader() {
dir=`tempDir`
echo $qed `apikey` `path $dir` `nodeId 0` `keyPath` `gossipAddr 0` `log error` `cert` `certKey` `profiling`
}

qedFollower() {
dir=`tempDir`
echo $qed `apikey` `path $dir` `nodeId $1` `keyPath` `gossipAddr $1` `log error` `cert` `certKey` `httpAddr $1` `mgmtAddr $1` `metricsAddr $1` `raftAddr $1` `gossipAddr $1` `joinAddr` `gossipJoinAddr` `cert` `certKey``profiling`
}


agent() {
type=$1; shift;
portIndex=$1; shift
id=$1; shift;
echo $qed agent `alertsUrls` $type `apiKey` `log error` `bindAddr $portIndex $id``gossipJoinAddr` `quedUrls` `pubUrls` `nodeId $id`
}

auditor() {
agent auditor 1 $1
}

monitor() {
agent monitor 2 $1
}

publisher() {
agent publisher 3 $1
}

service() {
echo $service
}

run() {
name=$1; shift;
cmd=$1; shift;
dir=$1; shift;
$cmd 2>&1 > $dir/$name.log &
echo $!
}

x=$1; shift
qedCluster=$1; shift;
monitors=$1; shift;
auditors=$1; shift;
publisers=$1; shift;


61 changes: 7 additions & 54 deletions tests/riot.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,17 @@ import (
"sync"
"time"

chart "github.com/wcharczuk/go-chart"

"github.com/bbva/qed/protocol"
)

var (
endpoint string
apiKey string
wantAdd bool
wantIncremental bool
wantMembership bool
offload bool
charts bool
endpoint string
apiKey string
wantAdd bool
wantIncremental bool
wantMembership bool
offload bool

profiling bool
incrementalDelta int
offset int
Expand All @@ -71,7 +69,6 @@ func init() {

flag.BoolVar(&wantIncremental, "incremental", false, "Execute Incremental benchmark")
flag.BoolVar(&offload, "offload", false, "Perform reads only on %50 of the cluster size (With cluster size 2 reads will be performed only on follower1)")
flag.BoolVar(&charts, "charts", false, "Create charts while executing the benchmarks. Output: graph-$testname.png")
flag.BoolVar(&profiling, "profiling", false, "Enable Go profiling with pprof tool. $ go tool pprof -http : http://localhost:6061 ")

usageDelta := "Specify delta for the IncrementalProof"
Expand Down Expand Up @@ -248,46 +245,6 @@ type axis struct {
x, y []float64
}

func drawChart(m string, a *axis) {
graph := chart.Chart{
XAxis: chart.XAxis{
Name: "Time",
NameStyle: chart.StyleShow(),
Style: chart.StyleShow(),
},
YAxis: chart.YAxis{
Name: "Reqests",
NameStyle: chart.StyleShow(),
Style: chart.StyleShow(),
},
Series: []chart.Series{
chart.ContinuousSeries{
Style: chart.Style{
Show: true,
StrokeColor: chart.GetDefaultColor(0).WithAlpha(64),
FillColor: chart.GetDefaultColor(0).WithAlpha(64),
},

XValues: a.x,
YValues: a.y,
},
},
}

req := fmt.Sprint(numRequests)
file, _ := os.Create("results/graph-" + m + "-" + req + ".png")
defer file.Close()
_ = graph.Render(chart.PNG, file)

}

func chartsData(a *axis, elapsed, reqs float64) *axis {
a.x = append(a.x, elapsed)
a.y = append(a.y, reqs)

return a
}

func summary(message string, numRequestsf, elapsed float64, c *Config) {

fmt.Printf(
Expand Down Expand Up @@ -332,10 +289,6 @@ func stats(c *Config, t Task, message string) {
case t := <-ticker.C:
_ = t
elapsed := time.Now().Sub(start).Seconds()
if charts {
os.Mkdir("results", 0755)
go drawChart(message, chartsData(graph, elapsed, c.counter/elapsed))
}
summaryPerDuration(message, numRequestsf, elapsed, c)
}
}
Expand Down
51 changes: 0 additions & 51 deletions tests/riot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/imdario/mergo"
"github.com/spf13/cobra"
"github.com/spf13/viper"
chart "github.com/wcharczuk/go-chart"

"github.com/bbva/qed/client"
"github.com/bbva/qed/log"
Expand All @@ -45,7 +44,6 @@ type Config struct {

// stress conf
Offload bool
Charts bool
Profiling bool
IncrementalDelta uint
Offset uint
Expand Down Expand Up @@ -112,7 +110,6 @@ func newRiotCommand() *cobra.Command {
f.BoolVarP(&config.Membership, "membership", "m", false, "Benchmark MembershipProof")
f.BoolVar(&config.Incremental, "incremental", false, "Execute Incremental benchmark")
f.BoolVar(&config.Offload, "offload", false, "Perform reads only on %50 of the cluster size (With cluster size 2 reads will be performed only on follower1)")
f.BoolVar(&config.Charts, "charts", false, "Create charts while executing the benchmarks. Output: graph-$testname.png")
f.BoolVar(&config.Profiling, "profiling", false, "Enable Go profiling with pprof tool. $ go tool pprof -http : http://localhost:6061 ")
f.UintVarP(&config.IncrementalDelta, "delta", "d", 1000, "Specify delta for the IncrementalProof")
f.UintVar(&config.NumRequests, "n", 10e4, "Number of requests for the attack")
Expand Down Expand Up @@ -323,32 +320,16 @@ func (a *Attack) CreateFanOut() {
}
}

func chartsData(a *axis, elapsed, reqs float64) *axis {
a.x = append(a.x, elapsed)
a.y = append(a.y, reqs)

return a
}

func setupMetrics(conf Config) {
graph := &axis{}
ticker := time.NewTicker(1 * time.Second)
start := time.Now()
defer ticker.Stop()

if conf.Charts {
if err := os.Mkdir("results", 0755); err != nil {
log.Error("Unable to create `results` folder")
}
}

go func() {
for {
<-ticker.C
elapsed := time.Since(start).Seconds()
if conf.Charts {
go drawChart(conf, chartsData(graph, elapsed, conf.counter/elapsed))
}
summaryPerDuration(conf, elapsed)
}
}()
Expand All @@ -368,35 +349,3 @@ func summaryPerDuration(conf Config, elapsed float64) {
type axis struct {
x, y []float64
}

func drawChart(conf Config, a *axis) {
graph := chart.Chart{
XAxis: chart.XAxis{
Name: "Time",
NameStyle: chart.StyleShow(),
Style: chart.StyleShow(),
},
YAxis: chart.YAxis{
Name: "Reqests",
NameStyle: chart.StyleShow(),
Style: chart.StyleShow(),
},
Series: []chart.Series{
chart.ContinuousSeries{
Style: chart.Style{
Show: true,
StrokeColor: chart.GetDefaultColor(0).WithAlpha(64),
FillColor: chart.GetDefaultColor(0).WithAlpha(64),
},

XValues: a.x,
YValues: a.y,
},
},
}

req := fmt.Sprint(conf.NumRequests)
file, _ := os.Create("results/graph-" + req + ".png")
defer file.Close()
_ = graph.Render(chart.PNG, file)
}

0 comments on commit d665abd

Please sign in to comment.