Skip to content

Commit

Permalink
explictly run garbage collection after loading credentials
Browse files Browse the repository at this point in the history
Decrypting the credentials requires a lot of memory, such that later
garbage collections only happen after doubling that memory usage again.
Explictly run a GC to reset the memory usage reference level.
  • Loading branch information
MichaelEischer committed Oct 10, 2024
1 parent ccdebc5 commit eeb4da5
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/calendarsync/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"runtime"
"time"

"github.com/inovex/CalendarSync/internal/auth"
Expand Down Expand Up @@ -180,6 +181,12 @@ func Run(c *cli.Context) error {
}
log.Info("loaded sink adapter", "adapter", cfg.Sink.Adapter.Type, "calendar", cfg.Sink.Adapter.Calendar)

// By default go runs a garbage collection once the memory usage doubles compared to the last GC run.
// Decrypting the storage in NewSourceAdapterFromConfig/NewSinkAdapterFromConfig requires a lot of memory,
// such that the next GC only trigger once the memory usage double compared to that peak. Explicitly trigger
// a GC to reset the memory usage reference level.
runtime.GC()

if log.GetLevel() == log.DebugLevel {
for _, transformation := range cfg.Transformations {
log.Debug("configured transformer", "name", transformation.Name, "config", transformation.Config)
Expand Down

0 comments on commit eeb4da5

Please sign in to comment.