@@ -13,22 +13,22 @@ import (
1313 "github.com/serverledge-faas/serverledge/internal/function"
1414)
1515
16- type ArchitectureUNawareBalancer struct {
16+ type ArchitectureUnawareBalancer struct {
1717 mu sync.Mutex
1818
1919 // instead of classic lists we will use hashRings (see hashRing.go) to implement a consistent hashing technique
2020 hashRing * HashRing
2121}
2222
23- // NewArchitectureUNawareBalancer Constructor
24- func NewArchitectureUNawareBalancer (targets []* middleware.ProxyTarget ) * ArchitectureUNawareBalancer {
23+ // NewArchitectureUnawareBalancer Constructor
24+ func NewArchitectureUnawareBalancer (targets []* middleware.ProxyTarget ) * ArchitectureUnawareBalancer {
2525
2626 // REPLICAS is the number of times each physical node will appear in the hash ring. This is done to improve how
2727 // virtual nodes (i.e.: replicas of each physical node) are distributed over the ring, to reduce variation.
2828 REPLICAS := config .GetInt (config .REPLICAS , 128 )
2929 log .Printf ("Running ArchitectureUNawareLB with %d replicas per node in the hash ring\n " , REPLICAS )
3030
31- b := & ArchitectureUNawareBalancer {
31+ b := & ArchitectureUnawareBalancer {
3232 hashRing : NewHashRing (REPLICAS ),
3333 }
3434
@@ -49,7 +49,7 @@ func NewArchitectureUNawareBalancer(targets []*middleware.ProxyTarget) *Architec
4949}
5050
5151// Next Used by Echo Proxy middleware to select the next target dynamically
52- func (b * ArchitectureUNawareBalancer ) Next (c echo.Context ) * middleware.ProxyTarget {
52+ func (b * ArchitectureUnawareBalancer ) Next (c echo.Context ) * middleware.ProxyTarget {
5353 b .mu .Lock ()
5454 defer b .mu .Unlock ()
5555
@@ -76,19 +76,19 @@ func (b *ArchitectureUNawareBalancer) Next(c echo.Context) *middleware.ProxyTarg
7676}
7777
7878// AddTarget Echo requires this method for dynamic load-balancing. It simply inserts a new node in the respective ring.
79- func (b * ArchitectureUNawareBalancer ) AddTarget (t * middleware.ProxyTarget ) bool {
79+ func (b * ArchitectureUnawareBalancer ) AddTarget (t * middleware.ProxyTarget ) bool {
8080 b .mu .Lock ()
8181 defer b .mu .Unlock ()
8282
8383 nodeInfo := GetSingleTargetInfo (t )
8484 // Every time we add a node, we set the information about its available memory
8585 if nodeInfo != nil {
8686 totalMemoryMb := nodeInfo .TotalMemory
87- freeMemoryMB := totalMemoryMb - nodeInfo .UsedMemory
87+ availableMemoryMb := nodeInfo .AvailableMemory
8888 freeCpu := nodeInfo .TotalCPU - nodeInfo .UsedCPU
8989 // Update will update the freeMemory only if the information in nodeInfo is fresher than what we
9090 // already have in the NodeMetrics cache.
91- NodeMetrics .Update (t .Name , freeMemoryMB , totalMemoryMb , nodeInfo .LastUpdateTime , freeCpu )
91+ NodeMetrics .Update (t .Name , availableMemoryMb , totalMemoryMb , nodeInfo .LastUpdateTime , freeCpu )
9292 }
9393
9494 b .hashRing .Add (t )
@@ -97,7 +97,7 @@ func (b *ArchitectureUNawareBalancer) AddTarget(t *middleware.ProxyTarget) bool
9797}
9898
9999// RemoveTarget Echo requires this method to remove a target by name
100- func (b * ArchitectureUNawareBalancer ) RemoveTarget (name string ) bool {
100+ func (b * ArchitectureUnawareBalancer ) RemoveTarget (name string ) bool {
101101 b .mu .Lock ()
102102 defer b .mu .Unlock ()
103103
0 commit comments