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

[GitHub] [kafka] showuon commented on a diff in pull request #13782: Suggest for performance fix: KAFKA-9693 Kafka latency spikes caused by log segment flush on roll - trunk version

showuon commented on code in PR #13782:
URL: https://github.com/apache/kafka/pull/13782#discussion_r1219035983


##########
storage/src/main/java/org/apache/kafka/storage/internals/log/ProducerStateManager.java:
##########
@@ -681,7 +687,12 @@ private static void writeSnapshot(File file, Map<Long, ProducerStateEntry> entri
 
         try (FileChannel fileChannel = FileChannel.open(file.toPath(), StandardOpenOption.CREATE, StandardOpenOption.WRITE)) {
             fileChannel.write(buffer);
-            fileChannel.force(true);
+        }
+
+        if (scheduler != null) {
+            scheduler.scheduleOnce("flush-producer-snapshot", () -> Utils.flushFileQuietly(file.toPath(), "producer-snapshot"));
+        } else {
+            Utils.flushFileQuietly(file.toPath(), "producer-snapshot");

Review Comment:
   After this change, the fileChannel needs to open/close twice under `scheduler == null` case. Maybe we can jsut do it like this:
   ```
   try (FileChannel fileChannel = FileChannel.open(file.toPath(), StandardOpenOption.CREATE, StandardOpenOption.WRITE)) {
               fileChannel.write(buffer);
              if (scheduler == null) {
                   // directly flush to disk
                   fileChannel.force(true);
              }
           }
   
           if (scheduler != null) {
               scheduler.scheduleOnce("flush-producer-snapshot", () -> Utils.flushFileQuietly(file.toPath(), "producer-snapshot"));
           }
   ```
   
   WDYT?



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