chia7712 commented on code in PR #21065:
URL: https://github.com/apache/kafka/pull/21065#discussion_r2645158450


##########
clients/src/main/java/org/apache/kafka/clients/producer/internals/BufferPool.java:
##########
@@ -274,6 +274,17 @@ public void deallocate(ByteBuffer buffer, int size) {
         }
     }
 
+    /**
+     * buffer is passed in only for use in tests
+     */
+    public void deallocateWithoutReuse(ByteBuffer buffer, int size) {
+        // We pass in a fresh buffer to be deallocated (added back to the pool 
if it is a poolable size)
+        // This is slightly inefficient if it's not a poolable size, but those 
tend to be small and
+        // this code is not hit often anyway
+        // This is useful if we're not 100% sure the buffer is not in use, 
which happens in some error cases
+        deallocate(ByteBuffer.allocate(size));

Review Comment:
   This approach might allocate more buffers then anticipated
   
   Could we consider decoupling batch expiration from buffer reclaiming? 
Specifically, we could stop reclaiming the buffer immediately when an in-flight 
batch expires, and instead wait for it to be returned to the pool naturally 
when the request completes



-- 
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