Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
822e967874 | ||
|
|
2acf890b8e | ||
|
|
3909695b44 |
@@ -9,11 +9,13 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
const HashMapSharding = 11
|
||||
const HashMapSharding = 31
|
||||
|
||||
var bigIntPool = sync.Pool{New: func() any {
|
||||
return big.NewInt(0)
|
||||
}}
|
||||
var bigIntPool = sync.Pool{
|
||||
New: func() any {
|
||||
return big.NewInt(0)
|
||||
},
|
||||
}
|
||||
|
||||
// FileListHashMap 文件Hash列表
|
||||
type FileListHashMap struct {
|
||||
@@ -63,7 +65,7 @@ func (this *FileListHashMap) Load(db *FileListDB) error {
|
||||
this.AddHashes(hashList)
|
||||
lastId = maxId
|
||||
|
||||
maxLoops --
|
||||
maxLoops--
|
||||
if maxLoops <= 0 {
|
||||
break
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ func (this *OpenFileCache) Put(filename string, file *OpenFile) {
|
||||
defer this.locker.Unlock()
|
||||
|
||||
// 如果超过当前容量,则关闭最早的
|
||||
if this.count >= this.maxCount || this.usedSize >= this.capacitySize {
|
||||
if this.count >= this.maxCount || this.usedSize+file.size >= this.capacitySize {
|
||||
this.consumeHead()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -584,13 +584,19 @@ func (this *MemoryStorage) flushItem(key string) {
|
||||
}
|
||||
|
||||
func (this *MemoryStorage) memoryCapacityBytes() int64 {
|
||||
var maxSystemBytes = int64(utils.SystemMemoryBytes()) / 3 // 1/3 of the system memory
|
||||
|
||||
if this.policy == nil {
|
||||
return 0
|
||||
return maxSystemBytes
|
||||
}
|
||||
|
||||
if SharedManager.MaxMemoryCapacity != nil {
|
||||
var capacityBytes = SharedManager.MaxMemoryCapacity.Bytes()
|
||||
if capacityBytes > 0 {
|
||||
if capacityBytes > maxSystemBytes {
|
||||
return maxSystemBytes
|
||||
}
|
||||
|
||||
return capacityBytes
|
||||
}
|
||||
}
|
||||
@@ -599,17 +605,15 @@ func (this *MemoryStorage) memoryCapacityBytes() int64 {
|
||||
if capacity != nil {
|
||||
var capacityBytes = capacity.Bytes()
|
||||
if capacityBytes > 0 {
|
||||
if capacityBytes > maxSystemBytes {
|
||||
return maxSystemBytes
|
||||
}
|
||||
return capacityBytes
|
||||
}
|
||||
}
|
||||
|
||||
// half of the system memory
|
||||
var memoryGB = utils.SystemMemoryGB()
|
||||
if memoryGB < 1 {
|
||||
memoryGB = 1
|
||||
}
|
||||
|
||||
return int64(memoryGB) << 30 / 2
|
||||
// 1/4 of the system memory
|
||||
return maxSystemBytes
|
||||
}
|
||||
|
||||
func (this *MemoryStorage) deleteWithoutLocker(key string) error {
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
)
|
||||
|
||||
var systemTotalMemory = -1
|
||||
var systemMemoryBytes uint64
|
||||
|
||||
func init() {
|
||||
if !teaconst.IsMain {
|
||||
@@ -29,7 +30,9 @@ func SystemMemoryGB() int {
|
||||
return 1
|
||||
}
|
||||
|
||||
systemTotalMemory = int(stat.Total / (1<<30))
|
||||
systemMemoryBytes = stat.Total
|
||||
|
||||
systemTotalMemory = int(stat.Total / (1 << 30))
|
||||
if systemTotalMemory <= 0 {
|
||||
systemTotalMemory = 1
|
||||
}
|
||||
@@ -38,3 +41,8 @@ func SystemMemoryGB() int {
|
||||
|
||||
return systemTotalMemory
|
||||
}
|
||||
|
||||
// SystemMemoryBytes 系统内存总字节数
|
||||
func SystemMemoryBytes() uint64 {
|
||||
return systemMemoryBytes
|
||||
}
|
||||
|
||||
@@ -8,4 +8,7 @@ func TestSystemMemoryGB(t *testing.T) {
|
||||
t.Log(SystemMemoryGB())
|
||||
t.Log(SystemMemoryGB())
|
||||
t.Log(SystemMemoryGB())
|
||||
t.Log(SystemMemoryBytes())
|
||||
t.Log(SystemMemoryBytes())
|
||||
t.Log(SystemMemoryBytes()>>30, "GB")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user