From 826006ac0184495a4c5226c7ad8e3ab88a9cc75f Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Tue, 2 Apr 2024 18:08:12 -0400 Subject: [PATCH] minor --- configuration/backend_rules_onlytwo.json | 31 ++++++++++++++++++++++++ core/services/backend_rules.go | 5 ++-- 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 configuration/backend_rules_onlytwo.json diff --git a/configuration/backend_rules_onlytwo.json b/configuration/backend_rules_onlytwo.json new file mode 100644 index 000000000000..96dec2733ab3 --- /dev/null +++ b/configuration/backend_rules_onlytwo.json @@ -0,0 +1,31 @@ +[ + { + "name": "OnlyTwoLT2", + "desc": "Test Rule: Only allow 2 backends to be loaded at once, unload the least recently used if a 3rd request comes in", + "salience": 10, + "when": [ + "Result.Action == ActionDefs.Blank", + "LoadedModelCount <= 1" + ], + "then": [ + "Result.Action = ActionDefs.Continue", + "Result.ModelName = RequestedModelName" + ] + }, + { + "name": "OnlyTwoGT2", + "desc": "Test Rule: Only allow 2 backends to be loaded at once, unload the least recently used if a 3rd request comes in", + "salience": 10, + "when": [ + "Result.Action == ActionDefs.Blank", + "LoadedModelCount >= 2" + ], + "then": [ + "Log(\"Too many backends in use, unloading least recently used...\")", + "LRU = LoadedModels[0].ModelName", + "ModelLoader.ShutdownModel(LRU)", + "Result.Action = ActionDefs.Continue", + "Result.ModelName = RequestedModelName" + ] + } +] \ No newline at end of file diff --git a/core/services/backend_rules.go b/core/services/backend_rules.go index c265cbc07892..274bbe4c25ff 100644 --- a/core/services/backend_rules.go +++ b/core/services/backend_rules.go @@ -92,7 +92,7 @@ func (rbbs RuleBasedBackendService) RuleBasedLoad(modelName string, alreadyLoade ruleBasedLoadDataCtx := ast.NewDataContext() ruleBasedLoadDataCtx.Add("ModelLoader", rbbs.modelLoader) - ruleBasedLoadDataCtx.Add("LoadedModelCount", rbbs.modelLoader.LoadedModelCount()) // Still relevant after second line??? + ruleBasedLoadDataCtx.Add("LoadedModelCount", rbbs.modelLoader.LoadedModelCount()) ruleBasedLoadDataCtx.Add("LoadedModels", rbbs.modelLoader.SortedLoadedModelMetadata()) ruleBasedLoadDataCtx.Add("ActionDefs", ruleBasedBackendResultActionDefinitions) @@ -100,7 +100,9 @@ func (rbbs RuleBasedBackendService) RuleBasedLoad(modelName string, alreadyLoade ruleBasedLoadDataCtx.Add("RequestedModelName", modelName) ruleBasedLoadDataCtx.Add("Source", source) ruleBasedLoadDataCtx.Add("Request", optionalRequest) + ruleBasedLoadDataCtx.Add("BackendConfig", bc) + ruleBasedLoadDataCtx.Add("AppConfig", rbbs.appConfig) ruleBasedLoadDataCtx.Add("Result", result) @@ -114,5 +116,4 @@ func (rbbs RuleBasedBackendService) RuleBasedLoad(modelName string, alreadyLoade return nil, err } return &result, nil - }