func (c *Cache) worker(exitChan chan bool) { var values *points.Points var sendTo chan *points.Points var forceReceive bool forceReceiveThreshold := cap(c.inputChan) / 10 ticker := time.NewTicker(c.metricInterval) defer ticker.Stop() MAIN_LOOP: for { if len(c.inputChan) > forceReceiveThreshold { forceReceive = true } else { forceReceive = false } if values == nil && !forceReceive { values = c.Pop() } if values != nil { sendTo = c.outputChan } else { sendTo = nil } select { case <-ticker.C: // checkpoint c.doCheckpoint() case query := <-c.queryChan: // carbonlink c.queryCnt++ reply := NewReply() if values != nil && values.Metric == query.Metric { reply.Points = values.Copy() } else if v, ok := c.data[query.Metric]; ok { reply.Points = v.Copy() } query.ReplyChan <- reply case sendTo <- values: // to persister values = nil case msg := <-c.inputChan: // from receiver if c.maxSize == 0 || c.size < c.maxSize { c.Add(msg) } else { c.overflowCnt++ } case <-exitChan: // exit break MAIN_LOOP } } }
func (test *udpTestCase) Eq(a *points.Points, b *points.Points) { if !a.Eq(b) { test.Fatalf("%#v != %#v", a, b) } }