示例#1
0
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)
	}
}
示例#2
0
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)
}