ソースを参照

added in-memory

Achilleas Tzenetopoulos 5 年 前
コミット
4776791106
共有2 個のファイルを変更した10 個の追加6 個の削除を含む
  1. 7 3
      kubernetes-v1.15.4/pkg/scheduler/customcache/cache.go
  2. 3 3
      kubernetes-v1.15.4/pkg/scheduler/scheduler.go

+ 7 - 3
kubernetes-v1.15.4/pkg/scheduler/customcache/cache.go

@@ -2,13 +2,15 @@ package customcache
 
 import (
 	"sync"
+	"time"
 )
 
-//var timeout *time.Ticker = time.NewTicker(time.Duration(10 * time.Second))
+var Τimeout *time.Ticker
 
 type MlabCache struct {
-	Cache map[string]map[string]float64
-	Mux   sync.Mutex
+	Cache   map[string]map[string]float64
+	Mux     sync.Mutex
+	Timeout *time.Ticker
 }
 
 var LabCache MlabCache = MlabCache{
@@ -62,6 +64,7 @@ var LabCache MlabCache = MlabCache{
 			"c6res":     -1,
 		},
 	},
+	Timeout: time.NewTicker(time.Duration(10 * time.Second)),
 }
 
 func (c *MlabCache) CleanCache() {
@@ -116,6 +119,7 @@ func (c *MlabCache) CleanCache() {
 			"c6res":     -1,
 		},
 	}
+	//Timeout := time.NewTicker(time.Duration(10 * time.Second))
 	c.Mux.Unlock()
 }
 

+ 3 - 3
kubernetes-v1.15.4/pkg/scheduler/scheduler.go

@@ -252,14 +252,14 @@ func NewFromConfig(config *factory.Config) *Scheduler {
 	}
 }
 
-var timeout *time.Ticker
+//var timeout *time.Ticker
 
 // Run begins watching and scheduling. It waits for cache to be synced, then starts a goroutine and returns immediately.
 func (sched *Scheduler) Run() {
 	if !sched.config.WaitForCacheSync() {
 		return
 	}
-	timeout = time.NewTicker(time.Duration(10 * time.Second))
+	//customcache.Timeout := time.NewTicker(time.Duration(10 * time.Second))
 	go wait.Until(sched.scheduleOne, 0, sched.config.StopEverything)
 }
 
@@ -448,7 +448,7 @@ func (sched *Scheduler) scheduleOne() {
 	// Check if the cache needs update
 	select {
 	// clean the cache if 10 seconds are passed
-	case <-timeout.C:
+	case <-customcache.labCache.Timeout.C:
 		klog.Infof("Time to erase")
 		customcache.LabCache.CleanCache()
 	default: