Skip to content

Commit

Permalink
Adding the feature for manual resources specification
Browse files Browse the repository at this point in the history
added special parameters coming from Advisors.
  • Loading branch information
Tusamarco committed Feb 10, 2023
1 parent 06e7440 commit b415743
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 9 deletions.
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,27 @@ Transfer-Encoding: chunked
]
}
```
From version `1.1.0` we support also open requests, this means you can pass the values for memory and cpu in open forms.
When retrieving the supported dimensions you will notice a special group `999`:
```json
{
"id": 999,
"name": "Open request",
"cpu": 0,
"memory": 0,
"mysqlCpu": 0,
"proxyCpu": 0,
"pmmCpu": 0,
"mysqlMemory": 0,
"proxyMemory": 0,
"pmmMemory": 0
}
```
This is the ID you should use for your request, plus the values for CPU and Memory ie:
` curl -i -X GET -H "Content-Type: application/json" -d '{"output":"human","dbtype":"pxc", "dimension": {"id": 999,"cpu":4000,"memory":2.5}, "loadtype": {"id": 2}, "connections": 100}' http://127.0.0.1:8080/calculator`

The calculator will automatically adjust the memory for MySQL, Proxy and Pmm monitoring in relation to what you are passing.

Let see each section one by one.
#### Dimension
- id : is what you will use to ASK the calculation
Expand All @@ -110,12 +131,33 @@ Here I just report some example, however connections can be any number from 50 u


## Getting the calculation back
Once you have it running and have decide what to pick, is time to get the calculation back.
Once you have it running and have decided what to pick, is time to get the calculation back.

To get the "results" you need to query a different entry point `/calculator` instead the previously used `/supported`.
to test it you can do something like:
`curl -i -X GET -H "Content-Type: application/json" -d '{"output":"json","dbtype":"pxc", "dimension": {"id": 2}, "loadtype": {"id": 2}, "connections": 400}' http://127.0.0.1:8080/calculator`

From version `1.1.0` we support also open requests, this means you can pass the values for memory and cpu in open forms.
When retrieving the supported dimensions you will notice a special group `999`:
```json
{
"id": 999,
"name": "Open request",
"cpu": 0,
"memory": 0,
"mysqlCpu": 0,
"proxyCpu": 0,
"pmmCpu": 0,
"mysqlMemory": 0,
"proxyMemory": 0,
"pmmMemory": 0
}
```
This is the ID you should use for your request, plus the values for CPU and Memory ie:
` curl -i -X GET -H "Content-Type: application/json" -d '{"output":"human","dbtype":"pxc", "dimension": {"id": 999,"cpu":4000,"memory":2.5}, "loadtype": {"id": 2}, "connections": 100}' http://127.0.0.1:8080/calculator`

The calculator will automatically adjust the memory for MySQL, Proxy and Pmm monitoring in relation to what you are passing.

Your (long) output will look like this:
```json
{"request": {,"message":{
Expand Down
53 changes: 52 additions & 1 deletion src/Objects/Configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ func (conf *Configuration) Init() {
{8, "12XLarge", 48000, 192, 45000, 2000, 1000, 190, 1.5, 0.500},
{9, "16XLarge", 64000, 256, 60000, 3000, 1000, 253, 2, 1},
{10, "24XLarge", 96000, 384, 90000, 4000, 2000, 380, 2.5, 1.5},
{999, "Open request", 0, 0, 0, 0, 0, 0, 0, 0},
}

// {999, "Open request", 0, 0, 0.875, 0.09375, 0.00025, 0.96875, 0.0234375, 0.0078125},
conf.LoadType = []LoadType{}

loadT := make(map[string]int)
Expand Down Expand Up @@ -184,6 +185,10 @@ func (family *Family) Init() map[string]Family {
"thread_stack": {"thread_stack", "configuration", "server", "1024", "1024", 125, 1048576},
"table_open_cache_instances": {"table_open_cache_instances", "configuration", "server", "4", "16", 1, 64},
"tablespace_definition_cache": {"tablespace_definition_cache", "configuration", "server", "512", "256", 256, 524288},
//Adding values to match common advisors checks
"sync_binlog": {"sync_binlog", "configuration", "server", "1", "1", 0, 1},
"sql_mode": {"sql_mode", "configuration", "server", "'ONLY_FULL_GROUP_BY STRICT_TRANS_TABLES NO_ZERO_IN_DATE NO_ZERO_DATE ERROR_FOR_DIVISION_BY_ZERO NO_ENGINE_SUBSTITUTION TRADITIONAL STRICT_ALL_TABLES'", "0", 0, 1},
"binlog_expire_logs_seconds": {"binlog_expire_logs_seconds", "configuration", "server", "604800", "0", 0, 0},
}

innodbGroup := map[string]Parameter{
Expand Down Expand Up @@ -312,3 +317,49 @@ func (f Family) parseParamsHuman(group GroupObj) bytes.Buffer {

return b
}

func (conf *Configuration) CalculateOpenDimension(dimension Dimension) Dimension {
if dimension.Cpu > 0 && dimension.Memory > 0 {
// {999, "Open request", 0, 0, 0.875, 0.09375, 0.00025, 0.96875, 0.0234375, 0.0078125},
// first identify the range request fits in
calcDimension := conf.getDimensionForFreeCalculation(dimension)

dimension.MysqlCpu = int(float64(dimension.Cpu) * float64(calcDimension.MysqlCpu) / float64(calcDimension.Cpu))
dimension.ProxyCpu = int(float64(dimension.Cpu) * float64(calcDimension.ProxyCpu) / float64(calcDimension.Cpu))
dimension.PmmCpu = int(float64(dimension.Cpu) * float64(calcDimension.PmmCpu) / float64(calcDimension.Cpu))
dimension.MysqlMemory = float64(dimension.Memory) * calcDimension.MysqlMemory / calcDimension.Memory
dimension.ProxyMemory = float64(dimension.Memory) * calcDimension.ProxyMemory / calcDimension.Memory
dimension.PmmMemory = float64(dimension.Memory) * calcDimension.PmmMemory / calcDimension.Memory

}

return dimension
}

// We return the dimension that is closer to the request
func (conf *Configuration) getDimensionForFreeCalculation(dimension Dimension) Dimension {
var calcDimension Dimension
for i := 0; i < len(conf.Dimension)-1; i++ {
if i == 0 && (dimension.Cpu <= conf.Dimension[i].Cpu || dimension.Memory <= conf.Dimension[i].Memory) {
calcDimension = conf.Dimension[i]
break
} else if i > 0 && (InBetween(dimension.Cpu, conf.Dimension[i-1].Cpu, conf.Dimension[i].Cpu) ||
InBetween(int(dimension.Memory), int(conf.Dimension[i-1].Memory), int(conf.Dimension[i].Memory))) {
// we always pich the smaller set for more conservative approach
calcDimension = conf.Dimension[i-1]
break
} else if i == len(conf.Dimension)-1 && (dimension.Cpu >= conf.Dimension[i].Cpu || dimension.Memory >= conf.Dimension[i].Memory) {
calcDimension = conf.Dimension[i]
break
}
}

return calcDimension
}
func InBetween(i, min, max int) bool {
if (i >= min) && (i <= max) {
return true
} else {
return false
}
}
8 changes: 7 additions & 1 deletion src/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ func (c *Configurator) GetAllGaleraProviderOptionsAsString() bytes.Buffer {

func (c *Configurator) init(r o.ConfigurationRequest, fam map[string]o.Family, conf o.Configuration, message o.ResponseMessage) (o.ResponseMessage, bool) {

dim := conf.GetDimensionByID(r.Dimension.Id)
//if dimension is custom we take it from request otherwise from Configuration
var dim o.Dimension
if r.Dimension.Id != 999 {
dim = conf.GetDimensionByID(r.Dimension.Id)
} else {
dim = r.Dimension
}
load := conf.GetLoadByID(r.LoadType.Id)
if load.Id == 0 || dim.Id == 0 {
log.Warning(fmt.Sprintf("Invalid load %d or Dimension %d detected ", load.Id, dim.Id))
Expand Down
24 changes: 18 additions & 6 deletions src/mysqloperatorcalculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func main() {
flag.BoolVar(&version, "version", false, "to get product version")
flag.Parse()

var versionS = "1.0.0"
var versionS = "1.1.0"
//initialize help

//just check if we need to pass version or help
Expand Down Expand Up @@ -118,6 +118,13 @@ func handleGetCalculate(writer http.ResponseWriter, request *http.Request) error
return err
}
return nil
} else if ConfRequest.Dimension.Id == 999 && (ConfRequest.Dimension.Cpu == 0 || ConfRequest.Dimension.Memory == 0) {
err := returnErrorMessage(writer, request, &ConfRequest, responseMsg, families, "Open dimension request missing CPU OR Memory value "+string(body[:]))
if err != nil {
return err
}
return nil

}

// create and init all the different params organized by families
Expand All @@ -131,7 +138,7 @@ func handleGetCalculate(writer http.ResponseWriter, request *http.Request) error

if connectionsOverload {
responseMsg.MName = "Resources Overload"
responseMsg.MText = "Too many connections for the choosed dimension. Resource Overlaoad, decrese number of connections OR choose higer CPUs number"
responseMsg.MText = "Too many connections for the chose dimension. Resource Overload, decrease number of connections OR choose higher CPUs number"
families = make(map[string]Objects.Family)
} else {
// here is the calculation step
Expand All @@ -157,12 +164,17 @@ func handleGetCalculate(writer http.ResponseWriter, request *http.Request) error
// we loop the arrays to get all the info we may need for the operation using the ID as reference
func getConfForConfRequest(request Objects.ConfigurationRequest, conf Objects.Configuration) Objects.ConfigurationRequest {

for i := 0; i < len(conf.Dimension); i++ {
if request.Dimension.Id != 999 {
for i := 0; i < len(conf.Dimension); i++ {

if request.Dimension.Id == conf.Dimension[i].Id {
request.Dimension = conf.Dimension[i]
break
if request.Dimension.Id == conf.Dimension[i].Id {
request.Dimension = conf.Dimension[i]
break
}
}
} else {
//We need to calibrate the dimension on the base of an open request
request.Dimension = conf.CalculateOpenDimension(request.Dimension)
}

for i := 0; i < len(conf.LoadType); i++ {
Expand Down

0 comments on commit b415743

Please sign in to comment.