mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-08 11:20:27 +08:00
优化代码
This commit is contained in:
@@ -157,6 +157,7 @@ func (this *FileStorage) UpdatePolicy(newPolicy *serverconfigs.HTTPCachePolicy)
|
||||
IsFull: false,
|
||||
})
|
||||
}
|
||||
this.subDirs = subDirs
|
||||
this.checkDiskSpace()
|
||||
|
||||
err = newOptions.Init()
|
||||
@@ -482,7 +483,7 @@ func (this *FileStorage) openWriter(key string, expiredAt int64, status int, hea
|
||||
stat, err := os.Stat(cachePath)
|
||||
|
||||
// 检查两次写入缓存的时间是否过于相近,分片内容不受此限制
|
||||
if err == nil && !isPartial && time.Now().Sub(stat.ModTime()) <= 1*time.Second {
|
||||
if err == nil && !isPartial && time.Since(stat.ModTime()) <= 1*time.Second {
|
||||
// 防止并发连续写入
|
||||
return nil, ErrFileIsWriting
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package nodes
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"runtime"
|
||||
"testing"
|
||||
@@ -43,7 +44,7 @@ func TestHTTPClientPool_cleanClients(t *testing.T) {
|
||||
Version: 2,
|
||||
Addr: &serverconfigs.NetworkAddressConfig{Host: "127.0.0.1", PortRange: "1234"},
|
||||
}
|
||||
err := origin.Init(nil)
|
||||
err := origin.Init(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -65,7 +66,7 @@ func BenchmarkHTTPClientPool_Client(b *testing.B) {
|
||||
Version: 2,
|
||||
Addr: &serverconfigs.NetworkAddressConfig{Host: "127.0.0.1", PortRange: "1234"},
|
||||
}
|
||||
err := origin.Init(nil)
|
||||
err := origin.Init(context.Background())
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ func (this *HTTPRequest) doRoot() (isBreak bool) {
|
||||
}
|
||||
|
||||
var filename = strings.Replace(requestPath, "/", Tea.DS, -1)
|
||||
var filePath = ""
|
||||
var filePath string
|
||||
if len(filename) > 0 && filename[0:1] == Tea.DS {
|
||||
filePath = rootDir + filename
|
||||
} else {
|
||||
|
||||
@@ -2,6 +2,7 @@ package nodes
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||
@@ -194,7 +195,7 @@ func (this *Node) Start() {
|
||||
}
|
||||
teaconst.NodeId = nodeConfig.Id
|
||||
teaconst.NodeIdString = types.String(teaconst.NodeId)
|
||||
err, serverErrors := nodeConfig.Init(nil)
|
||||
err, serverErrors := nodeConfig.Init(context.Background())
|
||||
if err != nil {
|
||||
remotelogs.Error("NODE", "init node config failed: "+err.Error())
|
||||
return
|
||||
@@ -391,7 +392,7 @@ func (this *Node) syncConfig(taskVersion int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
err, serverErrors := nodeConfig.Init(nil)
|
||||
err, serverErrors := nodeConfig.Init(context.Background())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1034,7 +1035,7 @@ func (this *Node) reloadServer() {
|
||||
remotelogs.Debug("NODE", "reload "+types.String(countUpdatingServers)+" servers")
|
||||
}
|
||||
|
||||
err, serverErrors := newNodeConfig.Init(nil)
|
||||
err, serverErrors := newNodeConfig.Init(context.Background())
|
||||
if err != nil {
|
||||
remotelogs.Error("NODE", "apply server config error: "+err.Error())
|
||||
return
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
//go:build arm64
|
||||
// +build arm64
|
||||
|
||||
package nodes
|
||||
|
||||
// 处理异常
|
||||
func (this *Node) handlePanic() {
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ func TestList_ManyItems(t *testing.T) {
|
||||
})
|
||||
list.GC(time.Now().Unix() + 1)
|
||||
t.Log("gc", count, "items")
|
||||
t.Log(time.Now().Sub(now))
|
||||
t.Log(time.Since(now))
|
||||
}
|
||||
|
||||
func TestList_Map_Performance(t *testing.T) {
|
||||
@@ -140,7 +140,7 @@ func TestList_Map_Performance(t *testing.T) {
|
||||
for i := 0; i < 100_000; i++ {
|
||||
delete(m, int64(i))
|
||||
}
|
||||
t.Log(time.Now().Sub(now))
|
||||
t.Log(time.Since(now))
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -88,3 +88,7 @@ func (this *TestRequest) DisableAccessLog() {
|
||||
func (this *TestRequest) ProcessResponseHeaders(headers http.Header, status int) {
|
||||
|
||||
}
|
||||
|
||||
func (this *TestRequest) WAFMaxRequestSize() int64 {
|
||||
return 1 << 20
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ func (this *IPRange) Contains(netIP net.IP) bool {
|
||||
}
|
||||
case IPRangeTypeSingeIP:
|
||||
if this.IPFrom != nil {
|
||||
return bytes.Equal(this.IPFrom, netIP)
|
||||
return this.IPFrom.Equal(netIP)
|
||||
}
|
||||
case IPRangeTypeRange:
|
||||
return bytes.Compare(this.IPFrom, netIP) <= 0 && bytes.Compare(this.IPTo, netIP) >= 0
|
||||
|
||||
Reference in New Issue
Block a user