-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Description
Version: go version go1.8.3 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/sulin/workspace/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/j0/z8rksv5911g9kwyfffq5y1rr0000gn/T/go-build131871117=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
When i use time.After for some short sleep, mostly 10ms~100ms.
I found the timer didn't expire at the expected time, but delay 10 seconds. this was occasionally, like 1/1000, but it really ruin my application.
The code is blow:
for !s._close {
p := newProtocol()
s.Lock()
delay := s.fec.onSend(p)
s.Unlock()
startTime := time.Now().UnixNano()
select {
case <-time.After(delay):
LOGGER.TraceF("normal %v: %v", delay, time.Duration(time.Now().UnixNano()-startTime))
case <-s.signal:
LOGGER.TraceF("break %v: %v", delay, time.Duration(time.Now().UnixNano()-startTime))
}
}Most log didn't delay much, like 10ms->12ms, I could accept it.
2017-09-03 16:18:18.094617288 [TRACE] normal 7.953537ms: 9.151017ms
2017-09-03 16:18:18.145271958 [TRACE] normal 8.877516ms: 10.193023ms
2017-09-03 16:18:18.220673023 [TRACE] normal 19.940444ms: 22.052824ms
2017-09-03 16:19:12.85975685 [TRACE] normal 10.94034ms: 13.224514ms
2017-09-03 16:19:12.885154309 [TRACE] normal 21.935108ms: 25.278368ms
But sometimes, the timer will delay very much, like 10ms->10s.
2017-09-03 16:18:52.915667148 [TRACE] normal 10.974347ms: 9.162969872s
2017-09-03 16:18:57.783207779 [TRACE] normal 21.896961ms: 4.867348206s