mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-28 14:35:00 +00:00
feat(federation): add load balanced option (#2915)
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
parent
031627584b
commit
252961751c
3 changed files with 55 additions and 9 deletions
|
@ -100,10 +100,23 @@ func (fs *FederatedServer) proxy(ctx context.Context, node *node.Node) error {
|
|||
return
|
||||
}
|
||||
|
||||
// open a TCP stream to one of the tunnels
|
||||
// chosen randomly
|
||||
// TODO: optimize this and track usage
|
||||
tunnelAddr := tunnelAddresses[rand.IntN(len(tunnelAddresses))]
|
||||
tunnelAddr := ""
|
||||
|
||||
if fs.loadBalanced {
|
||||
for _, t := range tunnelAddresses {
|
||||
fs.EnsureRecordExist(t)
|
||||
}
|
||||
|
||||
tunnelAddr = fs.SelectLeastUsedServer()
|
||||
log.Debug().Msgf("Selected tunnel %s", tunnelAddr)
|
||||
if tunnelAddr == "" {
|
||||
tunnelAddr = tunnelAddresses[rand.IntN(len(tunnelAddresses))]
|
||||
}
|
||||
|
||||
fs.RecordRequest(tunnelAddr)
|
||||
} else {
|
||||
tunnelAddr = tunnelAddresses[rand.IntN(len(tunnelAddresses))]
|
||||
}
|
||||
|
||||
tunnelConn, err := net.Dial("tcp", tunnelAddr)
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue