fix(tsm1): limit concurrent WAL encodings to reduce memory pressure under heavy write load (#20814)

Co-authored-by: zhaoyun.248 <zhaoyun.248@bytedance.com>
pull/21601/head^2
Yun Zhao 2021-06-04 04:11:36 +08:00 committed by GitHub
parent cd546e9eb8
commit ce536037dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 275 additions and 444 deletions

View File

@ -45,7 +45,7 @@ func (p *Bytes) Put(c []byte) {
// LimitedBytes is a pool of byte slices that can be re-used. Slices in
// this pool will not be garbage collected when not in use. The pool will
// hold onto a fixed number of byte slices of a maximum size. If the pool
// is empty and max pool size has not been allocated yet, it will return a
// is empty or the required size is larger than max size, it will return a
// new byte slice. Byte slices added to the pool that are over the max size
// are dropped.
type LimitedBytes struct {

View File

@ -112,7 +112,9 @@ type WAL struct {
SegmentSize int
// statistics for the WAL
stats *WALStatistics
stats *WALStatistics
// limiter limits the max concurrency of waiting WAL writes.
limiter limiter.Fixed
}
@ -409,6 +411,9 @@ func (l *WAL) writeToLog(entry WALEntry) (int, error) {
// limit how many concurrent encodings can be in flight. Since we can only
// write one at a time to disk, a slow disk can cause the allocations below
// to increase quickly. If we're backed up, wait until others have completed.
l.limiter.Take()
defer l.limiter.Release()
bytes := bytesPool.Get(entry.MarshalSize())
b, err := entry.Encode(bytes)

File diff suppressed because it is too large Load Diff

View File

@ -88,7 +88,7 @@ func (p *SeriesPartition) Open() error {
p.index = NewSeriesIndex(p.IndexPath())
if err := p.index.Open(); err != nil {
return err
} else if p.index.Recover(p.segments); err != nil {
} else if err := p.index.Recover(p.segments); err != nil {
return err
}