mirror of
				https://github.com/TeaOSLab/EdgeNode.git
				synced 2025-11-04 07:40:56 +08:00 
			
		
		
		
	默认不启用内存分片管理
This commit is contained in:
		@@ -15,6 +15,7 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	enableFragmentPool                  = false
 | 
			
		||||
	minMemoryFragmentPoolItemSize       = 8 << 10
 | 
			
		||||
	maxMemoryFragmentPoolItemSize       = 128 << 20
 | 
			
		||||
	maxItemsInMemoryFragmentPoolBucket  = 1024
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
		}
 | 
			
		||||
	}()
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user