dannycranmer commented on a change in pull request #17913:
URL: https://github.com/apache/flink/pull/17913#discussion_r756938508



##########
File path: 
flink-connectors/flink-connector-base/src/main/java/org/apache/flink/connector/base/sink/AsyncSinkBaseBuilder.java
##########
@@ -40,8 +40,9 @@
     private Integer maxBatchSize;
     private Integer maxInFlightRequests;
     private Integer maxBufferedRequests;
-    private Long flushOnBufferSizeInBytes;
+    private Long maxBatchSizeInBytes;
     private Long maxTimeInBufferMS;
+    private Long maxRecordSizeInBytes;

Review comment:
       Why are these not primitive? Are they nullable?

##########
File path: 
flink-connectors/flink-connector-base/src/main/java/org/apache/flink/connector/base/sink/writer/AsyncSinkWriter.java
##########
@@ -310,8 +309,32 @@ private void flush() {
 
         inFlightRequestsCount++;
         submitRequestEntries(batch, requestResult);
-        numRecordsOutCounter.inc(batchSize);
+    }
+
+    /**
+     * Creates the next batch of request entries while respecting the {@code 
maxBatchSize} and
+     * {@code flushOnBufferSizeBytes}. Also adds these to the metrics counters.

Review comment:
       `flushOnBufferSizeBytes` incorrect variable name

##########
File path: 
flink-connectors/flink-connector-base/src/main/java/org/apache/flink/connector/base/sink/writer/AsyncSinkWriter.java
##########
@@ -310,8 +309,32 @@ private void flush() {
 
         inFlightRequestsCount++;
         submitRequestEntries(batch, requestResult);
-        numRecordsOutCounter.inc(batchSize);
+    }
+
+    /**
+     * Creates the next batch of request entries while respecting the {@code 
maxBatchSize} and
+     * {@code flushOnBufferSizeBytes}. Also adds these to the metrics counters.
+     */
+    private List<RequestEntryT> createNextAvailableBatch() {
+        int batchSize = Math.min(maxBatchSize, bufferedRequestEntries.size());
+        List<RequestEntryT> batch = new ArrayList<>(batchSize);
+
+        int batchSizeBytes = 0;
+        for (int i = 0; i < batchSize; i++) {
+            if (batchSizeBytes + bufferedRequestEntries.peek().getSize()
+                    >= maxBatchSizeInBytes) {
+                break;
+            }
+            RequestEntryWrapper<RequestEntryT> elem = 
bufferedRequestEntries.remove();
+            batch.add(elem.getRequestEntry());
+            bufferedRequestEntriesTotalSizeInBytes -= elem.getSize();
+            batchSizeBytes += elem.getSize();

Review comment:
       Calling `.getSize()` multiple in the loop. Is it worth caching this 
value to a variable? Is it an expensive call? 

##########
File path: 
flink-connectors/flink-connector-base/src/main/java/org/apache/flink/connector/base/sink/writer/AsyncSinkWriter.java
##########
@@ -310,8 +309,32 @@ private void flush() {
 
         inFlightRequestsCount++;
         submitRequestEntries(batch, requestResult);
-        numRecordsOutCounter.inc(batchSize);
+    }
+
+    /**
+     * Creates the next batch of request entries while respecting the {@code 
maxBatchSize} and
+     * {@code flushOnBufferSizeBytes}. Also adds these to the metrics counters.
+     */
+    private List<RequestEntryT> createNextAvailableBatch() {
+        int batchSize = Math.min(maxBatchSize, bufferedRequestEntries.size());
+        List<RequestEntryT> batch = new ArrayList<>(batchSize);
+
+        int batchSizeBytes = 0;
+        for (int i = 0; i < batchSize; i++) {
+            if (batchSizeBytes + bufferedRequestEntries.peek().getSize()
+                    >= maxBatchSizeInBytes) {
+                break;
+            }

Review comment:
       It is ok if it is equal to maxBatchSizeInBytes? I think you just need 
`>` comparison




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