Skip to content

Commit

Permalink
renamed IndividualStats and made it work with bandwidth
Browse files Browse the repository at this point in the history
  • Loading branch information
ineiti committed Apr 13, 2017
1 parent 8b772ce commit 2a3457f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 16 deletions.
8 changes: 8 additions & 0 deletions simul/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ If you use the `onet.SimulationBFTree`, the following variables are also availab
- Depth - the depth of the tree in levels below the root-node
- Rounds - for how many rounds the simulation should run

### Simulations with long setup-times and multiple measurements

Per default, all rounds of an individual simulation-run will be averaged and
written to the csv-file. If you set `IndividualStats` to a non-`""`-value,
every round will create a new line. This is useful if you have a simulation
with a long setup-time and you want to do multiple measurements for the same
setup.

### Timeouts

Two timeout variables are available:
Expand Down
5 changes: 3 additions & 2 deletions simul/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ func RunTests(name string, runconfigs []*platform.RunConfig) {
if i == 0 {
stats.WriteHeader(f)
}
if strings.ToLower(rc.Get("EveryRoundStats")) == "true" {
stats.WriteValuesEveryRoundStats(f)
if rc.Get("IndividualStats") != "" {
err := stats.WriteIndividualStats(f)
log.ErrFatal(err)
} else {
stats.WriteValues(f)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Servers = 16
Simulation = "Count"
BF = 2
EveryRoundStats = "true"
IndividualStats = "true"

Hosts,Rounds
3, 3
3, 5
10 changes: 5 additions & 5 deletions simul/manage/simulation/simul_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ func TestSimulation(t *testing.T) {
simul.Start("count.toml", "csv1.toml", "csv2.toml")
}

func TestSimulation_EveryRoundStats(t *testing.T) {
simul.Start("everyroundstats.toml")
csv, err := ioutil.ReadFile("test_data/everyroundstats.csv")
func TestSimulation_IndividualStats(t *testing.T) {
simul.Start("individualstats.toml")
csv, err := ioutil.ReadFile("test_data/individualstats.csv")
log.ErrFatal(err)
// header + 3 rounds + final newline
assert.Equal(t, 5, len(strings.Split(string(csv), "\n")))
// header + 5 rounds + final newline
assert.Equal(t, 7, len(strings.Split(string(csv), "\n")))

simul.Start("csv1.toml")
csv, err = ioutil.ReadFile("test_data/csv1.csv")
Expand Down
6 changes: 3 additions & 3 deletions simul/monitor/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ func (s *Stats) WriteValues(w io.Writer) {
fmt.Fprintf(w, "\n")
}

// WriteValuesEveryRoundStats will write the values to the specified writer but without
// WriteIndividualStats will write the values to the specified writer but without
// making averages. Each value should either be:
// - represented once - then it'll be copied to all runs
// - have the same frequency as the other non-once values
func (s *Stats) WriteValuesEveryRoundStats(w io.Writer) error {
func (s *Stats) WriteIndividualStats(w io.Writer) error {
// by default
s.Lock()
defer s.Unlock()
Expand Down Expand Up @@ -505,7 +505,7 @@ func (t *Value) Values() []string {

// SingleValues returns the string representation of an entry in the value
func (t *Value) SingleValues(i int) []string {
v := "NaN"
v := fmt.Sprintf("%f", t.store[0])
if i < len(t.store) {
v = fmt.Sprintf("%f", t.store[i])
}
Expand Down
26 changes: 22 additions & 4 deletions simul/platform/runsimul.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/dedis/onet"
"github.com/dedis/onet/log"

"github.com/BurntSushi/toml"
"github.com/dedis/onet/network"
"github.com/dedis/onet/simul/manage"
"github.com/dedis/onet/simul/monitor"
Expand Down Expand Up @@ -38,20 +39,33 @@ func Simulate(serverAddress, simul, monitorAddress string) error {
// having a waitgroup so the binary stops when all servers are closed
var wgServer, wgSimulInit sync.WaitGroup
var ready = make(chan bool)
measureNodeBW := true
if len(scs) > 0 {
cfg := &conf{}
_, err := toml.Decode(scs[0].Config, cfg)
if err != nil {
return err
}
measureNodeBW = cfg.IndividualStats == ""
}
for i, sc := range scs {
// Starting all servers for that server
server := sc.Server
measures[i] = monitor.NewCounterIOMeasure("bandwidth", server)
log.Lvl3(serverAddress, "Starting server", server.ServerIdentity.Address)
if measureNodeBW {
measures[i] = monitor.NewCounterIOMeasure("bandwidth", server)
}
// Launch a server and notifies when it's done

wgServer.Add(1)
go func(c *onet.Server, m monitor.Measure) {
ready <- true
defer wgServer.Done()
c.Start()
// record bandwidth
m.Record()
// record bandwidth, except if we're measuring every
// round individually
if measureNodeBW {
m.Record()
}
log.Lvl3(serverAddress, "Simulation closed server", c.ServerIdentity)
}(server, measures[i])
// wait to be sure the goroutine started
Expand Down Expand Up @@ -161,3 +175,7 @@ func Simulate(serverAddress, simul, monitorAddress string) error {
}
return nil
}

type conf struct {
IndividualStats string
}

0 comments on commit 2a3457f

Please sign in to comment.