Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
822e967874 | ||
|
|
2acf890b8e | ||
|
|
3909695b44 |
@@ -9,11 +9,13 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
const HashMapSharding = 11
|
const HashMapSharding = 31
|
||||||
|
|
||||||
var bigIntPool = sync.Pool{New: func() any {
|
var bigIntPool = sync.Pool{
|
||||||
return big.NewInt(0)
|
New: func() any {
|
||||||
}}
|
return big.NewInt(0)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
// FileListHashMap 文件Hash列表
|
// FileListHashMap 文件Hash列表
|
||||||
type FileListHashMap struct {
|
type FileListHashMap struct {
|
||||||
@@ -63,7 +65,7 @@ func (this *FileListHashMap) Load(db *FileListDB) error {
|
|||||||
this.AddHashes(hashList)
|
this.AddHashes(hashList)
|
||||||
lastId = maxId
|
lastId = maxId
|
||||||
|
|
||||||
maxLoops --
|
maxLoops--
|
||||||
if maxLoops <= 0 {
|
if maxLoops <= 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ func (this *OpenFileCache) Put(filename string, file *OpenFile) {
|
|||||||
defer this.locker.Unlock()
|
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()
|
this.consumeHead()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -584,13 +584,19 @@ func (this *MemoryStorage) flushItem(key string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *MemoryStorage) memoryCapacityBytes() int64 {
|
func (this *MemoryStorage) memoryCapacityBytes() int64 {
|
||||||
|
var maxSystemBytes = int64(utils.SystemMemoryBytes()) / 3 // 1/3 of the system memory
|
||||||
|
|
||||||
if this.policy == nil {
|
if this.policy == nil {
|
||||||
return 0
|
return maxSystemBytes
|
||||||
}
|
}
|
||||||
|
|
||||||
if SharedManager.MaxMemoryCapacity != nil {
|
if SharedManager.MaxMemoryCapacity != nil {
|
||||||
var capacityBytes = SharedManager.MaxMemoryCapacity.Bytes()
|
var capacityBytes = SharedManager.MaxMemoryCapacity.Bytes()
|
||||||
if capacityBytes > 0 {
|
if capacityBytes > 0 {
|
||||||
|
if capacityBytes > maxSystemBytes {
|
||||||
|
return maxSystemBytes
|
||||||
|
}
|
||||||
|
|
||||||
return capacityBytes
|
return capacityBytes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -599,17 +605,15 @@ func (this *MemoryStorage) memoryCapacityBytes() int64 {
|
|||||||
if capacity != nil {
|
if capacity != nil {
|
||||||
var capacityBytes = capacity.Bytes()
|
var capacityBytes = capacity.Bytes()
|
||||||
if capacityBytes > 0 {
|
if capacityBytes > 0 {
|
||||||
|
if capacityBytes > maxSystemBytes {
|
||||||
|
return maxSystemBytes
|
||||||
|
}
|
||||||
return capacityBytes
|
return capacityBytes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// half of the system memory
|
// 1/4 of the system memory
|
||||||
var memoryGB = utils.SystemMemoryGB()
|
return maxSystemBytes
|
||||||
if memoryGB < 1 {
|
|
||||||
memoryGB = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
return int64(memoryGB) << 30 / 2
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *MemoryStorage) deleteWithoutLocker(key string) error {
|
func (this *MemoryStorage) deleteWithoutLocker(key string) error {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var systemTotalMemory = -1
|
var systemTotalMemory = -1
|
||||||
|
var systemMemoryBytes uint64
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !teaconst.IsMain {
|
if !teaconst.IsMain {
|
||||||
@@ -29,7 +30,9 @@ func SystemMemoryGB() int {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
systemTotalMemory = int(stat.Total / (1<<30))
|
systemMemoryBytes = stat.Total
|
||||||
|
|
||||||
|
systemTotalMemory = int(stat.Total / (1 << 30))
|
||||||
if systemTotalMemory <= 0 {
|
if systemTotalMemory <= 0 {
|
||||||
systemTotalMemory = 1
|
systemTotalMemory = 1
|
||||||
}
|
}
|
||||||
@@ -38,3 +41,8 @@ func SystemMemoryGB() int {
|
|||||||
|
|
||||||
return systemTotalMemory
|
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(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