Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions core/src/jmh/java/org/apache/iceberg/AppendBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class AppendBenchmark {

@Setup
public void setupBenchmark() {
dropTable();
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't cleanup already called in line 96 in the tearDown method? in the other comment, you mentioned that table exist exception, is it leftover from previous run that was interrupted and not cleaned up?

Copy link
Member Author

Choose a reason for hiding this comment

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

I honestly didn't check, I think it was probably the previous run OOMing

initTable();
initDataFiles();
}
Expand Down
32 changes: 26 additions & 6 deletions core/src/main/java/org/apache/iceberg/SnapshotProducer.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicReferenceArray;
import java.util.function.Consumer;
import java.util.function.Function;
import org.apache.iceberg.encryption.EncryptedOutputFile;
Expand All @@ -69,10 +69,10 @@
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
import org.apache.iceberg.relocated.com.google.common.collect.Lists;
import org.apache.iceberg.relocated.com.google.common.collect.Queues;
import org.apache.iceberg.relocated.com.google.common.collect.Sets;
import org.apache.iceberg.relocated.com.google.common.math.IntMath;
import org.apache.iceberg.util.Exceptions;
import org.apache.iceberg.util.Pair;
import org.apache.iceberg.util.PropertyUtil;
import org.apache.iceberg.util.SnapshotUtil;
import org.apache.iceberg.util.Tasks;
Expand Down Expand Up @@ -669,13 +669,33 @@ private static <F> List<ManifestFile> writeManifests(
Collection<F> files, Function<List<F>, List<ManifestFile>> writeFunc) {
int parallelism = manifestWriterCount(ThreadPools.WORKER_THREAD_POOL_SIZE, files.size());
List<List<F>> groups = divide(files, parallelism);
Queue<ManifestFile> manifests = Queues.newConcurrentLinkedQueue();
Tasks.foreach(groups)

// Create a new list pairing each group with its index
List<Pair<Integer, List<F>>> groupsWithIndex = Lists.newArrayList();
for (int i = 0; i < groups.size(); i++) {
groupsWithIndex.add(Pair.of(i, groups.get(i)));
}

AtomicReferenceArray<List<ManifestFile>> results = new AtomicReferenceArray<>(groups.size());

Tasks.foreach(groupsWithIndex)
.stopOnFailure()
.throwFailureWhenFinished()
.executeWith(ThreadPools.getWorkerPool())
.run(group -> manifests.addAll(writeFunc.apply(group)));
return ImmutableList.copyOf(manifests);
.run(
indexedGroup -> {
int index = indexedGroup.first();
List<F> group = indexedGroup.second();
List<ManifestFile> groupResults = writeFunc.apply(group);
results.set(index, groupResults);
});

// Collect results in order
ImmutableList.Builder<ManifestFile> builder = ImmutableList.builder();
for (int i = 0; i < results.length(); i++) {
builder.addAll(results.get(i));
}
return builder.build();
}

private static <T> List<List<T>> divide(Collection<T> collection, int groupCount) {
Expand Down
1 change: 1 addition & 0 deletions jmh.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ configure(jmhProjects) {
forceGC = true
includeTests = true
humanOutputFile = file(jmhOutputPath)
jvmArgs = ['-Xmx32g']
Copy link
Contributor

Choose a reason for hiding this comment

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

[doubt] is this required for the change ?

Copy link
Member Author

Choose a reason for hiding this comment

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

This was to make the benchmarks run without ooming. The OOM had to due with caching the files to be added before committing. The other change fixes a "Table Already Exists" exception that gets thrown if you run the benchmark suite

resultsFile = file(jmhJsonOutputPath)
resultFormat = 'JSON'
includes = [jmhIncludeRegex]
Expand Down