generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Kuromesi <[email protected]>
- Loading branch information
Showing
9 changed files
with
668 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package backend | ||
|
||
import ( | ||
"context" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/klog/v2" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/predicate" | ||
) | ||
|
||
type FilterConfigReconciler struct { | ||
client.Client | ||
Datastore *K8sDatastore | ||
} | ||
|
||
func (c *FilterConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
cm := &corev1.ConfigMap{} | ||
if err := c.Get(ctx, req.NamespacedName, cm); err != nil { | ||
if client.IgnoreNotFound(err) != nil { | ||
klog.Errorf("unable to get ConfigMap, err: %v", err) | ||
return ctrl.Result{}, err | ||
} | ||
c.Datastore.poolMu.Lock() | ||
defer c.Datastore.poolMu.Unlock() | ||
klog.V(1).Info("filter config deleted, reset filter config") | ||
c.Datastore.filterConfigMap = nil | ||
return ctrl.Result{}, nil | ||
} | ||
|
||
c.Datastore.poolMu.Lock() | ||
defer c.Datastore.poolMu.Unlock() | ||
|
||
if cm.DeletionTimestamp != nil { | ||
klog.V(1).Info("filter config deleting, reset filter config") | ||
c.Datastore.filterConfigMap = nil | ||
return ctrl.Result{}, nil | ||
} | ||
|
||
klog.V(1).Infof("update filter config to: %++v", cm.Data) | ||
c.Datastore.filterConfigMap = cm.DeepCopy() | ||
return ctrl.Result{}, nil | ||
} | ||
|
||
func (c *FilterConfigReconciler) SetupWithManager(mgr ctrl.Manager) error { | ||
return ctrl.NewControllerManagedBy(mgr). | ||
For(&corev1.ConfigMap{}). | ||
WithEventFilter(predicate.NewPredicateFuncs(func(object client.Object) bool { | ||
return object.GetName() == "filter-config" && object.GetNamespace() == "default" | ||
})). | ||
Complete(c) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
package scheduling | ||
|
||
const ( | ||
FilterCriticalRequestName = "critical_request" | ||
FilterLeastQueuingName = "least_queuing" | ||
FilterLowCostLoraName = "low_cost_lora" | ||
FilterLowLatencyName = "low_latency" | ||
FilterAffinityLoraName = "affinity_lora" | ||
FilterSheddableRequestName = "sheddable_request" | ||
FilterLeastKvCacheName = "least_kv_cache" | ||
FilterDropRequestName = "drop_request" | ||
FilterCanAcceptNewLoraName = "can_accept_new_lora" | ||
) | ||
|
||
const ( | ||
TopKByWaitingQueueSize = "waiting_queue_size" | ||
TopKByKVCacheUsagePercent = "kv_cache_usage_percent" | ||
) | ||
|
||
var filterMap = map[string]FilterGen{ | ||
FilterLowLatencyName: FilterLowLatency, | ||
FilterCriticalRequestName: FilterCriticalRequest, | ||
FilterLeastQueuingName: FilterLeastQueuing, | ||
FilterCanAcceptNewLoraName: FilterCanAcceptNewLora, | ||
FilterSheddableRequestName: FilterSheddableRequest, | ||
FilterDropRequestName: FilterDropRequest, | ||
FilterAffinityLoraName: FilterAffinityLora, | ||
FilterLowCostLoraName: FilterLowCostLora, | ||
FilterLeastKvCacheName: FilterLeastKvCache, | ||
} | ||
|
||
// FilterGen generate a filter from a filter option | ||
type FilterGen interface { | ||
Name() string | ||
Get(*FilterOption) filter | ||
Validate(*FilterOption) error | ||
} | ||
|
||
type FilterOption struct { | ||
KvCacheThreshold *float64 `json:"kvCacheThreshold,omitempty"` | ||
|
||
QueueThresholdCritical *int `json:"queueThresholdCritical,omitempty"` | ||
QueueingThresholdLoRA *int `json:"queueingThresholdLoRA,omitempty"` | ||
} | ||
|
||
type filterGenImpl struct { | ||
name string | ||
getter func(*FilterOption) filter | ||
validator func(*FilterOption) error | ||
} | ||
|
||
var _ FilterGen = &filterGenImpl{} | ||
|
||
func (fg *filterGenImpl) Name() string { | ||
return fg.name | ||
} | ||
|
||
func (fg *filterGenImpl) Get(fo *FilterOption) filter { | ||
return fg.getter(fo) | ||
} | ||
|
||
func (fg *filterGenImpl) Validate(fo *FilterOption) error { | ||
return fg.validator(fo) | ||
} | ||
|
||
var ( | ||
FilterCriticalRequest FilterGen = &filterGenImpl{ | ||
name: FilterCriticalRequestName, | ||
getter: func(fo *FilterOption) filter { | ||
return toFilter(criticalRequestPredicate) | ||
}, | ||
validator: func(fo *FilterOption) error { return nil }, | ||
} | ||
|
||
FilterLeastQueuing FilterGen = &filterGenImpl{ | ||
name: FilterLeastQueuingName, | ||
getter: func(fo *FilterOption) filter { | ||
return leastQueuingFilterFunc | ||
}, | ||
validator: func(fo *FilterOption) error { return nil }, | ||
} | ||
|
||
FilterLowCostLora FilterGen = &filterGenImpl{ | ||
name: FilterLowCostLoraName, | ||
getter: func(fo *FilterOption) filter { | ||
return toFilter(lowLoRACostPredicate) | ||
}, | ||
validator: func(fo *FilterOption) error { return nil }, | ||
} | ||
|
||
FilterLowLatency FilterGen = &filterGenImpl{ | ||
name: FilterLowLatencyName, | ||
getter: func(fo *FilterOption) filter { | ||
return toFilter(lowQueueingPodPredicate) | ||
}, | ||
validator: func(fo *FilterOption) error { return nil }, | ||
} | ||
|
||
FilterAffinityLora FilterGen = &filterGenImpl{ | ||
name: FilterAffinityLoraName, | ||
getter: func(fo *FilterOption) filter { | ||
return toFilter(loRAAffinityPredicate) | ||
}, | ||
validator: func(fo *FilterOption) error { return nil }, | ||
} | ||
|
||
FilterSheddableRequest FilterGen = &filterGenImpl{ | ||
name: FilterSheddableRequestName, | ||
getter: func(opt *FilterOption) filter { | ||
qtc, kct := queueThresholdCritical, kvCacheThreshold | ||
if opt != nil { | ||
if opt.KvCacheThreshold != nil { | ||
kct = *opt.KvCacheThreshold | ||
} | ||
if opt.QueueThresholdCritical != nil { | ||
qtc = *opt.QueueThresholdCritical | ||
} | ||
} | ||
return toFilter(noQueueAndLessThanKVCacheThresholdPredicate(qtc, kct)) | ||
}, | ||
validator: func(fo *FilterOption) error { return nil }, | ||
} | ||
|
||
FilterLeastKvCache FilterGen = &filterGenImpl{ | ||
name: FilterLeastKvCacheName, | ||
getter: func(fo *FilterOption) filter { | ||
return leastKVCacheFilterFunc | ||
}, | ||
validator: func(fo *FilterOption) error { return nil }, | ||
} | ||
|
||
FilterDropRequest FilterGen = &filterGenImpl{ | ||
name: FilterDropRequestName, | ||
getter: func(fo *FilterOption) filter { | ||
return dropRequestFilterFunc | ||
}, | ||
validator: func(fo *FilterOption) error { return nil }, | ||
} | ||
|
||
FilterCanAcceptNewLora FilterGen = &filterGenImpl{ | ||
name: FilterCanAcceptNewLoraName, | ||
getter: func(fo *FilterOption) filter { | ||
return toFilter(canAcceptNewLoraPredicate) | ||
}, | ||
validator: func(fo *FilterOption) error { return nil }, | ||
} | ||
) |
Oops, something went wrong.