You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "ashwinpankaj (via GitHub)" <gi...@apache.org> on 2023/03/17 04:07:00 UTC

[GitHub] [kafka] ashwinpankaj commented on a diff in pull request #13410: ProducerPerformance: reduce cost of message randomisation

ashwinpankaj commented on code in PR #13410:
URL: https://github.com/apache/kafka/pull/13410#discussion_r1139688411


##########
tools/src/main/java/org/apache/kafka/tools/ProducerPerformance.java:
##########
@@ -200,6 +190,37 @@ static Properties readProps(List<String> producerProps, String producerConfig, S
         return props;
     }
 
+
+    static List<byte[]> generatePayloads(String payloadFilePath, String payloadDelimiter, Integer recordSize, Random random) throws IOException {
+        if (payloadFilePath != null) {
+            return readPayloadFile(payloadFilePath, payloadDelimiter);
+        } else if (recordSize != null) {
+            return generateRandomPayloads(recordSize, random);
+        } else {
+            throw new IllegalArgumentException("no payload File Path or record Size provided");
+        }
+    }
+
+
+    private static List<byte[]> generateRandomPayloads(final int recordSize, final Random random) {
+        if (recordSize == 0) {
+            final ArrayList<byte[]> bytes = new ArrayList<>(1);
+            bytes.add(new byte[0]);
+            return bytes;
+        }
+        int approximateTotalSize = 10 * 1024 * 1024;
+        int numberOfCandidates = Math.max(1, approximateTotalSize / Math.max(1, recordSize));

Review Comment:
   Why not use `numRecords` from start() instead ?
   Don't we run the risk of regressing `https://github.com/apache/kafka/pull/10469` if `numberOfCandidates` is less than `numRecords` ?



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org