1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-03-17 20:17:48 +02:00

Run GC if some buffers were removerd from a pool

This commit is contained in:
DarthSim 2019-02-01 16:04:28 +06:00
parent c21e211c5a
commit 5d6c5bbc04

View File

@ -2,6 +2,7 @@ package main
import (
"bytes"
"runtime"
"sort"
"sync"
)
@ -58,12 +59,19 @@ func (p *bufPool) calibrateAndClean() {
p.defaultSize = maxInt(p.defaultSize, p.calls[0])
p.maxSize = maxInt(p.defaultSize, p.maxSize)
cleaned := false
for i, buf := range p.buffers {
if buf != nil && buf.Cap() > p.maxSize {
p.buffers[i] = nil
cleaned = true
}
}
if cleaned {
runtime.GC()
}
if prometheusEnabled {
setPrometheusBufferDefaultSize(p.name, p.defaultSize)
setPrometheusBufferMaxSize(p.name, p.maxSize)