Skip to content

Commit 8706546

Browse files
committed
Fixes, updates and refactor.
1 parent 744d498 commit 8706546

File tree

122 files changed

+2270
-681
lines changed

Some content is hidden

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

122 files changed

+2270
-681
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ before_script:
55
- mv ../../Strabox ../../strabox
66
script:
77
# Build the project
8-
- make build
9-
# Test the project
10-
- make test
8+
- make
9+
# Run the default/example simulation
10+
- make simulate
1111
notifications:
1212
on_success: change
1313
on_failure: change

Gopkg.lock

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

Gopkg.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
[[constraint]]
4141
name = "github.com/strabox/caravela"
42-
version = "0.1.0"
42+
version = "0.2.1"
4343

4444
[prune]
4545
go-tests = true

Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ GOCMD=go
55
GOBUILD=$(GOCMD) build
66
GOINSTALL=$(GOCMD) install
77
GOCLEAN=$(GOCMD) clean
8+
GOTEST=$(GOCMD) test
89

910
############ Output Files ###########
1011
EXE=.exe
1112
BINARY_NAME=caravela_sim$(EXE)
1213

1314
########################## COMMANDS ############################
1415

15-
all: build
16+
all: test build
1617

1718
build:
1819
@echo Building for the current machine settings...
@@ -28,6 +29,9 @@ install:
2829
$(GOINSTALL) -v -gcflags "-N -l" .
2930

3031
test:
31-
@echo Testing CARAVELA-SIM...
32-
$(BINARY_NAME) start
32+
@echo Testing...
33+
$(GOTEST) -v ./...
3334

35+
simulate:
36+
@echo Executing default/example simulation
37+
$(BINARY_NAME) start

cli/cli.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func Run() {
1818
app.Author = author
1919
app.Email = email
2020

21+
// Global Flags.
2122
app.Flags = []cli.Flag{
2223
cli.StringFlag{
2324
Name: "log, l",
@@ -31,22 +32,20 @@ func Run() {
3132
},
3233
}
3334

34-
// Before running the user's command
35+
// Before running the user's command.
3536
app.Before = func(context *cli.Context) error {
3637
logger := log.New()
37-
3838
// Set the format of the log text and the place to write
3939
logger.Level = util.LogLevel(context.String("log"))
4040
logger.Formatter = util.LogFormatter(true, true)
41-
log.SetOutput(os.Stdout)
42-
41+
logger.SetOutput(os.Stdout)
4342
util.Init(logger)
4443
return nil
4544
}
4645

4746
app.Commands = commands
4847

49-
// Run the user's command
48+
// Run the user's command.
5049
if err := app.Run(os.Args); err != nil {
5150
log.Fatal(err)
5251
}

configuration.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[Caravela]
22
RefreshingInterval = "30s"
3-
OffersStrategy = "chordDefault"
3+
OffersStrategy = "chord-smart"
44
Simulation = true
55
# Cpu Cores Partitions
66
[[Caravela.CpuCoresPartitions]]

configuration/configuration.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,23 @@ type Configuration struct {
2121
NumberOfNodes int // Number of nodes used in the simulation.
2222
TickInterval duration // Interval between each simulator tick (in simulation time).
2323
MaxTicks int // Maximum number of ticks done by the simulator.
24+
Multithread bool // Used to leverage the multiple cores to speed up the simulation.
25+
RequestFeeder string // Used to feed the simulator with a series of requests.
26+
ResourceGenerator string // Strategy used to generate the resources for each node.
2427
OutDirectoryPath string // Path of the output's directory.
2528
SimulatorLogLevel string // Log's level of the simulator.
2629
CaravelaLogLevel string // Log's level of the CARAVELA's system.
2730
}
2831

29-
// Produces the configuration structure for a basic simulation.
32+
// Default creates the configuration structure for a basic/default simulation.
3033
func Default() *Configuration {
3134
return &Configuration{
3235
NumberOfNodes: 2500,
3336
TickInterval: duration{Duration: 10 * time.Second},
3437
MaxTicks: 15,
38+
Multithread: true,
39+
RequestFeeder: "random",
40+
ResourceGenerator: "partition-based",
3541
OutDirectoryPath: DefaultOutDirectoryPath,
3642
SimulatorLogLevel: DefaultSimLogLevel,
3743
CaravelaLogLevel: "info",
@@ -97,6 +103,18 @@ func (config *Configuration) MaximumTicks() int {
97103
return config.MaxTicks
98104
}
99105

106+
func (config *Configuration) Multithreaded() bool {
107+
return config.Multithread
108+
}
109+
110+
func (config *Configuration) Feeder() string {
111+
return config.RequestFeeder
112+
}
113+
114+
func (config *Configuration) ResourceGen() string {
115+
return config.ResourceGenerator
116+
}
117+
100118
func (config *Configuration) OutputDirectoryPath() string {
101119
return config.OutDirectoryPath
102120
}
@@ -118,6 +136,9 @@ func (config *Configuration) Print() {
118136
util.Log.Infof("#Nodes: %d", config.TotalNumberOfNodes())
119137
util.Log.Infof("Tick Interval: %s", config.TicksInterval().String())
120138
util.Log.Infof("Max Ticks: %d", config.MaximumTicks())
139+
util.Log.Infof("Multithread: %t", config.Multithreaded())
140+
util.Log.Infof("Request Feeder: %s", config.Feeder())
141+
util.Log.Infof("Resource Generator: %s", config.ResourceGen())
121142
util.Log.Infof("Output directory: %s", config.OutputDirectoryPath())
122143
util.Log.Infof("Sim's log level: %s", config.SimulatorLogsLevel())
123144
util.Log.Infof("CARAVELA's log level: %s", config.CaravelaLogsLevel())

features.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
snapshot metrics in memory -> disc [some work]
2+
single-thread->multithread (speedup simulation 2x + added realism and request concurrency) [much work to handle multiple requests and track their metrics]
3+
requests feeder programmatically, from files whatever [a bit of work]
Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package caravela
22

33
import (
4+
"context"
45
"github.com/strabox/caravela-sim/simulation/metrics"
6+
"github.com/strabox/caravela-sim/util"
57
"github.com/strabox/caravela/api/types"
68
"github.com/strabox/caravela/configuration"
79
)
@@ -25,65 +27,79 @@ func NewRemoteClientMock(nodeService NodeService, metricsCollector *metrics.Coll
2527
// = CARAVELA's Remote Client Interface =
2628
// ===============================================================================
2729

28-
func (mock *RemoteClientMock) CreateOffer(fromSupp *types.Node, toTrader *types.Node,
30+
func (mock *RemoteClientMock) CreateOffer(ctx context.Context, fromSupp *types.Node, toTrader *types.Node,
2931
offer *types.Offer) error {
3032

3133
node, nodeIndex := mock.nodeService.NodeByGUID(toTrader.GUID)
34+
35+
// Collect Metrics
3236
mock.collector.APIRequestReceived(nodeIndex)
3337

34-
node.CreateOffer(fromSupp, toTrader, offer)
38+
node.CreateOffer(ctx, fromSupp, toTrader, offer)
3539
return nil
3640
}
3741

38-
func (mock *RemoteClientMock) RefreshOffer(fromTrader, toSupp *types.Node, offer *types.Offer) (bool, error) {
42+
func (mock *RemoteClientMock) RefreshOffer(ctx context.Context, fromTrader, toSupp *types.Node, offer *types.Offer) (bool, error) {
3943
node, nodeIndex := mock.nodeService.NodeByIP(toSupp.IP)
44+
45+
// Collect Metrics
4046
mock.collector.APIRequestReceived(nodeIndex)
4147

42-
return node.RefreshOffer(fromTrader, offer), nil
48+
return node.RefreshOffer(ctx, fromTrader, offer), nil
4349
}
4450

45-
func (mock *RemoteClientMock) RemoveOffer(fromSupp, toTrader *types.Node, offer *types.Offer) error {
51+
func (mock *RemoteClientMock) RemoveOffer(ctx context.Context, fromSupp, toTrader *types.Node, offer *types.Offer) error {
4652
node, nodeIndex := mock.nodeService.NodeByGUID(toTrader.GUID)
53+
54+
// Collect Metrics
4755
mock.collector.APIRequestReceived(nodeIndex)
4856

49-
node.RemoveOffer(fromSupp, toTrader, offer)
57+
node.RemoveOffer(ctx, fromSupp, toTrader, offer)
5058
return nil
5159
}
5260

53-
func (mock *RemoteClientMock) GetOffers(fromNode, toTrader *types.Node, relay bool) ([]types.AvailableOffer, error) {
61+
func (mock *RemoteClientMock) GetOffers(ctx context.Context, fromNode, toTrader *types.Node, relay bool) ([]types.AvailableOffer, error) {
5462
node, nodeIndex := mock.nodeService.NodeByGUID(toTrader.GUID)
55-
mock.collector.IncrMessagesTradedRequest(1)
63+
64+
// Collect Metrics
65+
mock.collector.IncrMessagesTradedRequest(ctx.Value(types.RequestCtxKey(util.SimRequestIDKey)).(string), 1)
5666
mock.collector.APIRequestReceived(nodeIndex)
5767

58-
offers := node.GetOffers(fromNode, toTrader, relay)
68+
offers := node.GetOffers(ctx, fromNode, toTrader, relay)
5969
return offers, nil
6070
}
6171

62-
func (mock *RemoteClientMock) AdvertiseOffersNeighbor(fromTrader, toNeighborTrader, traderOffering *types.Node) error {
72+
func (mock *RemoteClientMock) AdvertiseOffersNeighbor(ctx context.Context, fromTrader, toNeighborTrader, traderOffering *types.Node) error {
6373
node, nodeIndex := mock.nodeService.NodeByGUID(toNeighborTrader.GUID)
74+
75+
// Collect Metrics
6476
mock.collector.APIRequestReceived(nodeIndex)
6577

66-
node.AdvertiseOffersNeighbor(fromTrader, toNeighborTrader, traderOffering)
78+
node.AdvertiseOffersNeighbor(ctx, fromTrader, toNeighborTrader, traderOffering)
6779
return nil
6880
}
6981

70-
func (mock *RemoteClientMock) LaunchContainer(fromBuyer, toSupplier *types.Node, offer *types.Offer,
71-
containerConfig *types.ContainerConfig) (*types.ContainerStatus, error) {
82+
func (mock *RemoteClientMock) LaunchContainer(ctx context.Context, fromBuyer, toSupplier *types.Node, offer *types.Offer,
83+
containersConfigs []types.ContainerConfig) ([]types.ContainerStatus, error) {
7284
node, nodeIndex := mock.nodeService.NodeByIP(toSupplier.IP)
73-
mock.collector.IncrMessagesTradedRequest(1)
85+
86+
// Collect Metrics
87+
mock.collector.IncrMessagesTradedRequest(ctx.Value(types.RequestCtxKey(util.SimRequestIDKey)).(string), 1)
7488
mock.collector.APIRequestReceived(nodeIndex)
7589

76-
return node.LaunchContainers(fromBuyer, offer, containerConfig)
90+
return node.LaunchContainers(ctx, fromBuyer, offer, containersConfigs)
7791
}
7892

79-
func (mock *RemoteClientMock) StopLocalContainer(toSupplier *types.Node, containerID string) error {
93+
func (mock *RemoteClientMock) StopLocalContainer(ctx context.Context, toSupplier *types.Node, containerID string) error {
8094
node, nodeIndex := mock.nodeService.NodeByIP(toSupplier.IP)
95+
96+
// Collect Metrics
8197
mock.collector.APIRequestReceived(nodeIndex)
8298

83-
return node.StopLocalContainer(containerID)
99+
return node.StopLocalContainer(ctx, containerID)
84100
}
85101

86-
func (mock *RemoteClientMock) ObtainConfiguration(systemsNode *types.Node) (*configuration.Configuration, error) {
102+
func (mock *RemoteClientMock) ObtainConfiguration(_ context.Context, _ *types.Node) (*configuration.Configuration, error) {
87103
// Do Nothing (Not necessary for the simulation)
88104
return nil, nil
89105
}

mocks/caravela/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func Init(logLevel string) {
2828
// Configuration is a wrapper for obtaining the CARAVELA's configurations structure from the
2929
// default file.
3030
func Configuration() *caravelaConfig.Configuration {
31-
caravelaConfigs, err := caravelaConfig.ReadFromFile(util.RandomIP())
31+
caravelaConfigs, err := caravelaConfig.ReadFromFile(util.RandomIP(), caravelaConfig.DefaultFilePath)
3232
if err != nil {
3333
panic(errors.New("problem reading CARAVELA's config file, error: " + err.Error()))
3434
}

0 commit comments

Comments
 (0)