func (s *Scheme) runReader(reader factory.Reader, timer *time.Timer) { if s.warmupMessagesPerRun > 0 { logs.Logger.Info("Reading %d warmup messages", s.warmupMessagesPerRun) } var startTime, lastMessageTime time.Time buffer := make([]byte, s.bytesPerMessage*2) for i := 0; i < s.warmupMessagesPerRun; i++ { reader.Read(buffer) } logs.Logger.Info("Starting reading %d messages...", s.messagesPerRun) for { count, err := reader.Read(buffer) if err == io.EOF { break } lastMessageTime = time.Now() if startTime.IsZero() { startTime = lastMessageTime } timer.Reset(s.waitForLastMessage) s.countMessage(count, err) } logs.Logger.Info("Finished.") s.runTime = lastMessageTime.Sub(startTime) }
func (s *Scheme) RunReader(reader factory.Reader) { s.closer = reader defer s.done.Done() s.startReporter() buffer := make([]byte, s.bytesPerMessage*2) var ticker *time.Ticker if s.tickerTime > 0 { ticker = time.NewTicker(s.tickerTime) defer ticker.Stop() } for { if ticker != nil { <-ticker.C } if s.isClosed() { break } count, err := reader.Read(buffer) s.countMessage(count, err) } }
func (s *Scheme) RunReader(reader factory.Reader) { timer := time.NewTimer(time.Duration(1<<63 - 1)) wg := sync.WaitGroup{} wg.Add(1) go func() { defer wg.Done() s.runReader(reader, timer) }() <-timer.C err := reader.Close() if err != nil { logs.Logger.Warning("Error closing reader, %s", err.Error()) } wg.Wait() s.outputReport() }