mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2026-02-10 03:55:36 +08:00
优化代码
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
@@ -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"
|
||||
@@ -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) {
|
||||
@@ -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")
|
||||
}
|
||||
Reference in New Issue
Block a user