2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 10:58:55 +00:00

Merge pull request #4353 from MichaelEischer/tune-gc

Tune Go garbage collector
This commit is contained in:
Michael Eischer 2023-06-16 23:24:39 +02:00 committed by GitHub
commit 191c47d30e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,5 @@
Enhancement: Reduce memory usage by up to 25%
https://github.com/restic/restic/issues/3328
https://github.com/restic/restic/pull/4352
https://github.com/restic/restic/pull/4353

View File

@ -3,6 +3,7 @@ package main
import ( import (
"context" "context"
"math" "math"
"runtime"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
@ -205,6 +206,9 @@ func runPruneWithRepo(ctx context.Context, opts PruneOptions, gopts GlobalOption
return err return err
} }
// Trigger GC to reset garbage collection threshold
runtime.GC()
return doPrune(ctx, opts, gopts, repo, plan) return doPrune(ctx, opts, gopts, repo, plan)
} }

View File

@ -7,6 +7,7 @@ import (
"log" "log"
"os" "os"
"runtime" "runtime"
godebug "runtime/debug"
"github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/debug"
"github.com/restic/restic/internal/options" "github.com/restic/restic/internal/options"
@ -81,7 +82,16 @@ func needsPassword(cmd string) bool {
var logBuffer = bytes.NewBuffer(nil) var logBuffer = bytes.NewBuffer(nil)
func tweakGoGC() {
// lower GOGC from 100 to 50, unless it was manually overwritten by the user
oldValue := godebug.SetGCPercent(50)
if oldValue != 100 {
godebug.SetGCPercent(oldValue)
}
}
func main() { func main() {
tweakGoGC()
// install custom global logger into a buffer, if an error occurs // install custom global logger into a buffer, if an error occurs
// we can show the logs // we can show the logs
log.SetOutput(logBuffer) log.SetOutput(logBuffer)

View File

@ -7,6 +7,7 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"runtime"
"sort" "sort"
"sync" "sync"
@ -601,6 +602,9 @@ func (r *Repository) LoadIndex(ctx context.Context) error {
return err return err
} }
// Trigger GC to reset garbage collection threshold
runtime.GC()
if r.cfg.Version < 2 { if r.cfg.Version < 2 {
// sanity check // sanity check
ctx, cancel := context.WithCancel(ctx) ctx, cancel := context.WithCancel(ctx)