Skip to content

Commit ed380d2

Browse files
committed
Fixes, updates and refactor.
1 parent e65cf24 commit ed380d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1270
-185
lines changed

Gopkg.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configuration.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ SchedulingPolicy = "binpack"
99
SpreadOffersInterval = "2m30s"
1010
RefreshingInterval = "7m30s"
1111
# Debug performance flags
12-
SpreadOffers = true
13-
SpreadPartitionsState = true
12+
SpreadOffers = false
13+
SpreadPartitionsState = false
1414
PartitionsStateBufferSize = 10
15-
PseudoSuperPeers = true
15+
PseudoSuperPeers = false
1616
GUIDEstimatedNetworkSize = 20000
1717
GUIDScaleFactor = 5
1818
[Caravela.DiscoveryBackend.RandomChordBackend]

engine/engine.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
// engineLogTag log's tag for the simulator engine.
2222
const engineLogTag = "ENGINE"
2323

24+
const numOfRandomBagsOfNode = 20
25+
2426
// Engine represents an instance of a Caravela's simulator engine.
2527
// It holds all the structures to control, feed and analyse a engine during a simulation.
2628
type Engine struct {
@@ -54,7 +56,7 @@ func NewEngine(metricsCollector *metrics.Collector, simConfig *configuration.Con
5456
nodes: make([]*caravelaNode.Node, simConfig.TotalNumberOfNodes()),
5557
overlayMock: nil,
5658
feeder: feeder.Create(simConfig, caravelaConfigurations, baseRngSeed),
57-
nodesBags: make([][]*caravelaNode.Node, 10),
59+
nodesBags: make([][]*caravelaNode.Node, numOfRandomBagsOfNode),
5860

5961
metricsCollector: metricsCollector,
6062
workersPool: grpool.NewPool(maxWorkers, maxWorkers*30),
@@ -107,7 +109,8 @@ func (e *Engine) Init() {
107109
// Initialize metric's collector.
108110
maxNodesResources := make([]types.Resources, e.simulatorConfigs.TotalNumberOfNodes())
109111
for i := range maxNodesResources {
110-
maxNodesResources[i] = e.nodes[i].MaximumResourcesSim()
112+
_, nodeMaxResources, _ := e.nodes[i].NodeInformationSim()
113+
maxNodesResources[i] = nodeMaxResources
111114
}
112115
e.metricsCollector.InitNewSimulation(e.caravelaConfigs.DiscoveryBackend(), maxNodesResources)
113116

@@ -122,7 +125,7 @@ func (e *Engine) Init() {
122125
allNodes[i] = i
123126
}
124127
for i := range e.nodesBags {
125-
e.nodesBags[i] = make([]*caravelaNode.Node, e.simulatorConfigs.TotalNumberOfNodes()/10)
128+
e.nodesBags[i] = make([]*caravelaNode.Node, e.simulatorConfigs.TotalNumberOfNodes()/numOfRandomBagsOfNode)
126129
for j := range e.nodesBags[i] {
127130
randIndex := util.RandomInteger(0, len(allNodes)-1)
128131
e.nodesBags[i][j] = e.nodes[allNodes[randIndex]]
@@ -136,7 +139,7 @@ func (e *Engine) Init() {
136139

137140
// Start starts the simulator engine.
138141
func (e *Engine) Start() {
139-
const ticksPerPersist = 5
142+
const ticksPerSnapshot = 5
140143

141144
if !e.isInit {
142145
panic(errors.New("simulator is not initialized"))
@@ -175,11 +178,9 @@ func (e *Engine) Start() {
175178
break
176179
}
177180

178-
if numTicks != 0 && (numTicks%ticksPerPersist) == 0 {
181+
if numTicks != 0 && (numTicks%ticksPerSnapshot) == 0 {
179182
e.metricsCollector.Persist(simCurrentTime)
180-
continue
181183
}
182-
e.metricsCollector.CreateNewGlobalSnapshot(simCurrentTime)
183184
}
184185

185186
close(ticksChan) // Alert feeder that the engine has ended.
@@ -266,7 +267,7 @@ func (e *Engine) fireTimerActions(currentTime time.Duration, lastTimeRefreshes,
266267
return lastTimeRefreshes, lastTimeSpreadOffers
267268
}
268269

269-
// updateMetrics updates all the collector metrics.
270+
// updateMetrics updates all the collector's metrics.
270271
func (e *Engine) updateMetrics() {
271272
defer e.workersPool.WaitAll()
272273

@@ -277,10 +278,9 @@ func (e *Engine) updateMetrics() {
277278
e.workersPool.WaitCount(1)
278279
e.workersPool.JobQueue <- func() {
279280
defer e.workersPool.JobDone()
280-
nodeFreeResources := tempNode.AvailableResourcesSim()
281-
nodeMaxResources := tempNode.MaximumResourcesSim()
281+
nodeFreeResources, nodeMaxResources, numActiveOffers := tempNode.NodeInformationSim()
282282
e.assertNodeState(nodeFreeResources, nodeMaxResources)
283-
e.metricsCollector.SetAvailableNodeResources(tempI, nodeFreeResources)
283+
e.metricsCollector.SetNodeInformation(tempI, nodeFreeResources, numActiveOffers)
284284
}
285285
}
286286
}
@@ -336,20 +336,16 @@ func (e *Engine) nextRngSeed() int64 {
336336

337337
func (e *Engine) assertNodeState(freeResources, maximumResources types.Resources) {
338338
if freeResources.CPUs < 0 {
339-
util.Log.Error("ASDDDDDDDDDDDDDD")
340339
panic(errors.New("negative free CPUs"))
341340
}
342341
if freeResources.Memory < 0 {
343-
util.Log.Error("ASDDDDasdasdDDDDDDDDDD")
344342
panic(errors.New("negative free Memory"))
345343
}
346344

347345
if freeResources.CPUs > maximumResources.CPUs {
348-
util.Log.Error("ASDDDDDDDDDDDDDDasdasdadasd")
349346
panic(errors.New("over free CPUs"))
350347
}
351348
if freeResources.Memory > maximumResources.Memory {
352-
util.Log.Error("ASDDDDDDDDDDDDDDjkadlkasdkadslk")
353349
panic(errors.New("over free Memory"))
354350
}
355351
}

engine/metrics/collector.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ func (coll *Collector) InitNewSimulation(simLabel string, nodesMaxRes []types.Re
8484

8585
// ================================= Metrics Collector Methods ====================================
8686

87+
func (coll *Collector) IncrChordMessages(amount int64) {
88+
if activeGlobal, err := coll.activeGlobal(); err == nil {
89+
activeGlobal.IncrChordMessages(amount)
90+
}
91+
}
92+
8793
// GetOfferRelayed increment the number of messages traded from type GetOffersRelayed.
8894
func (coll *Collector) GetOfferRelayed(amount int64) {
8995
if activeGlobal, err := coll.activeGlobal(); err == nil {
@@ -111,10 +117,10 @@ func (coll *Collector) APIRequestReceived(nodeIndex int) {
111117
}
112118
}
113119

114-
// SetAvailableNodeResources sets the available resources of a node.
115-
func (coll *Collector) SetAvailableNodeResources(nodeIndex int, res types.Resources) {
120+
// SetNodeInformation sets the available resources of a node.
121+
func (coll *Collector) SetNodeInformation(nodeIndex int, freeResources types.Resources, numActiveOffers int) {
116122
if activeGlobal, err := coll.activeGlobal(); err == nil {
117-
activeGlobal.SetAvailableNodeResources(nodeIndex, res)
123+
activeGlobal.SetAvailableNodeResources(nodeIndex, freeResources)
118124
}
119125
}
120126

@@ -288,7 +294,7 @@ func (coll *Collector) plotGraphics() {
288294

289295
goroutinePool.WaitCount(1)
290296
goroutinePool.JobQueue <- func() {
291-
coll.plotMessagesTraderByRequestBoxPlots()
297+
coll.plotMessagesExchangedByRequestBoxPlots()
292298
goroutinePool.JobDone()
293299
}
294300

engine/metrics/collector_plots.go

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66
"github.com/strabox/caravela-sim/engine/metrics/graphics"
7+
"github.com/strabox/caravela-sim/util"
78
"gonum.org/v1/gonum/mat"
89
"gonum.org/v1/plot/palette"
910
"gonum.org/v1/plot/plotter"
@@ -96,24 +97,24 @@ func (coll *Collector) plotSystemFreeResourcesVSRequestSuccess() {
9697
}
9798
}
9899

99-
func (coll *Collector) plotMessagesTraderByRequestBoxPlots() {
100-
plotRes := graphics.NewPlot("Lookup Messages Traded Distribution", "", "#Messages", false)
101-
102-
dataPoints := make([]interface{}, 0)
100+
func (coll *Collector) plotMessagesExchangedByRequestBoxPlots() {
103101
for _, simData := range coll.simulations {
104-
boxPoints := make(plotter.Values, 0)
102+
plotRes := graphics.NewPlot(fmt.Sprintf("Lookup Messages Traded Distribution (%s)", simData.label), "", "#Messages", false)
103+
104+
dataPoints := make([]interface{}, 0)
105+
boxPlotPoints := make(plotter.Values, 0)
105106
for _, snapshot := range simData.snapshots {
106-
boxPoints = append(boxPoints, snapshot.MessagesExchangedByRequest()...)
107+
boxPlotPoints = append(boxPlotPoints, snapshot.MessagesExchangedByRequest()...)
108+
dataPoints = append(dataPoints, util.FmtDuration(snapshot.EndTime()), boxPlotPoints)
107109
}
108-
dataPoints = append(dataPoints, simData.label, boxPoints)
109-
}
110110

111-
err := plotutil.AddBoxPlots(plotRes, vg.Points(55), dataPoints...)
112-
if err != nil {
113-
panic(errors.New("Problem with plots, error: " + err.Error()))
114-
}
111+
err := plotutil.AddBoxPlots(plotRes, vg.Points(20), dataPoints...)
112+
if err != nil {
113+
panic(errors.New("Problem with plots, error: " + err.Error()))
114+
}
115115

116-
graphics.Save(plotRes, 15*vg.Centimeter, 15*vg.Centimeter, generatePNGFileName(coll.outputDirPath, "MessagesDistribution"))
116+
graphics.Save(plotRes, 35*vg.Centimeter, 12*vg.Centimeter, generatePNGFileName(coll.outputDirPath, "MessagesDistribution_"+simData.label))
117+
}
117118
}
118119

119120
func (coll *Collector) plotResourcesUsedDistributionByNodesOverTime() {
@@ -134,8 +135,9 @@ func (coll *Collector) plotResourcesUsedDistributionByNodesOverTime() {
134135

135136
dataGrid := &graphics.UnitGrid{Data: mat.NewDense(len(simData.snapshots), coll.numNodes, data)}
136137

137-
graphics.NewHeatMap(generatePNGFileName("ResourcesUsedDistribution_"+simData.label), fmt.Sprintf("Resources Used Distribution (%s)", simData.label),
138-
"Nodes", "Time (Seconds)", coll.outputDirPath, yTicks, dataGrid, palette.Heat(64, 1))
138+
graphics.NewHeatMap(generatePNGFileName(coll.outputDirPath, "ResourcesUsedDistribution_"+simData.label),
139+
fmt.Sprintf("Resources Used Distribution (%s)", simData.label),
140+
"Nodes", "Time (Seconds)", yTicks, dataGrid, palette.Heat(64, 1))
139141
}
140142
}
141143

@@ -157,8 +159,9 @@ func (coll *Collector) plotResourcesUnreachableDistributionByNodesOverTime() {
157159

158160
dataGrid := &graphics.UnitGrid{Data: mat.NewDense(len(simData.snapshots), coll.numNodes, data)}
159161

160-
graphics.NewHeatMap(generatePNGFileName("ResourcesUnreachableDistribution_"+simData.label), fmt.Sprintf("Resources Unreachable Distribution (%s)", simData.label),
161-
"Nodes", "Time (Seconds)", coll.outputDirPath, yTicks, dataGrid, palette.Heat(64, 1))
162+
graphics.NewHeatMap(generatePNGFileName(coll.outputDirPath, "ResourcesUnreachableDistribution_"+simData.label),
163+
fmt.Sprintf("Resources Unreachable Distribution (%s)", simData.label),
164+
"Nodes", "Time (Seconds)", yTicks, dataGrid, palette.Heat(64, 1))
162165
}
163166
}
164167

@@ -180,8 +183,9 @@ func (coll *Collector) plotMessagesAPIDistributionByNodesOverTime() {
180183

181184
dataGrid := &graphics.UnitGrid{Data: mat.NewDense(len(simData.snapshots), coll.numNodes, data)}
182185

183-
graphics.NewHeatMap(generatePNGFileName("MessagesAPIDistribution_"+simData.label), fmt.Sprintf("Messages Distribution (%s)", simData.label),
184-
"Nodes", "Time (Seconds)", coll.outputDirPath, yTicks, dataGrid, palette.Heat(64, 1))
186+
graphics.NewHeatMap(generatePNGFileName(coll.outputDirPath, "MessagesAPIDistribution_"+simData.label),
187+
fmt.Sprintf("Messages Distribution (%s)", simData.label),
188+
"Nodes", "Time (Seconds)", yTicks, dataGrid, palette.Heat(64, 1))
185189
}
186190
}
187191

@@ -195,7 +199,7 @@ func (coll *Collector) plotTotalMessagesTradedInSystem() {
195199
for i, simData := range coll.simulations {
196200
messagesTradedAcc := float64(0)
197201
for _, snapshot := range simData.snapshots {
198-
messagesTradedAcc += snapshot.TotalAPIMessagesReceivedByAllNodes()
202+
messagesTradedAcc += snapshot.TotalMessagesReceivedByAllNodes()
199203
}
200204

201205
barChart, err := plotter.NewBarChart(plotter.Values{messagesTradedAcc}, barWidth)
@@ -217,7 +221,7 @@ func (coll *Collector) plotTotalMessagesTradedInSystem() {
217221
plotRes.Legend.Top = true
218222
plotRes.NominalX("Main Simulation")
219223

220-
graphics.Save(plotRes, 15*vg.Centimeter, 15*vg.Centimeter, generatePNGFileName(coll.outputDirPath, "MessagesTradedInSystem"))
224+
graphics.Save(plotRes, 10*vg.Centimeter, 12*vg.Centimeter, generatePNGFileName(coll.outputDirPath, "MessagesTradedInSystem"))
221225
}
222226

223227
// ======================================= Debug Performance Plots ===============================

engine/metrics/global.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package metrics
22

33
import (
4-
"github.com/strabox/caravela-sim/util"
54
"github.com/strabox/caravela/api/types"
65
"sync"
76
"sync/atomic"
@@ -15,6 +14,7 @@ type Global struct {
1514

1615
RunRequestsSucceeded int64 `json:"RunRequestsSucceeded"` // Number of run requests that were successful deployed.
1716
NodesMetrics []Node `json:"NodesMetrics"` // Metrics collected for each system's node.
17+
ChordMessagesTraded int64 `json:"ChordMessagesTraded"`
1818

1919
RunRequestsAggregator sync.Map `json:"-"`
2020
RunRequestsCompleted []RunRequest `json:"RunRequestsCompleted"`
@@ -69,6 +69,10 @@ func NewGlobalNext(numNodes int, prevGlobal *Global) *Global {
6969

7070
// ========================= Metrics Collector Methods ====================================
7171

72+
func (g *Global) IncrChordMessages(amount int64) {
73+
atomic.AddInt64(&g.ChordMessagesTraded, amount)
74+
}
75+
7276
func (g *Global) GetOfferRelayed(amount int64) {
7377
atomic.AddInt64(&g.GetOffersRelayed, amount)
7478
}
@@ -166,10 +170,6 @@ func (g *Global) ResourcesUsedNodeRatio() []float64 {
166170
res := make([]float64, len(g.NodesMetrics))
167171
for i, nodeMetric := range g.NodesMetrics {
168172
res[i] = nodeMetric.UsedResourcesRatio()
169-
if res[i] < 0 {
170-
util.Log.Errorf("NodeIndex: %d, Max: <%d;%d>, Free: <%d;%d>, Used: <%d;%d>", i, nodeMetric.MaxResources.CPUs, nodeMetric.MaxResources.Memory,
171-
nodeMetric.FreeRes.CPUs, nodeMetric.FreeRes.Memory, nodeMetric.UsedResources().CPUs, nodeMetric.UsedResources().Memory)
172-
}
173173
}
174174
return res
175175
}
@@ -190,6 +190,15 @@ func (g *Global) TotalAPIMessagesReceivedByAllNodes() float64 {
190190
return float64(acc)
191191
}
192192

193+
func (g *Global) TotalMessagesReceivedByAllNodes() float64 {
194+
acc := int64(0)
195+
for _, nodeMetric := range g.NodesMetrics {
196+
acc += nodeMetric.TotalAPIRequestsReceived()
197+
}
198+
acc += g.ChordMessagesTraded
199+
return float64(acc)
200+
}
201+
193202
// ================================= Getters and Setters =================================
194203

195204
func (g *Global) StartTime() time.Duration {
@@ -204,6 +213,10 @@ func (g *Global) SetEndTime(endTime time.Duration) {
204213
g.End = endTime
205214
}
206215

216+
func (g *Global) TotalChordMessages() int64 {
217+
return g.ChordMessagesTraded
218+
}
219+
207220
func (g *Global) TotalGetOffersRelayed() int64 {
208221
return g.GetOffersRelayed
209222
}

engine/metrics/graphics/heat_map.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ import (
1313
"log"
1414
"math"
1515
"os"
16-
"path/filepath"
1716
)
1817

19-
func NewHeatMap(fileName, title, XLabel, YLabel, outputDirPath string, yTicks []int, grid *UnitGrid, colorPalette palette.Palette) {
18+
func NewHeatMap(fileName, title, XLabel, YLabel string, yTicks []int, grid *UnitGrid, colorPalette palette.Palette) {
2019
heatMap := plotter.NewHeatMap(grid, colorPalette)
2120

2221
plotRes := NewPlot(title, XLabel, YLabel, false)
@@ -50,7 +49,7 @@ func NewHeatMap(fileName, title, XLabel, YLabel, outputDirPath string, yTicks []
5049
plotRes.X.Max = 1.5
5150
plotRes.Y.Max = 1.5
5251

53-
img := vgimg.New(2550, 1640)
52+
img := vgimg.New(1850, 940)
5453
dc := draw.New(img)
5554

5655
legend.Top = true
@@ -63,7 +62,7 @@ func NewHeatMap(fileName, title, XLabel, YLabel, outputDirPath string, yTicks []
6362
dc = draw.Crop(dc, 0, -legendWidth-vg.Millimeter, 0, 0) // Make space for the legend.
6463
plotRes.Draw(dc)
6564

66-
w, err := os.Create(filepath.Join(outputDirPath, fileName))
65+
w, err := os.Create(fileName)
6766
if err != nil {
6867
log.Panic(err)
6968
}

0 commit comments

Comments
 (0)