Browse Source

Warn if Consumer is naively configured in a way that will cause busy-looping

Burke Libbey 12 years ago
parent
commit
4b108b6689
1 changed files with 6 additions and 0 deletions
  1. 6 0
      consumer.go

+ 6 - 0
consumer.go

@@ -1,5 +1,7 @@
 package sarama
 
+import "log"
+
 // OffsetMethod is passed in ConsumerConfig to tell the consumer how to determine the starting offset.
 type OffsetMethod int
 
@@ -72,6 +74,10 @@ func NewConsumer(client *Client, topic string, partition int32, group string, co
 		config = new(ConsumerConfig)
 	}
 
+	if config.MaxWaitTime == 0 && config.MinFetchSize == 0 && config.DefaultFetchSize == 0 {
+		log.Println("ConsumerConfig{MaxWaitTime, MinFetchSize, DefaultFetchSize} are all set to 0. This causes busy-looping when no events are available. You should seriously consider changing these values. MinFetchSize should be at least 1 in almost all scenarios.")
+	}
+
 	if config.DefaultFetchSize < 0 {
 		return nil, ConfigurationError("Invalid DefaultFetchSize")
 	} else if config.DefaultFetchSize == 0 {