优化代码

This commit is contained in:
GoEdgeLab
2023-10-02 08:18:43 +08:00
parent 59cca9c6c7
commit 42150681d0
4 changed files with 4 additions and 5 deletions

View File

@@ -223,7 +223,7 @@ func (this *MemoryStorage) openWriter(key string, expiresAt int64, status int, h
delete(this.writingKeyMap, key)
this.locker.Unlock()
if valueItem != nil && valueItem.IsDone {
if valueItem != nil {
valueItem.TotalSize = int64(len(valueItem.HeaderValue) + len(valueItem.BodyValue) + len(key) + 256 /** meta size **/)
atomic.AddInt64(&this.usedSize, valueItem.TotalSize)

View File

@@ -138,7 +138,7 @@ func (this *MemoryWriter) Close() error {
func (this *MemoryWriter) Discard() error {
// 需要在Locker之外
defer this.once.Do(func() {
this.endFunc(nil)
this.endFunc(this.item)
})
this.storage.locker.Lock()

View File

@@ -4,7 +4,6 @@ import (
"github.com/TeaOSLab/EdgeNode/internal/utils"
"github.com/TeaOSLab/EdgeNode/internal/utils/expires"
"github.com/TeaOSLab/EdgeNode/internal/utils/fasttime"
"github.com/iwind/TeaGo/logs"
"sort"
"sync"
)
@@ -150,7 +149,6 @@ func (this *IPList) ContainsIPStrings(ipStrings []string) (item *IPItem, found b
func (this *IPList) SetDeleted() {
this.isDeleted = true
logs.Println("set deleted:", this.isDeleted) // TODO
}
func (this *IPList) addItem(item *IPItem, sortable bool) {

View File

@@ -12,6 +12,7 @@ func setMaxMemory(memoryGB int) {
if memoryGB <= 0 {
memoryGB = 1
}
var maxMemoryBytes = (int64(memoryGB) << 30) * 80 / 100 // 默认 80%
var maxMemoryBytes = (int64(memoryGB) << 30) * 75 / 100 // 默认 75%
debug.SetMemoryLimit(maxMemoryBytes)
}