diff --git a/internal/caches/memory_fragment_pool.go b/internal/caches/memory_fragment_pool.go index 2ab2c67..9e4541a 100644 --- a/internal/caches/memory_fragment_pool.go +++ b/internal/caches/memory_fragment_pool.go @@ -15,6 +15,7 @@ import ( ) const ( + enableFragmentPool = false minMemoryFragmentPoolItemSize = 8 << 10 maxMemoryFragmentPoolItemSize = 128 << 20 maxItemsInMemoryFragmentPoolBucket = 1024 diff --git a/internal/caches/storage_memory.go b/internal/caches/storage_memory.go index 931092b..4c69a0a 100644 --- a/internal/caches/storage_memory.go +++ b/internal/caches/storage_memory.go @@ -517,7 +517,7 @@ func (this *MemoryStorage) flushItem(key string) { _ = this.Delete(key) // 重用内存,前提是确保内存不再被引用 - if ok && item.IsDone && !item.isReferring && len(item.BodyValue) > 0 { + if enableFragmentPool && ok && item.IsDone && !item.isReferring && len(item.BodyValue) > 0 { SharedFragmentMemoryPool.Put(item.BodyValue) } }() diff --git a/internal/caches/writer_memory.go b/internal/caches/writer_memory.go index 6e4fb9e..66c165a 100644 --- a/internal/caches/writer_memory.go +++ b/internal/caches/writer_memory.go @@ -32,7 +32,9 @@ func NewMemoryWriter(memoryStorage *MemoryStorage, key string, expiredAt int64, ModifiedAt: fasttime.Now().Unix(), Status: status, } - if expectedBodySize > 0 && expectedBodySize <= maxMemoryFragmentPoolItemSize { + if enableFragmentPool && + expectedBodySize > 0 && + expectedBodySize <= maxMemoryFragmentPoolItemSize { bodyBytes, ok := SharedFragmentMemoryPool.Get(expectedBodySize) // try to reuse memory if ok { valueItem.BodyValue = bodyBytes @@ -168,7 +170,8 @@ func (this *MemoryWriter) Discard() error { this.storage.locker.Lock() delete(this.storage.valuesMap, this.hash) - if this.item != nil && + if enableFragmentPool && + this.item != nil && !this.item.isReferring && cap(this.item.BodyValue) >= minMemoryFragmentPoolItemSize { SharedFragmentMemoryPool.Put(this.item.BodyValue)