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