Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ boolean write(Record record) {

@Nullable RecordWriter writer = writers.getIfPresent(routingPartitionKey);
if (writer == null && openWriters >= maxNumWriters) {
return false;
writers.cleanUp();
if (openWriters >= maxNumWriters) {
return false;
}
}
Comment on lines 165 to 170

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Calling writers.cleanUp() on every single write attempt that results in a spill can introduce significant CPU overhead and lock contention, especially when processing a large volume of records for partitions that exceed maxNumWriters. Since Guava's cleanUp() acquires locks on all cache segments, calling it repeatedly in a tight loop for every spilled record is inefficient.\n\nTo optimize this, consider rate-limiting the cleanUp() calls (e.g., at most once every second) by tracking the last cleanup time using a timestamp field (e.g., lastCleanupNanos) in DestinationState.\n\nNote: You will need to define private long lastCleanupNanos = 0L; as a field in the DestinationState class for this suggestion to compile.

      if (writer == null && openWriters >= maxNumWriters) {\n        long now = System.nanoTime();\n        if (now - lastCleanupNanos > 1000000000L) {\n          writers.cleanUp();\n          lastCleanupNanos = now;\n        }\n        if (openWriters >= maxNumWriters) {\n          return false;\n        }\n      }

writer = fetchWriterForPartition(routingPartitionKey, writer);
writer.write(record);
Expand Down
Loading