1GB gomemlim
This commit is contained in:
parent
dbaaac1a6e
commit
b148be72dc
@ -17,6 +17,7 @@ import (
|
|||||||
|
|
||||||
var profileTicker = time.NewTicker(1 * time.Second)
|
var profileTicker = time.NewTicker(1 * time.Second)
|
||||||
var perMinuteMap = make(map[time.Time]int)
|
var perMinuteMap = make(map[time.Time]int)
|
||||||
|
var timeSinceRefresh = time.Now()
|
||||||
|
|
||||||
//var profileTicker = time.NewTicker(120 * time.Second)
|
//var profileTicker = time.NewTicker(120 * time.Second)
|
||||||
|
|
||||||
@ -25,7 +26,7 @@ var profileCounter = 0
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
defer profile.Start(profile.MemProfile).Stop()
|
defer profile.Start(profile.MemProfile).Stop()
|
||||||
debug.SetMemoryLimit(2 * 1024 * 1024 * 1024)
|
debug.SetMemoryLimit(1 * 1024 * 1024 * 1024)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
@ -35,8 +36,9 @@ func main() {
|
|||||||
runtime.ReadMemStats(&m)
|
runtime.ReadMemStats(&m)
|
||||||
|
|
||||||
// if mem > 3GB and we havent captured a profile this min, capture it
|
// if mem > 3GB and we havent captured a profile this min, capture it
|
||||||
|
// or if its been 2 mins since last profile, capture it
|
||||||
t := time.Now().Truncate(time.Minute)
|
t := time.Now().Truncate(time.Minute)
|
||||||
if m.HeapAlloc > 3*1024*1024*1024 && perMinuteMap[t] == 0 {
|
if (m.HeapAlloc > uint64(3*1024*1024*1024) && perMinuteMap[t] == 0) || time.Since(timeSinceRefresh) > 2*time.Minute {
|
||||||
filename := "mem." + strconv.Itoa(profileCounter) + ".pprof"
|
filename := "mem." + strconv.Itoa(profileCounter) + ".pprof"
|
||||||
|
|
||||||
f, _ := os.Create(filename)
|
f, _ := os.Create(filename)
|
||||||
@ -48,6 +50,7 @@ func main() {
|
|||||||
|
|
||||||
profileCounter++
|
profileCounter++
|
||||||
perMinuteMap[t] = 1
|
perMinuteMap[t] = 1
|
||||||
|
timeSinceRefresh = time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -491,7 +491,7 @@ func (op *BackupOperation) do(
|
|||||||
|
|
||||||
// Sleep for 4 mins to let the memory usage settle down so that we have a better
|
// Sleep for 4 mins to let the memory usage settle down so that we have a better
|
||||||
// picture. Also allows pprof to run twice during this time.
|
// picture. Also allows pprof to run twice during this time.
|
||||||
// time.Sleep(4 * time.Minute)
|
time.Sleep(3 * time.Minute)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, clues.New("failed")
|
return nil, clues.New("failed")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user