Bläddra i källkod

added in-memory

Achilleas Tzenetopoulos 5 år sedan
förälder
incheckning
6c69b1c926

+ 13 - 0
kubernetes-v1.15.4/pkg/scheduler/algorithm/priorities/custom_resource_allocation.go

@@ -105,9 +105,22 @@ func customScoreInfluxDB(metrics []string, uuid string, socket,
 	// Calculate the average for the metrics provided
 	return calculateWeightedAverage(response, numberOfRows, len(metrics))
 }
+func InvalidateCache() {
+	// Check if the cache needs update
+	select {
+	// clean the cache if 10 seconds are passed
+	case <-customcache.LabCache.Timeout.C:
+		klog.Infof("Time to erase")
+		customcache.LabCache.Timeout.C.Stop()
+		customcache.LabCache.CleanCache()
+	default:
+	}
+}
 
 func customResourceScorer(nodeName string) (float64, error) {
 
+	InvalidateCache()
+
 	cores, _ := Cores[nodeName]
 
 	var results map[string]float64

+ 5 - 1
kubernetes-v1.15.4/pkg/scheduler/customcache/cache.go

@@ -6,6 +6,7 @@ import (
 )
 
 var LabCache MlabCache
+var duration int
 
 type MlabCache struct {
 	Cache   map[string]map[string]float64
@@ -65,7 +66,7 @@ func init() {
 				"c6res":     -1,
 			},
 		},
-		Timeout: time.NewTicker(time.Duration(10 * time.Second)),
+		//Timeout: time.NewTicker(time.Duration(10 * time.Second)),
 	}
 }
 
@@ -135,6 +136,9 @@ func (c *MlabCache) UpdateCache(input map[string]float64, c6res float64, nodenam
 		"mem_write": input["mem_write"],
 		"c6res":     c6res,
 	}
+
+	// Reset the ticker
+	c.Timeout = time.NewTicker(time.Duration(duration) * time.Second)
 	c.Mux.Unlock()
 
 	//klog.Infof("After cache update")

+ 8 - 10
kubernetes-v1.15.4/pkg/scheduler/scheduler.go

@@ -24,8 +24,6 @@ import (
 
 	"k8s.io/klog"
 
-	"github.com/iwita/kube-scheduler/customcache"
-
 	v1 "k8s.io/api/core/v1"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/apimachinery/pkg/runtime"
@@ -445,14 +443,14 @@ func (sched *Scheduler) bind(assumed *v1.Pod, b *v1.Binding) error {
 // scheduleOne does the entire scheduling workflow for a single pod.  It is serialized on the scheduling algorithm's host fitting.
 func (sched *Scheduler) scheduleOne() {
 
-	// Check if the cache needs update
-	select {
-	// clean the cache if 10 seconds are passed
-	case <-customcache.LabCache.Timeout.C:
-		klog.Infof("Time to erase")
-		customcache.LabCache.CleanCache()
-	default:
-	}
+	// // Check if the cache needs update
+	// select {
+	// // clean the cache if 10 seconds are passed
+	// case <-customcache.LabCache.Timeout.C:
+	// 	klog.Infof("Time to erase")
+	// 	customcache.LabCache.CleanCache()
+	// default:
+	// }
 
 	fwk := sched.config.Framework