mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2026-05-05 14:25:20 +08:00
优化本地数据库性能
This commit is contained in:
@@ -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
13
internal/utils/exit.go
Normal 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)
|
||||
}
|
||||
19
internal/utils/fnv/hash.go
Normal file
19
internal/utils/fnv/hash.go
Normal 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
|
||||
}
|
||||
16
internal/utils/fnv/hash_test.go
Normal file
16
internal/utils/fnv/hash_test.go
Normal 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))
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
package sizes
|
||||
|
||||
const (
|
||||
K = 1024
|
||||
K int64 = 1024
|
||||
M = 1024 * K
|
||||
G = 1024 * M
|
||||
T = 1024 * G
|
||||
|
||||
Reference in New Issue
Block a user