Last active
December 10, 2021 12:14
-
-
Save samueleresca/3a6a9f0a077ff699bf7afd996db28cd0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (qs QuorumSystem) loadOptimalStrategy( | |
optimize OptimizeType, | |
readQuorums []ExprSet, | |
writeQuorums []ExprSet, | |
readFraction DistributionValues, | |
loadLimit *float64, | |
networkLimit *float64, | |
latencyLimit *float64) (*Strategy, error) { | |
... | |
buildLatencyDef := func(latencyLimit *float64) (lpDefinition, error) { | |
def := newDefinitionWithVarsAndConstraints(readQuorumVars, writeQuorumVars) | |
// building latency objs | -inf <= latency_def <= inf | |
objExpr := make([]float64, len(def.Vars)) | |
for _, v := range readQuorumVars { | |
nodes := make([]Node, 0) | |
for x := range v.Quorum { | |
q := qs.GetNodeByName(x.String()) | |
nodes = append(nodes, q) | |
} | |
l, err := qs.readQuorumLatency(nodes) | |
if err != nil { | |
return lpDefinition{}, fmt.Errorf("error on readQuorumLatency %s", err) | |
} | |
objExpr[v.Index] = fr * v.Value * float64(l) | |
} | |
for _, v := range writeQuorumVars { | |
nodes := make([]Node, 0) | |
for x := range v.Quorum { | |
q := qs.GetNodeByName(x.String()) | |
nodes = append(nodes, q) | |
} | |
l, err := qs.writeQuorumLatency(nodes) | |
if err != nil { | |
return lpDefinition{}, fmt.Errorf("error on writeQuorumLatency %s", err) | |
} | |
objExpr[v.Index] = (1 - fr) * v.Value * float64(l) | |
} | |
objExpr = append([]float64{ninf}, objExpr...) | |
if latencyLimit == nil { | |
objExpr = append(objExpr, pinf) | |
} else { | |
objExpr = append(objExpr, *latencyLimit) | |
} | |
def.Objectives = append(def.Objectives, objExpr) | |
return def, nil | |
} | |
... | |
return &newStrategy, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment