mirror of
https://github.com/lordmathis/llamactl.git
synced 2025-11-06 00:54:23 +00:00
Move LRU eviction to timeout.go
This commit is contained in:
@@ -240,40 +240,6 @@ func (im *instanceManager) StopInstance(name string) (*instance.Process, error)
|
|||||||
return instance, nil
|
return instance, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// EvictLRUInstance finds and stops the least recently used running instance.
|
|
||||||
func (im *instanceManager) EvictLRUInstance() error {
|
|
||||||
im.mu.RLock()
|
|
||||||
var lruInstance *instance.Process
|
|
||||||
|
|
||||||
for name, _ := range im.runningInstances {
|
|
||||||
inst := im.instances[name]
|
|
||||||
if inst == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if inst.GetOptions() != nil && inst.GetOptions().IdleTimeout != nil && *inst.GetOptions().IdleTimeout <= 0 {
|
|
||||||
continue // Skip instances without idle timeout
|
|
||||||
}
|
|
||||||
|
|
||||||
if lruInstance == nil {
|
|
||||||
lruInstance = inst
|
|
||||||
}
|
|
||||||
|
|
||||||
if inst.LastRequestTime() < lruInstance.LastRequestTime() {
|
|
||||||
lruInstance = inst
|
|
||||||
}
|
|
||||||
}
|
|
||||||
im.mu.RUnlock()
|
|
||||||
|
|
||||||
if lruInstance == nil {
|
|
||||||
return fmt.Errorf("failed to find lru instance")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Evict Instance
|
|
||||||
_, err := im.StopInstance(lruInstance.Name)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// RestartInstance stops and then starts an instance, returning the updated instance.
|
// RestartInstance stops and then starts an instance, returning the updated instance.
|
||||||
func (im *instanceManager) RestartInstance(name string) (*instance.Process, error) {
|
func (im *instanceManager) RestartInstance(name string) (*instance.Process, error) {
|
||||||
instance, err := im.StopInstance(name)
|
instance, err := im.StopInstance(name)
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package manager
|
package manager
|
||||||
|
|
||||||
import "log"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"llamactl/pkg/instance"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
func (im *instanceManager) checkAllTimeouts() {
|
func (im *instanceManager) checkAllTimeouts() {
|
||||||
im.mu.RLock()
|
im.mu.RLock()
|
||||||
@@ -24,3 +28,37 @@ func (im *instanceManager) checkAllTimeouts() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EvictLRUInstance finds and stops the least recently used running instance.
|
||||||
|
func (im *instanceManager) EvictLRUInstance() error {
|
||||||
|
im.mu.RLock()
|
||||||
|
var lruInstance *instance.Process
|
||||||
|
|
||||||
|
for name, _ := range im.runningInstances {
|
||||||
|
inst := im.instances[name]
|
||||||
|
if inst == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if inst.GetOptions() != nil && inst.GetOptions().IdleTimeout != nil && *inst.GetOptions().IdleTimeout <= 0 {
|
||||||
|
continue // Skip instances without idle timeout
|
||||||
|
}
|
||||||
|
|
||||||
|
if lruInstance == nil {
|
||||||
|
lruInstance = inst
|
||||||
|
}
|
||||||
|
|
||||||
|
if inst.LastRequestTime() < lruInstance.LastRequestTime() {
|
||||||
|
lruInstance = inst
|
||||||
|
}
|
||||||
|
}
|
||||||
|
im.mu.RUnlock()
|
||||||
|
|
||||||
|
if lruInstance == nil {
|
||||||
|
return fmt.Errorf("failed to find lru instance")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Evict Instance
|
||||||
|
_, err := im.StopInstance(lruInstance.Name)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user