Skip to content

Commit

Permalink
speedup with multiple get
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Feb 3, 2023
1 parent beba4cd commit 84653d7
Show file tree
Hide file tree
Showing 21 changed files with 13 additions and 35 deletions.
1 change: 0 additions & 1 deletion cluster/calcium/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"testing"

enginemocks "github.com/projecteru2/core/engine/mocks"
resourcemocks "github.com/projecteru2/core/resources/mocks"
storemocks "github.com/projecteru2/core/store/mocks"
"github.com/projecteru2/core/types"

Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/calcium.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/projecteru2/core/log"
"github.com/projecteru2/core/resource3"
"github.com/projecteru2/core/resource3/cobalt"
"github.com/projecteru2/core/resources"
""
"github.com/projecteru2/core/source"
"github.com/projecteru2/core/source/github"
"github.com/projecteru2/core/source/gitlab"
Expand Down
1 change: 0 additions & 1 deletion cluster/calcium/calcium_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"

resourcemocks "github.com/projecteru2/core/resources/mocks"
sourcemocks "github.com/projecteru2/core/source/mocks"
storemocks "github.com/projecteru2/core/store/mocks"
"github.com/projecteru2/core/types"
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/capacity.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"

"github.com/projecteru2/core/log"
"github.com/projecteru2/core/resources"
""
"github.com/projecteru2/core/strategy"
"github.com/projecteru2/core/types"
"github.com/sanity-io/litter"
Expand Down
2 changes: 0 additions & 2 deletions cluster/calcium/capacity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (

enginemocks "github.com/projecteru2/core/engine/mocks"
lockmocks "github.com/projecteru2/core/lock/mocks"
"github.com/projecteru2/core/resources"
resourcemocks "github.com/projecteru2/core/resources/mocks"
storemocks "github.com/projecteru2/core/store/mocks"
"github.com/projecteru2/core/strategy"
"github.com/projecteru2/core/types"
Expand Down
2 changes: 0 additions & 2 deletions cluster/calcium/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
enginemocks "github.com/projecteru2/core/engine/mocks"
enginetypes "github.com/projecteru2/core/engine/types"
lockmocks "github.com/projecteru2/core/lock/mocks"
"github.com/projecteru2/core/resources"
resourcemocks "github.com/projecteru2/core/resources/mocks"
storemocks "github.com/projecteru2/core/store/mocks"
"github.com/projecteru2/core/strategy"
"github.com/projecteru2/core/types"
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/dissociate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"

"github.com/projecteru2/core/log"
"github.com/projecteru2/core/resources"
""
"github.com/projecteru2/core/types"
"github.com/projecteru2/core/utils"
)
Expand Down
1 change: 0 additions & 1 deletion cluster/calcium/dissociate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

lockmocks "github.com/projecteru2/core/lock/mocks"
resourcemocks "github.com/projecteru2/core/resources/mocks"
storemocks "github.com/projecteru2/core/store/mocks"
"github.com/projecteru2/core/types"

Expand Down
2 changes: 0 additions & 2 deletions cluster/calcium/lambda_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
enginemocks "github.com/projecteru2/core/engine/mocks"
enginetypes "github.com/projecteru2/core/engine/types"
lockmocks "github.com/projecteru2/core/lock/mocks"
"github.com/projecteru2/core/resources"
resourcemocks "github.com/projecteru2/core/resources/mocks"
storemocks "github.com/projecteru2/core/store/mocks"
"github.com/projecteru2/core/strategy"
"github.com/projecteru2/core/types"
Expand Down
1 change: 0 additions & 1 deletion cluster/calcium/lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
enginemocks "github.com/projecteru2/core/engine/mocks"
"github.com/projecteru2/core/lock"
lockmocks "github.com/projecteru2/core/lock/mocks"
resourcemocks "github.com/projecteru2/core/resources/mocks"
storemocks "github.com/projecteru2/core/store/mocks"
"github.com/projecteru2/core/types"

Expand Down
1 change: 0 additions & 1 deletion cluster/calcium/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

enginemocks "github.com/projecteru2/core/engine/mocks"
enginetypes "github.com/projecteru2/core/engine/types"
resourcemocks "github.com/projecteru2/core/resources/mocks"
storemocks "github.com/projecteru2/core/store/mocks"
"github.com/projecteru2/core/types"

Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
enginefactory "github.com/projecteru2/core/engine/factory"
enginetypes "github.com/projecteru2/core/engine/types"
"github.com/projecteru2/core/log"
"github.com/projecteru2/core/resources"
""
"github.com/projecteru2/core/types"
"github.com/projecteru2/core/utils"
)
Expand Down
2 changes: 0 additions & 2 deletions cluster/calcium/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
enginemocks "github.com/projecteru2/core/engine/mocks"
enginetypes "github.com/projecteru2/core/engine/types"
lockmocks "github.com/projecteru2/core/lock/mocks"
resourcetypes "github.com/projecteru2/core/resources"
resourcemocks "github.com/projecteru2/core/resources/mocks"
storemocks "github.com/projecteru2/core/store/mocks"
"github.com/projecteru2/core/types"

Expand Down
2 changes: 0 additions & 2 deletions cluster/calcium/realloc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
enginemocks "github.com/projecteru2/core/engine/mocks"
enginetypes "github.com/projecteru2/core/engine/types"
lockmocks "github.com/projecteru2/core/lock/mocks"
resourcetypes "github.com/projecteru2/core/resources"
resourcemocks "github.com/projecteru2/core/resources/mocks"
storemocks "github.com/projecteru2/core/store/mocks"
"github.com/projecteru2/core/types"

Expand Down
1 change: 0 additions & 1 deletion cluster/calcium/remap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
enginetypes "github.com/projecteru2/core/engine/types"
lockmocks "github.com/projecteru2/core/lock/mocks"
"github.com/projecteru2/core/log"
resourcemocks "github.com/projecteru2/core/resources/mocks"
storemocks "github.com/projecteru2/core/store/mocks"
"github.com/projecteru2/core/types"
"github.com/stretchr/testify/assert"
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"sync"

"github.com/projecteru2/core/log"
"github.com/projecteru2/core/resources"
""
"github.com/projecteru2/core/types"
"github.com/projecteru2/core/utils"
)
Expand Down
2 changes: 0 additions & 2 deletions cluster/calcium/remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (

enginemocks "github.com/projecteru2/core/engine/mocks"
lockmocks "github.com/projecteru2/core/lock/mocks"
resourcetypes "github.com/projecteru2/core/resources"
resourcemocks "github.com/projecteru2/core/resources/mocks"
storemocks "github.com/projecteru2/core/store/mocks"
"github.com/projecteru2/core/types"

Expand Down
1 change: 0 additions & 1 deletion cluster/calcium/replace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
enginemocks "github.com/projecteru2/core/engine/mocks"
enginetypes "github.com/projecteru2/core/engine/types"
lockmocks "github.com/projecteru2/core/lock/mocks"
resourcemocks "github.com/projecteru2/core/resources/mocks"
storemocks "github.com/projecteru2/core/store/mocks"
"github.com/projecteru2/core/types"

Expand Down
1 change: 0 additions & 1 deletion cluster/calcium/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

enginemocks "github.com/projecteru2/core/engine/mocks"
lockmocks "github.com/projecteru2/core/lock/mocks"
resourcemocks "github.com/projecteru2/core/resources/mocks"
storemocks "github.com/projecteru2/core/store/mocks"
"github.com/projecteru2/core/types"

Expand Down
2 changes: 0 additions & 2 deletions cluster/calcium/wal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
enginemocks "github.com/projecteru2/core/engine/mocks"
enginetypes "github.com/projecteru2/core/engine/types"
lockmocks "github.com/projecteru2/core/lock/mocks"
resourcetypes "github.com/projecteru2/core/resources"
resourcemocks "github.com/projecteru2/core/resources/mocks"
storemocks "github.com/projecteru2/core/store/mocks"
"github.com/projecteru2/core/types"

Expand Down
16 changes: 8 additions & 8 deletions resource3/plugins/cpumem/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,14 @@ func (p Plugin) GetMostIdleNode(ctx context.Context, nodenames []string) (*plugi
var mostIdleNode string
var minIdle = math.MaxFloat64

for _, nodename := range nodenames {
resourceInfo, err := p.doGetNodeResourceInfo(ctx, nodename)
if err != nil {
log.WithFunc("resource.cpumem.GetMostIdleNode").WithField("node", nodename).Error(ctx, err)
return nil, err
}
idle := float64(resourceInfo.Usage.CPUMap.TotalPieces()) / float64(resourceInfo.Capacity.CPUMap.TotalPieces())
idle += float64(resourceInfo.Usage.Memory) / float64(resourceInfo.Capacity.Memory)
nodesResourceInfo, err := p.doGetNodesResourceInfo(ctx, nodenames)
if err != nil {
return nil, err
}

for nodename, nodeResourceInfo := range nodesResourceInfo {
idle := float64(nodeResourceInfo.Usage.CPUMap.TotalPieces()) / float64(nodeResourceInfo.Capacity.CPUMap.TotalPieces())
idle += float64(nodeResourceInfo.Usage.Memory) / float64(nodeResourceInfo.Capacity.Memory)

if idle < minIdle {
mostIdleNode = nodename
Expand Down

0 comments on commit 84653d7

Please sign in to comment.