-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add record pool size to avoid using too much memory
- Loading branch information
1 parent
3121b22
commit d9ab557
Showing
7 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package util | ||
|
||
import "sync/atomic" | ||
|
||
type RecordSize struct { | ||
poolSize int64 | ||
realSize int64 | ||
} | ||
|
||
func (rs *RecordSize) SetPoolSize(size int64) { | ||
rs.poolSize = size | ||
} | ||
|
||
func (rs *RecordSize) Inc(size int64) { | ||
atomic.AddInt64(&rs.realSize, size) | ||
} | ||
|
||
func (rs *RecordSize) Reset() { | ||
atomic.StoreInt64(&rs.realSize, 0) | ||
} | ||
|
||
func (rs *RecordSize) Dec(size int64) { | ||
atomic.AddInt64(&rs.realSize, size*(-1)) | ||
} | ||
|
||
func (rs *RecordSize) Get() int64 { | ||
return atomic.LoadInt64(&rs.realSize) | ||
} | ||
|
||
func (rs *RecordSize) Allow() bool { | ||
realSize := atomic.LoadInt64(&rs.realSize) | ||
return realSize < rs.poolSize | ||
} | ||
|
||
var Rs RecordSize |