mirror of
https://github.com/yusing/godoxy.git
synced 2025-07-25 13:24:03 +02:00
tweak(logging): rename write count variable and adjust buffer check interval
This commit is contained in:
parent
e41c6530ab
commit
9eb674029e
1 changed files with 4 additions and 5 deletions
|
@ -30,9 +30,8 @@ type (
|
||||||
writeLock sync.Mutex
|
writeLock sync.Mutex
|
||||||
closed bool
|
closed bool
|
||||||
|
|
||||||
wps int64
|
writeCount int64
|
||||||
bufSize int
|
bufSize int
|
||||||
lastAdjust time.Time
|
|
||||||
|
|
||||||
lineBufPool *synk.BytesPool // buffer pool for formatting a single log line
|
lineBufPool *synk.BytesPool // buffer pool for formatting a single log line
|
||||||
|
|
||||||
|
@ -69,7 +68,7 @@ const (
|
||||||
MinBufferSize = 4 * kilobyte
|
MinBufferSize = 4 * kilobyte
|
||||||
MaxBufferSize = 8 * megabyte
|
MaxBufferSize = 8 * megabyte
|
||||||
|
|
||||||
bufferAdjustInterval = time.Second // How often we check & adjust
|
bufferAdjustInterval = 5 * time.Second // How often we check & adjust
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultRotateInterval = time.Hour
|
const defaultRotateInterval = time.Hour
|
||||||
|
@ -297,11 +296,11 @@ func (l *AccessLogger) write(data []byte) {
|
||||||
} else if n < len(data) {
|
} else if n < len(data) {
|
||||||
l.handleErr(gperr.Errorf("%w, writing %d bytes, only %d written", io.ErrShortWrite, len(data), n))
|
l.handleErr(gperr.Errorf("%w, writing %d bytes, only %d written", io.ErrShortWrite, len(data), n))
|
||||||
}
|
}
|
||||||
atomic.AddInt64(&l.wps, int64(n))
|
atomic.AddInt64(&l.writeCount, int64(n))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *AccessLogger) adjustBuffer() {
|
func (l *AccessLogger) adjustBuffer() {
|
||||||
wps := int(atomic.SwapInt64(&l.wps, 0))
|
wps := int(atomic.SwapInt64(&l.writeCount, 0)) / int(bufferAdjustInterval.Seconds())
|
||||||
origBufSize := l.bufSize
|
origBufSize := l.bufSize
|
||||||
newBufSize := origBufSize
|
newBufSize := origBufSize
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue