-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: sort targets by the remaining slots
- Loading branch information
1 parent
5fb7d99
commit 340a802
Showing
10 changed files
with
65 additions
and
47 deletions.
There are no files selected for viewing
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
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
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
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
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package loadbalancer | ||
|
||
type LlamaCppTargetHeap []*LlamaCppTarget | ||
|
||
func (self LlamaCppTargetHeap) Len() int { | ||
return len(self) | ||
} | ||
|
||
func (self LlamaCppTargetHeap) Less(i, j int) bool { | ||
// inverse comparison, because we want the target with the most idle slots | ||
// to be at the top | ||
return !self[i].Less(self[j]) | ||
} | ||
|
||
func (self LlamaCppTargetHeap) Swap(i, j int) { | ||
self[i], self[j] = self[j], self[i] | ||
} | ||
|
||
func (self *LlamaCppTargetHeap) Push(x any) { | ||
*self = append(*self, x.(*LlamaCppTarget)) | ||
} | ||
|
||
func (self *LlamaCppTargetHeap) Pop() any { | ||
old := *self | ||
n := len(old) | ||
x := old[n-1] | ||
*self = old[0 : n-1] | ||
|
||
return x | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
package loadbalancer | ||
|
||
import ( | ||
"github.com/emirpasic/gods/v2/trees/binaryheap" | ||
"container/heap" | ||
|
||
"github.com/hashicorp/go-hclog" | ||
) | ||
|
||
func NewLoadBalancer( | ||
logger hclog.Logger, | ||
) *LoadBalancer { | ||
targetHeap := &LlamaCppTargetHeap{} | ||
|
||
heap.Init(targetHeap) | ||
|
||
return &LoadBalancer{ | ||
Logger: logger, | ||
targets: binaryheap.NewWith[*LlamaCppTarget](LlamaCppTargetComparator), | ||
targets: targetHeap, | ||
} | ||
} |
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