mirror of
				https://github.com/TeaOSLab/EdgeNode.git
				synced 2025-11-04 07:40:56 +08:00 
			
		
		
		
	减少Daemon使用的内存
This commit is contained in:
		@@ -3,6 +3,7 @@
 | 
			
		||||
package compressions
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeNode/internal/utils"
 | 
			
		||||
	"io"
 | 
			
		||||
)
 | 
			
		||||
@@ -10,6 +11,10 @@ import (
 | 
			
		||||
var sharedBrotliReaderPool *ReaderPool
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	if teaconst.IsDaemon {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var maxSize = utils.SystemMemoryGB() * 256
 | 
			
		||||
	if maxSize == 0 {
 | 
			
		||||
		maxSize = 256
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,7 @@
 | 
			
		||||
package compressions
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeNode/internal/utils"
 | 
			
		||||
	"io"
 | 
			
		||||
)
 | 
			
		||||
@@ -10,6 +11,10 @@ import (
 | 
			
		||||
var sharedDeflateReaderPool *ReaderPool
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	if teaconst.IsDaemon {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var maxSize = utils.SystemMemoryGB() * 256
 | 
			
		||||
	if maxSize == 0 {
 | 
			
		||||
		maxSize = 256
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,7 @@
 | 
			
		||||
package compressions
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeNode/internal/utils"
 | 
			
		||||
	"io"
 | 
			
		||||
)
 | 
			
		||||
@@ -10,6 +11,10 @@ import (
 | 
			
		||||
var sharedGzipReaderPool *ReaderPool
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	if teaconst.IsDaemon {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var maxSize = utils.SystemMemoryGB() * 256
 | 
			
		||||
	if maxSize == 0 {
 | 
			
		||||
		maxSize = 256
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,7 @@
 | 
			
		||||
package compressions
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeNode/internal/utils"
 | 
			
		||||
	"io"
 | 
			
		||||
)
 | 
			
		||||
@@ -10,6 +11,10 @@ import (
 | 
			
		||||
var sharedZSTDReaderPool *ReaderPool
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	if teaconst.IsDaemon {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var maxSize = utils.SystemMemoryGB() * 256
 | 
			
		||||
	if maxSize == 0 {
 | 
			
		||||
		maxSize = 256
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,7 @@
 | 
			
		||||
package compressions
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeNode/internal/utils"
 | 
			
		||||
	"github.com/andybalholm/brotli"
 | 
			
		||||
	"io"
 | 
			
		||||
@@ -11,6 +12,10 @@ import (
 | 
			
		||||
var sharedBrotliWriterPool *WriterPool
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	if teaconst.IsDaemon {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var maxSize = utils.SystemMemoryGB() * 256
 | 
			
		||||
	if maxSize == 0 {
 | 
			
		||||
		maxSize = 256
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,7 @@ package compressions
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"compress/flate"
 | 
			
		||||
	teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeNode/internal/utils"
 | 
			
		||||
	"io"
 | 
			
		||||
)
 | 
			
		||||
@@ -11,6 +12,10 @@ import (
 | 
			
		||||
var sharedDeflateWriterPool *WriterPool
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	if teaconst.IsDaemon {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var maxSize = utils.SystemMemoryGB() * 256
 | 
			
		||||
	if maxSize == 0 {
 | 
			
		||||
		maxSize = 256
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,7 @@ package compressions
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"compress/gzip"
 | 
			
		||||
	teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeNode/internal/utils"
 | 
			
		||||
	"io"
 | 
			
		||||
)
 | 
			
		||||
@@ -11,6 +12,10 @@ import (
 | 
			
		||||
var sharedGzipWriterPool *WriterPool
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	if teaconst.IsDaemon {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var maxSize = utils.SystemMemoryGB() * 256
 | 
			
		||||
	if maxSize == 0 {
 | 
			
		||||
		maxSize = 256
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,7 @@
 | 
			
		||||
package compressions
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeNode/internal/utils"
 | 
			
		||||
	"github.com/klauspost/compress/zstd"
 | 
			
		||||
	"io"
 | 
			
		||||
@@ -11,6 +12,10 @@ import (
 | 
			
		||||
var sharedZSTDWriterPool *WriterPool
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	if teaconst.IsDaemon {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var maxSize = utils.SystemMemoryGB() * 256
 | 
			
		||||
	if maxSize == 0 {
 | 
			
		||||
		maxSize = 256
 | 
			
		||||
 
 | 
			
		||||
@@ -12,6 +12,7 @@ var (
 | 
			
		||||
 | 
			
		||||
	NodeId       int64 = 0
 | 
			
		||||
	NodeIdString       = ""
 | 
			
		||||
	IsDaemon           = false
 | 
			
		||||
 | 
			
		||||
	GlobalProductName = nodeconfigs.DefaultProductName
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -7,6 +7,7 @@ package firewalls
 | 
			
		||||
import (
 | 
			
		||||
	"bytes"
 | 
			
		||||
	"errors"
 | 
			
		||||
	teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeNode/internal/events"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeNode/internal/firewalls/nftables"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
 | 
			
		||||
@@ -21,6 +22,10 @@ import (
 | 
			
		||||
 | 
			
		||||
// check nft status, if being enabled we load it automatically
 | 
			
		||||
func init() {
 | 
			
		||||
	if teaconst.IsDaemon {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if runtime.GOOS == "linux" {
 | 
			
		||||
		var ticker = time.NewTicker(3 * time.Minute)
 | 
			
		||||
		go func() {
 | 
			
		||||
 
 | 
			
		||||
@@ -207,8 +207,9 @@ func (this *Node) Start() {
 | 
			
		||||
 | 
			
		||||
// Daemon 实现守护进程
 | 
			
		||||
func (this *Node) Daemon() {
 | 
			
		||||
	isDebug := lists.ContainsString(os.Args, "debug")
 | 
			
		||||
	isDebug = true
 | 
			
		||||
	teaconst.IsDaemon = true
 | 
			
		||||
 | 
			
		||||
	var isDebug = lists.ContainsString(os.Args, "debug")
 | 
			
		||||
	for {
 | 
			
		||||
		conn, err := this.sock.Dial()
 | 
			
		||||
		if err != nil {
 | 
			
		||||
@@ -227,7 +228,7 @@ func (this *Node) Daemon() {
 | 
			
		||||
				_ = os.Setenv("EdgeDaemon", "on")
 | 
			
		||||
				_ = os.Setenv("EdgeBackground", "on")
 | 
			
		||||
 | 
			
		||||
				cmd := exec.Command(exe)
 | 
			
		||||
				var cmd = exec.Command(exe)
 | 
			
		||||
				err = cmd.Start()
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					return err
 | 
			
		||||
 
 | 
			
		||||
@@ -9,7 +9,7 @@ var unixTime = time.Now().Unix()
 | 
			
		||||
var unixTimeMilli = time.Now().UnixMilli()
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	ticker := time.NewTicker(200 * time.Millisecond)
 | 
			
		||||
	var ticker = time.NewTicker(200 * time.Millisecond)
 | 
			
		||||
	goman.New(func() {
 | 
			
		||||
		for range ticker.C {
 | 
			
		||||
			unixTime = time.Now().Unix()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user