pgier commented on code in PR #799:
URL: https://github.com/apache/pulsar-client-go/pull/799#discussion_r912109886


##########
perf/perf-producer.go:
##########
@@ -101,25 +100,28 @@ func produce(produceArgs *ProduceArgs, stop <-chan 
struct{}) {
        payload := make([]byte, produceArgs.MessageSize)
 
        ch := make(chan float64)
-
-       go func(stopCh <-chan struct{}) {
-               var rateLimiter *rate.RateLimiter
-               if produceArgs.Rate > 0 {
-                       rateLimiter = rate.New(produceArgs.Rate, time.Second)
+       rateLimitCh := make(chan time.Time, produceArgs.Rate)
+       go func(rateLimit int, interval time.Duration) {
+               for {
+                       oldest := <-rateLimitCh
+                       if rateLimit > 0 { // 0 is defined as no limit enforced
+                               time.Sleep(interval - time.Since(oldest))
+                       }
                }
+       }(produceArgs.Rate, time.Second)

Review Comment:
   Can this function also be skipped if Rate is zero?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to