Skip to content

Commit 733565a

Browse files
committed
Update.
1 parent 205ea8f commit 733565a

File tree

5 files changed

+58
-27
lines changed

5 files changed

+58
-27
lines changed

cli/init_node.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ func initNode(hostIP, configFilePath string, join bool, joinIP string) error {
4444
// Print/log the systemConfigurations values
4545
systemConfigurations.Print()
4646

47-
// Global GUID size initialization
48-
guid.Init(systemConfigurations.ChordHashSizeBits())
47+
// GUID package custom initialization.
48+
guid.Init(systemConfigurations.ChordHashSizeBits(), int64(systemConfigurations.GUIDEstimatedNetworkSize()),
49+
int64(systemConfigurations.GUIDScaleFactor()))
4950

5051
// Create Overlay Component
5152
overlayConfigured := overlay.Create(systemConfigurations)
@@ -59,7 +60,7 @@ func initNode(hostIP, configFilePath string, join bool, joinIP string) error {
5960
// Create the API server
6061
apiServer := rest.NewServer(systemConfigurations.APIPort())
6162

62-
// Create a CARAVELA Node passing all the external components and start it functions
63+
// Create a Caravela's Node passing all the external components and start its functions.
6364
thisNode := node.NewNode(systemConfigurations, overlayConfigured, caravelaCli, dockerClient, apiServer)
6465

6566
err = thisNode.Start(join, joinIP)

configuration.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ Backend = "chord-single-offer"
1010
[Caravela.DiscoveryBackend.OfferingChordBackend]
1111
SupplyingInterval = "1m"
1212
SpreadOffersInterval = "1m"
13-
RefreshesCheckInterval = "1m30s"
14-
RefreshingInterval = "1m"
13+
RefreshingInterval = "5m"
14+
RefreshesCheckInterval = "5m30s"
15+
RefreshMissedTimeout = "1m"
1516
MaxRefreshesFailed = 3
1617
MaxRefreshesMissed = 2
17-
RefreshMissedTimeout = "1m30s"
1818
[Caravela.DiscoveryBackend.RandomChordBackend]
1919
RandBackendMaxRetries = 3
2020
[Caravela.Resources]

configuration/configuration.go

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ type offeringChordDiscBackend struct {
6969
MaxRefreshesFailed int `json:"MaxRefreshesFailed"` // Maximum amount of refreshes that a supplier failed to reply
7070
MaxRefreshesMissed int `json:"MaxRefreshesMissed"` // Maximum amount of refreshes a trader failed to send to the supplier
7171
// Debug performance flags
72-
SpreadOffers bool `json:"SpreadOffers"` // Used to tell if the spread offers mechanism is used or not.
73-
SpreadPartitionsState bool `json:"SpreadPartitionsState"` // Used to tell if the spread partitions state is used or not.
72+
SpreadOffers bool `json:"SpreadOffers"` // Used to tell if the spread offers mechanism is used or not.
73+
SpreadPartitionsState bool `json:"SpreadPartitionsState"` // Used to tell if the spread partitions state is used or not.
74+
GUIDEstimatedNetworkSize int `json:"GUIDEstimatedNetworkSize"` // Estimated network size to tune the GUID scale.
75+
GUIDScaleFactor int `json:"GUIDScaleFactor"` // GUID scale's factor.
7476
}
7577

7678
type randomChordDiscBackend struct {
@@ -132,8 +134,10 @@ func Default(hostIP string) *Configuration {
132134
MaxRefreshesMissed: 2,
133135
RefreshMissedTimeout: duration{Duration: refreshingInterval.Duration + (5 * time.Second)},
134136
// Debug performance flags
135-
SpreadOffers: true,
136-
SpreadPartitionsState: true,
137+
SpreadOffers: true,
138+
SpreadPartitionsState: true,
139+
GUIDEstimatedNetworkSize: 50000,
140+
GUIDScaleFactor: 5,
137141
},
138142
RandomChordBackend: randomChordDiscBackend{
139143
RandBackendMaxRetries: 6,
@@ -271,6 +275,14 @@ func (c *Configuration) validate() error {
271275
return fmt.Errorf("maximum number of missed refreshes must be a positive integer")
272276
}
273277

278+
if c.GUIDEstimatedNetworkSize() <= 0 {
279+
return fmt.Errorf("estimated network size must a positive integer")
280+
}
281+
282+
if c.GUIDScaleFactor() <= 0 {
283+
return fmt.Errorf("GUID scale factor must a positive integer")
284+
}
285+
274286
// ======================= Random Chord Discovery Backend specific ==========================
275287

276288
if c.RandBackendMaxRetries() <= 0 {
@@ -316,7 +328,7 @@ func (c *Configuration) Print() {
316328
log.Printf("Messages Timeout: %s", c.APITimeout().String())
317329
log.Printf("CPU Slices: %d", c.CPUSlices())
318330
log.Printf("CPU Overcommit: %d", c.CPUOvercommit())
319-
log.Printf("Memory Overcommit: %d", c.MemoryOvercommit())
331+
log.Printf("Memory Overcommit: %d", c.MemoryOvercommit())
320332
log.Printf("Scheduling Policy: %s", c.SchedulingPolicy())
321333
log.Printf("FreeResources Partitions:")
322334
for _, powerPart := range c.Caravela.Resources.CPUClasses {
@@ -341,8 +353,11 @@ func (c *Configuration) Print() {
341353
log.Printf(" Refresh missed timeout: %s", c.RefreshMissedTimeout().String())
342354
log.Printf(" Max num of refreshes failed: %d", c.MaxRefreshesFailed())
343355
log.Printf(" Max num of refreshes missed: %d", c.MaxRefreshesMissed())
356+
// Debug performance flags.
344357
log.Printf(" Spread Offers: %t", c.SpreadOffers())
345358
log.Printf(" Spread Partitions State: %t", c.SpreadPartitionsState())
359+
log.Printf(" GUID Estimated Network Size: %d", c.GUIDEstimatedNetworkSize())
360+
log.Printf(" GUID Scale Factor: %d", c.GUIDScaleFactor())
346361

347362
log.Printf("$$$$$$$$$$$$$$$$$$$$$$$ IMAGES STORAGE $$$$$$$$$$$$$$$$$$$$$$$$$$$")
348363
log.Printf("Active Storage Backend: %s", c.ImagesStorageBackend())
@@ -440,14 +455,26 @@ func (c *Configuration) RefreshMissedTimeout() time.Duration {
440455
return c.Caravela.DiscoveryBackend.OfferingChordBackend.RefreshMissedTimeout.Duration
441456
}
442457

458+
// Debug performance flag.
443459
func (c *Configuration) SpreadOffers() bool {
444460
return c.Caravela.DiscoveryBackend.OfferingChordBackend.SpreadOffers
445461
}
446462

463+
// Debug performance flag.
447464
func (c *Configuration) SpreadPartitionsState() bool {
448465
return c.Caravela.DiscoveryBackend.OfferingChordBackend.SpreadPartitionsState
449466
}
450467

468+
// Debug performance flag.
469+
func (c *Configuration) GUIDEstimatedNetworkSize() int {
470+
return c.Caravela.DiscoveryBackend.OfferingChordBackend.GUIDEstimatedNetworkSize
471+
}
472+
473+
// Debug performance flag.
474+
func (c *Configuration) GUIDScaleFactor() int {
475+
return c.Caravela.DiscoveryBackend.OfferingChordBackend.GUIDScaleFactor
476+
}
477+
451478
// =================== Random Chord Discovery Backend specific ==============
452479

453480
func (c *Configuration) RandBackendMaxRetries() int {

node/common/guid/guid.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,27 @@ var isGUIDInitialized = false
1818
// 160-bits default (To maintain compatibility with used chord overlay implementation)
1919
var guidSizeBits = 160
2020

21+
// ...
22+
var scaleGUIDStep *big.Int = nil
23+
2124
// GUID represents a Global Unique Identifier (GUID) for a system's node
2225
type GUID struct {
2326
id *big.Int
2427
}
2528

2629
// Init initializes the GUID package with the size of the GUID.
27-
func Init(guidBitsSize int) {
30+
func Init(guidBitsSize int, estimatedGUIDs, scaleFactor int64) {
2831
if !isGUIDInitialized {
32+
// Initialize the GUID size.
2933
guidSizeBits = guidBitsSize
3034
isGUIDInitialized = true
35+
36+
// Initialize the GUID scale step.
37+
maxGUID := MaximumGUID()
38+
tempBigInt := big.NewInt(0)
39+
tempBigInt.Div(maxGUID.id, big.NewInt(estimatedGUIDs))
40+
tempBigInt.Mul(tempBigInt, big.NewInt(scaleFactor))
41+
scaleGUIDStep = tempBigInt
3142
}
3243
}
3344

@@ -105,27 +116,19 @@ func newGUIDBigInt(bytesID *big.Int) *GUID {
105116
return guid
106117
}
107118

108-
func scaleWindow() *big.Int {
109-
maxGUID := MaximumGUID()
110-
111-
tempBigInt := big.NewInt(0)
112-
tempBigInt.Div(maxGUID.id, big.NewInt(10000))
113-
tempBigInt.Mul(tempBigInt, big.NewInt(5))
114-
115-
return tempBigInt
116-
}
117-
118-
// GenerateInnerRandomGUIDV2 ...
119-
func (g *GUID) GenerateInnerRandomGUIDV2(topGUID GUID) (*GUID, error) {
119+
// GenerateInnerRandomGUIDScaled generates a random GUID that belongs to the interval [this, topGUID).
120+
// But it returns one of a specific set of GUIDs from the interval. This set is small than the total GUIDs of
121+
// the interval.
122+
func (g *GUID) GenerateInnerRandomGUIDScaled(topGUID GUID) (*GUID, error) {
120123
dif := big.NewInt(0)
121124

122125
dif.Sub(topGUID.id, g.id)
123126

124-
dif.Div(dif, scaleWindow())
127+
dif.Div(dif, scaleGUIDStep)
125128

126129
dif.Rand(randomGenerator, dif)
127130

128-
dif.Mul(dif, scaleWindow())
131+
dif.Mul(dif, scaleGUIDStep)
129132

130133
dif.Add(g.id, dif)
131134

node/common/guid/range.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func NewGUIDRange(lowerGUID GUID, higherGUID GUID) *Range {
2020

2121
// GenerateRandom generate random GUID inside the range.
2222
func (r *Range) GenerateRandom() (*GUID, error) {
23-
return r.lowerGUID.GenerateInnerRandomGUIDV2(*r.higherGUID)
23+
return r.lowerGUID.GenerateInnerRandomGUIDScaled(*r.higherGUID)
2424
}
2525

2626
// CreatePartitions returns partitions, set of ranges, of the receiver range.

0 commit comments

Comments
 (0)