mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-12-28 16:36:36 +08:00
优化内容压缩
* 取消用户设置的压缩级别,现在压缩级别通过系统自动设置 * Pool中的对象命中100万次时自动销毁,避免内存泄漏 * 降低Pool中的对象数量,避免占用太多内存 * 根据系统CPU线程数自动计算压缩级别,避免消耗太多CPU * zstd限制解码的最大Window * zstd使用低内存模式
This commit is contained in:
@@ -2,10 +2,13 @@
|
||||
|
||||
package compressions
|
||||
|
||||
import "sync/atomic"
|
||||
|
||||
type BaseReader struct {
|
||||
pool *ReaderPool
|
||||
|
||||
isFinished bool
|
||||
hits uint32
|
||||
}
|
||||
|
||||
func (this *BaseReader) SetPool(pool *ReaderPool) {
|
||||
@@ -13,8 +16,11 @@ func (this *BaseReader) SetPool(pool *ReaderPool) {
|
||||
}
|
||||
|
||||
func (this *BaseReader) Finish(obj Reader) error {
|
||||
if this.isFinished {
|
||||
return nil
|
||||
}
|
||||
err := obj.RawClose()
|
||||
if err == nil && this.pool != nil && !this.isFinished {
|
||||
if err == nil && this.pool != nil {
|
||||
this.pool.Put(obj)
|
||||
}
|
||||
this.isFinished = true
|
||||
@@ -24,3 +30,7 @@ func (this *BaseReader) Finish(obj Reader) error {
|
||||
func (this *BaseReader) ResetFinish() {
|
||||
this.isFinished = false
|
||||
}
|
||||
|
||||
func (this *BaseReader) IncreaseHit() uint32 {
|
||||
return atomic.AddUint32(&this.hits, 1)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user