优化本地数据库性能

This commit is contained in:
GoEdgeLab
2022-03-15 18:32:39 +08:00
parent 240698ff0d
commit cbc97652a5
13 changed files with 940 additions and 515 deletions

View File

@@ -24,7 +24,11 @@ func init() {
var stats = []string{}
for _, stat := range SharedQueryStatManager.TopN(10) {
var avg = stat.CostTotal / float64(stat.Calls)
stats = append(stats, fmt.Sprintf("%.2fms/%.2fms/%.2fms - %d - %s", stat.CostMin*1000, stat.CostMax*1000, avg*1000, stat.Calls, stat.Query))
var query = stat.Query
if len(query) > 100 {
query = query[:100]
}
stats = append(stats, fmt.Sprintf("%.2fms/%.2fms/%.2fms - %d - %s", stat.CostMin*1000, stat.CostMax*1000, avg*1000, stat.Calls, query))
}
logs.Println("====DB STATS====\n" + strings.Join(stats, "\n"))
}

13
internal/utils/exit.go Normal file
View File

@@ -0,0 +1,13 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package utils
import (
"github.com/TeaOSLab/EdgeNode/internal/events"
"os"
)
func Exit() {
events.Notify(events.EventTerminated)
os.Exit(0)
}

View File

@@ -0,0 +1,19 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package fnv
const (
offset64 uint64 = 14695981039346656037
prime64 uint64 = 1099511628211
)
// Hash
// 非unique Hash
func Hash(key string) uint64 {
var hash = offset64
for _, b := range key {
hash ^= uint64(b)
hash *= prime64
}
return hash
}

View File

@@ -0,0 +1,16 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package fnv_test
import (
"github.com/TeaOSLab/EdgeNode/internal/utils/fnv"
"github.com/iwind/TeaGo/types"
"testing"
)
func TestHash(t *testing.T) {
for _, key := range []string{"costarring", "liquid", "hello"} {
var h = fnv.Hash(key)
t.Log(key + " => " + types.String(h))
}
}

View File

@@ -3,7 +3,7 @@
package sizes
const (
K = 1024
K int64 = 1024
M = 1024 * K
G = 1024 * M
T = 1024 * G