Merge pull request #202 from safing/fix/windows-iphlp-bufsize

Increase max iphlp buffer size
This commit is contained in:
Daniel
2020-11-30 15:13:02 +01:00
committed by GitHub

View File

@@ -97,13 +97,20 @@ const (
const ( const (
startBufSize = 4096 startBufSize = 4096
bufSizeUses = 100
// bufSizeUsageTTL defines how often a buffer size is used before it is
// shrunk again.
bufSizeUsageTTL = 100
// maxBufSize is the maximum size we will allocate for responses. This was
// previously set at 65k, which was too little for some production cases.
maxBufSize = 1048576 // 2^20B, 1MB
) )
var ( var (
bufSize = startBufSize bufSize = startBufSize
bufSizeUsageLeft = bufSizeUses bufSizeUsesLeft = bufSizeUsageTTL
bufSizeLock sync.Mutex bufSizeLock sync.Mutex
) )
func getBufSize() int { func getBufSize() int {
@@ -111,12 +118,17 @@ func getBufSize() int {
defer bufSizeLock.Unlock() defer bufSizeLock.Unlock()
// using bufSize // using bufSize
bufSizeUsageLeft-- bufSizeUsesLeft--
// check if we want to reset // check if we want to reset
if bufSizeUsageLeft <= 0 { if bufSizeUsesLeft <= 0 {
// reset // decrease
bufSize = startBufSize bufSize /= 2
bufSizeUsageLeft = bufSizeUses // not too little
if bufSize < startBufSize {
bufSize = startBufSize
}
// reset counter
bufSizeUsesLeft = bufSizeUsageTTL
} }
return bufSize return bufSize
@@ -129,11 +141,11 @@ func increaseBufSize() int {
// increase // increase
bufSize *= 2 bufSize *= 2
// not too much // not too much
if bufSize > 65536 { if bufSize > maxBufSize {
bufSize = 65536 bufSize = maxBufSize
} }
// reset // reset
bufSizeUsageLeft = bufSizeUses bufSizeUsesLeft = bufSizeUsageTTL
// return new bufSize // return new bufSize
return bufSize return bufSize
} }