nsqio / go-diskqueue

A Go package providing a filesystem-backed FIFO queue
MIT License
464 stars 103 forks source link

synchronized Depth call #11

Closed ploxiln closed 4 years ago

ploxiln commented 4 years ago

the Depth() method is more "eventually consistent", rather than always correct at the instant it returns, as pointed out by #10 - here is my proposed alternate-style fix

ploxiln commented 4 years ago

It looks like nsqd only explicitly queries backend depth when preparing stats:

[pierce@plo-mbp15 nsq]$ ag --context=1 --ignore='*_test.go' '\.Depth\('
nsqd/channel.go
256-func (c *Channel) Depth() int64 {
257: return int64(len(c.memoryMsgChan)) + c.backend.Depth()
258-}

nsqd/topic.go
238-func (t *Topic) Depth() int64 {
239: return int64(len(t.memoryMsgChan)) + t.backend.Depth()
240-}

nsqd/stats.go
26-          Channels:     channels,
27:          Depth:        t.Depth(),
28:          BackendDepth: t.backend.Depth(),
29-          MessageCount: atomic.LoadUint64(&t.messageCount),
--
62-          ChannelName:   c.name,
63:          Depth:         c.Depth(),
64:          BackendDepth:  c.backend.Depth(),
65-          InFlightCount: inflight,

So these Depth functions are only called by GetStats() -> NewChannelStats() / NewTopicStats(), while a few places call GetStats():

so anyway I think that's not too frequent

ploxiln commented 4 years ago

cc @mreiferson @jehiah