Jelajahi Sumber

Remove unnecessary channel in producer performance tool

AJ Yoo 7 tahun lalu
induk
melakukan
da81d9c8f0
1 mengubah file dengan 3 tambahan dan 6 penghapusan
  1. 3 6
      tools/kafka-producer-performance/main.go

+ 3 - 6
tools/kafka-producer-performance/main.go

@@ -216,8 +216,7 @@ func main() {
 	}
 
 	// Print out metrics periodically.
-	metricsDone := make(chan struct{})
-	ctx, stopMetrics := context.WithCancel(context.Background())
+	ctx, cancel := context.WithCancel(context.Background())
 	go func(ctx context.Context) {
 		t := time.Tick(5 * time.Second)
 		for {
@@ -225,7 +224,6 @@ func main() {
 			case <-t:
 				printMetrics(os.Stdout, config.MetricRegistry)
 			case <-ctx.Done():
-				metricsDone <- struct{}{}
 				return
 			}
 		}
@@ -238,9 +236,8 @@ func main() {
 		runAsyncProducer(config, brokers, messages, *throughput)
 	}
 
-	stopMetrics()
-	<-metricsDone
-	close(metricsDone)
+	cancel()
+	<-ctx.Done()
 
 	// Print final metrics.
 	printMetrics(os.Stdout, config.MetricRegistry)