Skip to content

Commit

Permalink
Imp: delete time wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexStocks committed Jun 7, 2019
1 parent 3f195ce commit 8b0e100
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 26 deletions.
9 changes: 7 additions & 2 deletions change_log.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@
## develop history ##
---

- 2019/06/07
> Improvement
* use time.After instead of wheel.After
* add remark for tcp reading

- 2018/10/16
> Feature
* add rpc/micro CallOneway/AsyncCall
* version: v1.0.3

- 2018/08/19
> Feature
* use multiple service config in service configuration
Expand All @@ -32,7 +37,7 @@
- 2018/08/13
> Feature
* Add Micro

- 2018/08/07
> Improvement
* RPC package format: {2 Bytes Header len + Header + 2 Body len + Body} ---> {Header + Body}
Expand Down
18 changes: 6 additions & 12 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ func (c *client) dialTCP() Session {
}

log.Infof("net.DialTimeout(addr:%s, timeout:%v) = error:%+v", c.addr, connectTimeout, err)
// time.Sleep(connInterval)
<-wheel.After(connInterval)
time.Sleep(connInterval)
}
}

Expand Down Expand Up @@ -167,8 +166,7 @@ func (c *client) dialUDP() Session {
}
if err != nil {
log.Warnf("net.DialTimeout(addr:%s, timeout:%v) = error:%+v", c.addr, err)
// time.Sleep(connInterval)
<-wheel.After(connInterval)
time.Sleep(connInterval)
continue
}

Expand All @@ -177,8 +175,7 @@ func (c *client) dialUDP() Session {
if length, err = conn.Write(connectPingPackage[:]); err != nil {
conn.Close()
log.Warnf("conn.Write(%s) = {length:%d, err:%+v}", string(connectPingPackage), length, err)
// time.Sleep(connInterval)
<-wheel.After(connInterval)
time.Sleep(connInterval)
continue
}
conn.SetReadDeadline(time.Now().Add(1e9))
Expand All @@ -189,8 +186,7 @@ func (c *client) dialUDP() Session {
if err != nil {
log.Infof("conn{%#v}.Read() = {length:%d, err:%+v}", conn, length, err)
conn.Close()
// time.Sleep(connInterval)
<-wheel.After(connInterval)
time.Sleep(connInterval)
continue
}
//if err == nil {
Expand Down Expand Up @@ -228,8 +224,7 @@ func (c *client) dialWS() Session {
}

log.Infof("websocket.dialer.Dial(addr:%s) = error:%+v", c.addr, err)
// time.Sleep(connInterval)
<-wheel.After(connInterval)
time.Sleep(connInterval)
}
}

Expand Down Expand Up @@ -307,8 +302,7 @@ func (c *client) dialWSS() Session {
}

log.Infof("websocket.dialer.Dial(addr:%s) = error:%+v", c.addr, err)
// time.Sleep(connInterval)
<-wheel.After(connInterval)
time.Sleep(connInterval)
}
}

Expand Down
3 changes: 1 addition & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ func (s *server) runTcpEventLoop(newSession NewSessionCallback) {
return
}
if delay != 0 {
// time.Sleep(delay)
<-wheel.After(delay)
time.Sleep(delay)
}
client, err = s.accept(newSession)
if err != nil {
Expand Down
12 changes: 2 additions & 10 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ const (
// session
/////////////////////////////////////////

var (
wheel = NewWheel(time.Millisecond*100, 1200) // wheel longest span is 2 minute
)

func GetTimeWheel() *Wheel {
return wheel
}

// getty base session
type session struct {
name string
Expand Down Expand Up @@ -337,7 +329,7 @@ func (s *session) WritePkg(pkg interface{}, timeout time.Duration) error {
case s.wQ <- pkg:
break // for possible gen a new pkg

case <-wheel.After(timeout):
case <-time.After(timeout):
log.Warnf("%s, [session.WritePkg] wQ{len:%d, cap:%d}", s.Stat(), len(s.wQ), cap(s.wQ))
return ErrSessionBlocked
}
Expand Down Expand Up @@ -510,7 +502,7 @@ LOOP:
log.Infof("[session.handleLoop] drop writeout package{%#v}", outPkg)
}

case <-wheel.After(s.period):
case <-time.After(s.period):
if flag {
if wsFlag {
err := wsConn.writePing()
Expand Down

0 comments on commit 8b0e100

Please sign in to comment.