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