关于Keepalive相关部分.减少长连接.

This commit is contained in:
eson 2018-12-18 10:21:15 +08:00
parent 4c724ffc7b
commit 8de6e69857

View File

@ -2,9 +2,10 @@ package main
import (
"log"
"net/http"
"sync/atomic"
"time"
"474420502.top/eson/requests"
)
// PingWorker 专为ping服务, 保证不存在多余的Ping的, 让终端服务的请求合理减少.
@ -23,11 +24,10 @@ func (pw *PingWorker) PingNet() bool {
return atomic.LoadInt64(&pw.LastPingNet) == 1
}
timeout := time.Duration(5 * time.Second)
client := http.Client{
Timeout: timeout,
}
_, err := client.Get("http://14.17.96.148:3333/ippool/switch/imactive")
ses := requests.NewSession()
ses.SetConfig(requests.CRequestTimeout, 5)
_, err := ses.Get("http://14.17.96.148:3333/ippool/switch/imactive").Execute()
if err != nil {
log.Println("PingNet err http://14.17.96.148:3333/ippool/switch/imactive check Network")
atomic.StoreInt64(&pw.LastPingNet, 0)
@ -46,11 +46,10 @@ func (pw *PingWorker) PingVPN() bool {
return atomic.LoadInt64(&pw.LastPingVPN) == 1
}
timeout := time.Duration(5 * time.Second)
client := http.Client{
Timeout: timeout,
}
_, err := client.Get("http://10.10.10.1:3333/ippool/switch/imactive")
ses := requests.NewSession()
ses.SetConfig(requests.CRequestTimeout, 5)
_, err := ses.Get("http://10.10.10.1:3333/ippool/switch/imactive").Execute()
if err != nil {
log.Println("PingVPN err http://10.10.10.1:3333/ippool/switch/imactive check Network")
atomic.StoreInt64(&pw.LastPingVPN, 0)