减少Daemon使用的内存

This commit is contained in:
GoEdgeLab
2022-07-26 09:41:43 +08:00
parent 222631bdb9
commit 99b7f77410
12 changed files with 51 additions and 4 deletions

View File

@@ -3,6 +3,7 @@
package compressions package compressions
import ( import (
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/utils" "github.com/TeaOSLab/EdgeNode/internal/utils"
"io" "io"
) )
@@ -10,6 +11,10 @@ import (
var sharedBrotliReaderPool *ReaderPool var sharedBrotliReaderPool *ReaderPool
func init() { func init() {
if teaconst.IsDaemon {
return
}
var maxSize = utils.SystemMemoryGB() * 256 var maxSize = utils.SystemMemoryGB() * 256
if maxSize == 0 { if maxSize == 0 {
maxSize = 256 maxSize = 256

View File

@@ -3,6 +3,7 @@
package compressions package compressions
import ( import (
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/utils" "github.com/TeaOSLab/EdgeNode/internal/utils"
"io" "io"
) )
@@ -10,6 +11,10 @@ import (
var sharedDeflateReaderPool *ReaderPool var sharedDeflateReaderPool *ReaderPool
func init() { func init() {
if teaconst.IsDaemon {
return
}
var maxSize = utils.SystemMemoryGB() * 256 var maxSize = utils.SystemMemoryGB() * 256
if maxSize == 0 { if maxSize == 0 {
maxSize = 256 maxSize = 256

View File

@@ -3,6 +3,7 @@
package compressions package compressions
import ( import (
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/utils" "github.com/TeaOSLab/EdgeNode/internal/utils"
"io" "io"
) )
@@ -10,6 +11,10 @@ import (
var sharedGzipReaderPool *ReaderPool var sharedGzipReaderPool *ReaderPool
func init() { func init() {
if teaconst.IsDaemon {
return
}
var maxSize = utils.SystemMemoryGB() * 256 var maxSize = utils.SystemMemoryGB() * 256
if maxSize == 0 { if maxSize == 0 {
maxSize = 256 maxSize = 256

View File

@@ -3,6 +3,7 @@
package compressions package compressions
import ( import (
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/utils" "github.com/TeaOSLab/EdgeNode/internal/utils"
"io" "io"
) )
@@ -10,6 +11,10 @@ import (
var sharedZSTDReaderPool *ReaderPool var sharedZSTDReaderPool *ReaderPool
func init() { func init() {
if teaconst.IsDaemon {
return
}
var maxSize = utils.SystemMemoryGB() * 256 var maxSize = utils.SystemMemoryGB() * 256
if maxSize == 0 { if maxSize == 0 {
maxSize = 256 maxSize = 256

View File

@@ -3,6 +3,7 @@
package compressions package compressions
import ( import (
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/utils" "github.com/TeaOSLab/EdgeNode/internal/utils"
"github.com/andybalholm/brotli" "github.com/andybalholm/brotli"
"io" "io"
@@ -11,6 +12,10 @@ import (
var sharedBrotliWriterPool *WriterPool var sharedBrotliWriterPool *WriterPool
func init() { func init() {
if teaconst.IsDaemon {
return
}
var maxSize = utils.SystemMemoryGB() * 256 var maxSize = utils.SystemMemoryGB() * 256
if maxSize == 0 { if maxSize == 0 {
maxSize = 256 maxSize = 256

View File

@@ -4,6 +4,7 @@ package compressions
import ( import (
"compress/flate" "compress/flate"
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/utils" "github.com/TeaOSLab/EdgeNode/internal/utils"
"io" "io"
) )
@@ -11,6 +12,10 @@ import (
var sharedDeflateWriterPool *WriterPool var sharedDeflateWriterPool *WriterPool
func init() { func init() {
if teaconst.IsDaemon {
return
}
var maxSize = utils.SystemMemoryGB() * 256 var maxSize = utils.SystemMemoryGB() * 256
if maxSize == 0 { if maxSize == 0 {
maxSize = 256 maxSize = 256

View File

@@ -4,6 +4,7 @@ package compressions
import ( import (
"compress/gzip" "compress/gzip"
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/utils" "github.com/TeaOSLab/EdgeNode/internal/utils"
"io" "io"
) )
@@ -11,6 +12,10 @@ import (
var sharedGzipWriterPool *WriterPool var sharedGzipWriterPool *WriterPool
func init() { func init() {
if teaconst.IsDaemon {
return
}
var maxSize = utils.SystemMemoryGB() * 256 var maxSize = utils.SystemMemoryGB() * 256
if maxSize == 0 { if maxSize == 0 {
maxSize = 256 maxSize = 256

View File

@@ -3,6 +3,7 @@
package compressions package compressions
import ( import (
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/utils" "github.com/TeaOSLab/EdgeNode/internal/utils"
"github.com/klauspost/compress/zstd" "github.com/klauspost/compress/zstd"
"io" "io"
@@ -11,6 +12,10 @@ import (
var sharedZSTDWriterPool *WriterPool var sharedZSTDWriterPool *WriterPool
func init() { func init() {
if teaconst.IsDaemon {
return
}
var maxSize = utils.SystemMemoryGB() * 256 var maxSize = utils.SystemMemoryGB() * 256
if maxSize == 0 { if maxSize == 0 {
maxSize = 256 maxSize = 256

View File

@@ -12,6 +12,7 @@ var (
NodeId int64 = 0 NodeId int64 = 0
NodeIdString = "" NodeIdString = ""
IsDaemon = false
GlobalProductName = nodeconfigs.DefaultProductName GlobalProductName = nodeconfigs.DefaultProductName

View File

@@ -7,6 +7,7 @@ package firewalls
import ( import (
"bytes" "bytes"
"errors" "errors"
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/events" "github.com/TeaOSLab/EdgeNode/internal/events"
"github.com/TeaOSLab/EdgeNode/internal/firewalls/nftables" "github.com/TeaOSLab/EdgeNode/internal/firewalls/nftables"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/remotelogs"
@@ -21,6 +22,10 @@ import (
// check nft status, if being enabled we load it automatically // check nft status, if being enabled we load it automatically
func init() { func init() {
if teaconst.IsDaemon {
return
}
if runtime.GOOS == "linux" { if runtime.GOOS == "linux" {
var ticker = time.NewTicker(3 * time.Minute) var ticker = time.NewTicker(3 * time.Minute)
go func() { go func() {

View File

@@ -207,8 +207,9 @@ func (this *Node) Start() {
// Daemon 实现守护进程 // Daemon 实现守护进程
func (this *Node) Daemon() { func (this *Node) Daemon() {
isDebug := lists.ContainsString(os.Args, "debug") teaconst.IsDaemon = true
isDebug = true
var isDebug = lists.ContainsString(os.Args, "debug")
for { for {
conn, err := this.sock.Dial() conn, err := this.sock.Dial()
if err != nil { if err != nil {
@@ -227,7 +228,7 @@ func (this *Node) Daemon() {
_ = os.Setenv("EdgeDaemon", "on") _ = os.Setenv("EdgeDaemon", "on")
_ = os.Setenv("EdgeBackground", "on") _ = os.Setenv("EdgeBackground", "on")
cmd := exec.Command(exe) var cmd = exec.Command(exe)
err = cmd.Start() err = cmd.Start()
if err != nil { if err != nil {
return err return err

View File

@@ -9,7 +9,7 @@ var unixTime = time.Now().Unix()
var unixTimeMilli = time.Now().UnixMilli() var unixTimeMilli = time.Now().UnixMilli()
func init() { func init() {
ticker := time.NewTicker(200 * time.Millisecond) var ticker = time.NewTicker(200 * time.Millisecond)
goman.New(func() { goman.New(func() {
for range ticker.C { for range ticker.C {
unixTime = time.Now().Unix() unixTime = time.Now().Unix()