From 1d240dff4c511b972b9e762c1a968ad104d7ab64 Mon Sep 17 00:00:00 2001 From: Matt Oswalt Date: Sun, 3 Feb 2019 13:58:48 -0800 Subject: [PATCH 1/2] Fixed GC goroutine; make GC interval configurable Signed-off-by: Matt Oswalt --- config/config.go | 8 ++++++++ scheduler/namespaces.go | 14 ++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/config/config.go b/config/config.go index f9d8f065..8a113358 100644 --- a/config/config.go +++ b/config/config.go @@ -17,6 +17,7 @@ type SyringeConfig struct { HealthCheckInterval int TSDBExportInterval int TSDBEnabled bool + GCInterval int LessonRepoRemote string LessonRepoBranch string @@ -94,6 +95,13 @@ func LoadConfigVars() (*SyringeConfig, error) { config.LessonRepoDir = dir } + gc, err := strconv.Atoi(os.Getenv("SYRINGE_GC_INTERVAL")) + if gc == 0 || err != nil { + config.GCInterval = 5 + } else { + config.GCInterval = gc + } + return &config, nil } diff --git a/scheduler/namespaces.go b/scheduler/namespaces.go index 8ca0ea9d..6209f986 100644 --- a/scheduler/namespaces.go +++ b/scheduler/namespaces.go @@ -130,7 +130,7 @@ func (ls *LessonScheduler) createNamespace(req *LessonScheduleRequest) (*corev1. Labels: map[string]string{ "lessonId": fmt.Sprintf("%d", req.LessonDef.LessonId), "syringeManaged": "yes", - "name": nsName, + "name": nsName, "syringeTier": ls.SyringeConfig.Tier, "lastAccessed": strconv.Itoa(int(time.Now().Unix())), "created": strconv.Itoa(int(time.Now().Unix())), @@ -185,7 +185,8 @@ func (ls *LessonScheduler) purgeOldLessons() ([]string, error) { panic(err) } lastAccessed := time.Unix(i, 0) - if time.Since(lastAccessed) < 30*time.Minute { + + if time.Since(lastAccessed) < time.Duration(ls.SyringeConfig.GCInterval)*time.Minute { continue } @@ -205,14 +206,15 @@ func (ls *LessonScheduler) purgeOldLessons() ([]string, error) { return []string{}, nil } - log.Warnf("Garbage-collecting %d old lessons", len(oldNameSpaces)) + log.Infof("Garbage-collecting %d old lessons", len(oldNameSpaces)) + log.Debug(oldNameSpaces) var wg sync.WaitGroup wg.Add(len(oldNameSpaces)) for n := range oldNameSpaces { - go func() { + go func(ns string) { defer wg.Done() - ls.deleteNamespace(oldNameSpaces[n]) - }() + ls.deleteNamespace(ns) + }(oldNameSpaces[n]) } wg.Wait() log.Infof("Finished garbage-collecting %d old lessons", len(oldNameSpaces)) From 3185bab45935aadf0fbf874856a8e15fb96566f7 Mon Sep 17 00:00:00 2001 From: Matt Oswalt Date: Sun, 3 Feb 2019 22:55:47 -0800 Subject: [PATCH 2/2] Added changelog update Signed-off-by: Matt Oswalt --- CHANGELOG.md | 1 + config/config.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4cde03c..6d063277 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## In development +- Fixed GC goroutine; make GC interval configurable [#63](https://github.com/nre-learning/syringe/pull/63/files) ## 0.2.0 - January 24, 2019 diff --git a/config/config.go b/config/config.go index 8a113358..04045ede 100644 --- a/config/config.go +++ b/config/config.go @@ -97,7 +97,7 @@ func LoadConfigVars() (*SyringeConfig, error) { gc, err := strconv.Atoi(os.Getenv("SYRINGE_GC_INTERVAL")) if gc == 0 || err != nil { - config.GCInterval = 5 + config.GCInterval = 30 } else { config.GCInterval = gc }