optimize: increse concurrency of http latency test

This commit is contained in:
mzz2017 committed 2022-12-09 21:34:09 +08:00
1 parent 2445181f64
commit bcadc53dd3
4 files changed
+24 -5

No files matched your search

+22 -2
View File
@@ -3,6 +3,7 @@ package ntp
import (
"fmt"
"github.com/beevik/ntp"
"sync"
"time"
)
@@ -10,8 +11,27 @@ const (
DisplayFormat = "2006/01/02 15:04 MST"
)
func IsDatetimeSynced() (bool, time.Time, error) {
t, err := ntp.Time("ntp.aliyun.com")
var (
ntpSyncCache struct {
value bool
lastReq time.Time
realTime time.Time
mu sync.Mutex
}
)
func IsDatetimeSynced() (ok bool, t time.Time, err error) {
ntpSyncCache.mu.Lock()
defer ntpSyncCache.mu.Unlock()
if time.Since(ntpSyncCache.lastReq) < 5*time.Second {
return ntpSyncCache.value, ntpSyncCache.realTime, nil
}
defer func() {
ntpSyncCache.value = ok
ntpSyncCache.lastReq = time.Now()
ntpSyncCache.realTime = t
}()
t, err = ntp.Time("ntp.aliyun.com")
if err != nil {
return false, time.Time{}, fmt.Errorf("IsDatetimeSynced: %w", err)
}
+1
View File
@@ -133,6 +133,7 @@ func NewProcess(tmpl *Template, prestart func() error, poststart func() error) (
}
portList = append(portList, port)
}
log.Trace("portList for connectivity test: %+v", portList)
startTime := time.Now()
for i := 0; i < len(portList); {
conn, err := net.Dial("tcp", net.JoinHostPort("127.0.0.1", portList[i]))
+1 -1
View File
@@ -61,7 +61,7 @@ func GetHttpLatency(ctx *gin.Context) {
common.ResponseError(ctx, logError("bad request"))
return
}
wt, err = service.TestHttpLatency(wt, 8*time.Second, 4, false)
wt, err = service.TestHttpLatency(wt, 8*time.Second, 128, false)
if err != nil {
common.ResponseError(ctx, logError(err))
return
-2
View File
@@ -149,7 +149,6 @@ func TestHttpLatency(which []*configure.Which, timeout time.Duration, maxParalle
port = l.Addr().(*net.TCPAddr).Port
break
}
time.Sleep(30 * time.Millisecond)
}
v2rayInboundPort := strconv.Itoa(port)
pluginPort := 0
@@ -162,7 +161,6 @@ func TestHttpLatency(which []*configure.Which, timeout time.Duration, maxParalle
port = l.Addr().(*net.TCPAddr).Port
break
}
time.Sleep(30 * time.Millisecond)
}
pluginPort = port
pluginPortMap[i] = port