mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-06 01:50:26 +08:00
调整缓存索引数据库缓存尺寸
This commit is contained in:
@@ -65,10 +65,10 @@ func (this *FileListDB) Open(dbPath string) error {
|
|||||||
this.dbPath = dbPath
|
this.dbPath = dbPath
|
||||||
|
|
||||||
// 动态调整Cache值
|
// 动态调整Cache值
|
||||||
var cacheSize = 32000
|
var cacheSize = 512
|
||||||
var memoryGB = utils.SystemMemoryGB()
|
var memoryGB = utils.SystemMemoryGB()
|
||||||
if memoryGB >= 8 {
|
if memoryGB >= 1 {
|
||||||
cacheSize += 32000 * memoryGB / 8
|
cacheSize = 128 * memoryGB
|
||||||
}
|
}
|
||||||
|
|
||||||
// write db
|
// write db
|
||||||
|
|||||||
@@ -4,12 +4,20 @@ package caches_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/caches"
|
"github.com/TeaOSLab/EdgeNode/internal/caches"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
_ "github.com/iwind/TeaGo/bootstrap"
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
|
"runtime"
|
||||||
|
"runtime/debug"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFileListDB_ListLFUItems(t *testing.T) {
|
func TestFileListDB_ListLFUItems(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var db = caches.NewFileListDB()
|
var db = caches.NewFileListDB()
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -34,6 +42,10 @@ func TestFileListDB_ListLFUItems(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileListDB_CleanMatchKey(t *testing.T) {
|
func TestFileListDB_CleanMatchKey(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var db = caches.NewFileListDB()
|
var db = caches.NewFileListDB()
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -62,6 +74,10 @@ func TestFileListDB_CleanMatchKey(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileListDB_CleanMatchPrefix(t *testing.T) {
|
func TestFileListDB_CleanMatchPrefix(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var db = caches.NewFileListDB()
|
var db = caches.NewFileListDB()
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -88,3 +104,67 @@ func TestFileListDB_CleanMatchPrefix(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFileListDB_Memory(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var db = caches.NewFileListDB()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
_ = db.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
|
err := db.Open(Tea.Root + "/data/db-0.db")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = db.Init()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Log(db.Total())
|
||||||
|
|
||||||
|
// load hashes
|
||||||
|
var maxId int64
|
||||||
|
var hashList []string
|
||||||
|
var before = time.Now()
|
||||||
|
for i := 0; i < 1_000; i++ {
|
||||||
|
hashList, maxId, err = db.ListHashes(maxId)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(hashList) == 0 {
|
||||||
|
t.Log("hashes loaded", time.Since(before).Seconds()*1000, "ms")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if i%100 == 0 {
|
||||||
|
t.Log(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runtime.GC()
|
||||||
|
debug.FreeOSMemory()
|
||||||
|
|
||||||
|
//time.Sleep(600 * time.Second)
|
||||||
|
|
||||||
|
for i := 0; i < 1_000; i++ {
|
||||||
|
_, err = db.ListLFUItems(5000)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if i%100 == 0 {
|
||||||
|
t.Log(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Log("loaded")
|
||||||
|
|
||||||
|
runtime.GC()
|
||||||
|
debug.FreeOSMemory()
|
||||||
|
|
||||||
|
time.Sleep(600 * time.Second)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user