优化代码

This commit is contained in:
GoEdgeLab
2024-03-28 17:17:34 +08:00
parent e242502948
commit 04bff814d9
27 changed files with 52 additions and 63 deletions

View File

@@ -4,10 +4,10 @@ import (
"sync"
)
var BytePool1k = NewBytePool(1024)
var BytePool4k = NewBytePool(4 * 1024)
var BytePool16k = NewBytePool(16 * 1024)
var BytePool32k = NewBytePool(32 * 1024)
var BytePool1k = NewBytePool(1 << 10)
var BytePool4k = NewBytePool(4 << 10)
var BytePool16k = NewBytePool(16 << 10)
var BytePool32k = NewBytePool(32 << 10)
// BytePool pool for get byte slice
type BytePool struct {

View File

@@ -4,8 +4,8 @@ package cachehits
import (
"github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/utils"
"github.com/TeaOSLab/EdgeNode/internal/utils/fasttime"
memutils "github.com/TeaOSLab/EdgeNode/internal/utils/mem"
"github.com/iwind/TeaGo/Tea"
"sync"
"sync/atomic"
@@ -38,7 +38,7 @@ func NewStat(goodRatio uint64) *Stat {
goodRatio = 5
}
var maxItems = utils.SystemMemoryGB() * 10_000
var maxItems = memutils.SystemMemoryGB() * 10_000
if maxItems <= 0 {
maxItems = 100_000
}

View File

@@ -3,8 +3,8 @@
package counters
import (
"github.com/TeaOSLab/EdgeNode/internal/utils"
"github.com/TeaOSLab/EdgeNode/internal/utils/fasttime"
memutils "github.com/TeaOSLab/EdgeNode/internal/utils/mem"
syncutils "github.com/TeaOSLab/EdgeNode/internal/utils/sync"
"github.com/cespare/xxhash"
"sync"
@@ -31,7 +31,7 @@ type Counter[T SupportedUIntType] struct {
// NewCounter create new counter
func NewCounter[T SupportedUIntType]() *Counter[T] {
var count = utils.SystemMemoryGB() * 8
var count = memutils.SystemMemoryGB() * 8
if count < 8 {
count = 8
}

View File

@@ -6,7 +6,7 @@ import (
"errors"
"fmt"
"github.com/TeaOSLab/EdgeNode/internal/events"
"github.com/TeaOSLab/EdgeNode/internal/utils"
memutils "github.com/TeaOSLab/EdgeNode/internal/utils/mem"
"github.com/cockroachdb/pebble"
"github.com/iwind/TeaGo/Tea"
"io"
@@ -90,7 +90,7 @@ func (this *Store) Open() error {
Logger: NewLogger(),
}
var memoryMB = utils.SystemMemoryGB() * 1
var memoryMB = memutils.SystemMemoryGB() * 1
if memoryMB > 256 {
memoryMB = 256
}

View File

@@ -1,6 +1,6 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package utils
package memutils
import (
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"

View File

@@ -1,7 +1,7 @@
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build go1.19
package utils
package memutils
import (
"runtime/debug"

View File

@@ -1,7 +1,7 @@
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build !go1.19
package utils
package memutils
// 设置软内存最大值
func setMaxMemory(memoryGB int) {

View File

@@ -1,14 +0,0 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package utils
import "testing"
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")
}