Skip to content
This repository has been archived by the owner on Dec 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #63 from nre-learning/gc-fix
Browse files Browse the repository at this point in the history
Fixed GC goroutine; make GC interval configurable
  • Loading branch information
Mierdin authored Feb 4, 2019
2 parents 5c792fb + 3185bab commit c1f1c8d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type SyringeConfig struct {
HealthCheckInterval int
TSDBExportInterval int
TSDBEnabled bool
GCInterval int

LessonRepoRemote string
LessonRepoBranch string
Expand Down Expand Up @@ -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 = 30
} else {
config.GCInterval = gc
}

return &config, nil

}
14 changes: 8 additions & 6 deletions scheduler/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
Expand Down Expand Up @@ -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
}

Expand All @@ -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))
Expand Down

0 comments on commit c1f1c8d

Please sign in to comment.