Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option --auto-flush to enable benchmarking of ion-java writer with auto-flush configured. #59

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 src/com/amazon/ion/benchmark/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Constants {
static final String JSON_USE_BIG_DECIMALS_NAME = "g";
static final String AUTO_VALUE = "auto";
static final String NONE_VALUE = "none";
static final String AUTO_FLUSH_ENABLED = "m";

private Constants() {
// Do not instantiate.
Expand Down
5 changes: 5 additions & 0 deletions src/com/amazon/ion/benchmark/IonUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ static IonWriterSupplier newBinaryWriterSupplier(OptionsCombinationBase options)
} else {
builder.withFloatBinary32Disabled();
}
if(options.autoFlush) {
builder.withAutoFlushEnabled();
} else {
builder.withAutoFlushDisabled();
}
if (options instanceof WriteOptionsCombination) {
// When this method is used by the read benchmark for converting the input file, 'options' will be a
// ReadOptionsCombination, which does not have the 'ionWriterUserBufferSize' value, because this value
Expand Down
6 changes: 5 additions & 1 deletion src/com/amazon/ion/benchmark/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class Main {
+ "[--results-file <file>] [--io-type <type>]... [--io-buffer-size <int>]... [--format <type>]... "
+ "[--api <api>]... [--ion-imports-for-input <file>] [--ion-imports-for-benchmark <file>]... "
+ "[--ion-flush-period <int>]... [--ion-length-preallocation <int>]... [--ion-float-width <int>]... "
+ "[--ion-use-symbol-tokens <bool>]... [--ion-writer-block-size <int>]... "
+ "[--ion-use-symbol-tokens <bool>]... [--ion-writer-block-size <int>]... [--auto-flush <bool>]..."
+ "[--json-use-big-decimals <bool>]... <input_file>\n"

+ " ion-java-benchmark read [--profile] [--limit <int>] [--mode <mode>] [--time-unit <unit>] "
Expand Down Expand Up @@ -200,6 +200,10 @@ public class Main {
+ "specified multiple times to compare different values. Ignored unless the format is ion_binary. "
+ "[default: auto]\n"

+ " -m --auto-flush <bool> If this option is enabled, then the flush operation will be executed "
+ "automatically when the size of the value is overflow "
linlin-s marked this conversation as resolved.
Show resolved Hide resolved
+ "[default: false]\n"

// 'read' options:

+ " -s --paths <file> A file containing a sequence of Ion s-expressions representing "
Expand Down
5 changes: 4 additions & 1 deletion src/com/amazon/ion/benchmark/OptionsCombinationBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
import java.nio.file.Path;
import java.util.function.Function;

import static com.amazon.ion.benchmark.Constants.API_NAME;
import static com.amazon.ion.benchmark.Constants.AUTO_FLUSH_ENABLED;
import static com.amazon.ion.benchmark.Constants.FLUSH_PERIOD_NAME;
import static com.amazon.ion.benchmark.Constants.FORMAT_NAME;
import static com.amazon.ion.benchmark.Constants.API_NAME;
import static com.amazon.ion.benchmark.Constants.ION_FLOAT_WIDTH_NAME;
import static com.amazon.ion.benchmark.Constants.ION_IMPORTS_FOR_BENCHMARK_NAME;
import static com.amazon.ion.benchmark.Constants.ION_IMPORTS_FOR_INPUT_NAME;
Expand Down Expand Up @@ -49,6 +50,7 @@ abstract class OptionsCombinationBase {
final boolean useSymbolTokens;
final int limit;
final boolean jsonUseBigDecimals;
final boolean autoFlush;

/**
* Retrieves and translates a value from the struct, if the field is present and is not the 'auto' value. Otherwise,
Expand Down Expand Up @@ -89,6 +91,7 @@ static <T> T getOrDefault(IonStruct options, String fieldName, Function<IonValue
useSymbolTokens = getOrDefault(optionsCombinationStruct, ION_USE_SYMBOL_TOKENS_NAME, val -> ((IonBool) val).booleanValue(), false);
limit = getOrDefault(optionsCombinationStruct, LIMIT_NAME, val -> ((IonInt) val).intValue(), Integer.MAX_VALUE);
jsonUseBigDecimals = getOrDefault(optionsCombinationStruct, JSON_USE_BIG_DECIMALS_NAME, val -> ((IonBool) val).booleanValue(), true);
autoFlush = getOrDefault(optionsCombinationStruct, AUTO_FLUSH_ENABLED, val -> ((IonBool) val).booleanValue(), false);
}

/**
Expand Down
12 changes: 11 additions & 1 deletion src/com/amazon/ion/benchmark/OptionsMatrixBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
import java.util.function.Predicate;
import java.util.function.Supplier;

import static com.amazon.ion.benchmark.Constants.API_NAME;
import static com.amazon.ion.benchmark.Constants.AUTO_FLUSH_ENABLED;
import static com.amazon.ion.benchmark.Constants.FLUSH_PERIOD_NAME;
import static com.amazon.ion.benchmark.Constants.FORMAT_NAME;
import static com.amazon.ion.benchmark.Constants.API_NAME;
import static com.amazon.ion.benchmark.Constants.ION_FLOAT_WIDTH_NAME;
import static com.amazon.ion.benchmark.Constants.ION_IMPORTS_FOR_BENCHMARK_NAME;
import static com.amazon.ion.benchmark.Constants.ION_IMPORTS_FOR_INPUT_NAME;
Expand Down Expand Up @@ -403,6 +404,15 @@ private static String getFileOrDefault(String fileNameOrNone, String defaultFile
() -> ION_SYSTEM.newBool(true),
OPTION_ONLY_APPLIES_TO_JSON
);
parseAndCombine(
optionsMatrix.get("--auto-flush"),
AUTO_FLUSH_ENABLED,
OptionsMatrixBase::getTrueOrNull,
ION_SYSTEM::newBool,
optionsCombinationStructs,
() -> ION_SYSTEM.newBool(false),
OPTION_ONLY_APPLIES_TO_ION_STREAMING
);
parseCommandSpecificOptions(optionsMatrix, optionsCombinationStructs);
serializedOptionsCombinations = serializeOptionsCombinations(optionsCombinationStructs);
if (profile) {
Expand Down
33 changes: 33 additions & 0 deletions tst/com/amazon/ion/benchmark/OptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ private static class ExpectedWriteOptionsCombination
extends ExpectedOptionsCombinationBase<ExpectedWriteOptionsCombination, WriteOptionsCombination> {

Integer ionWriterBlockSize = null;
Boolean autoFlush = null;

static ExpectedWriteOptionsCombination defaultOptions() {
return new ExpectedWriteOptionsCombination();
Expand All @@ -363,6 +364,11 @@ final ExpectedWriteOptionsCombination ionWriterBlockSize(Integer ionWriterBlockS
return this;
}

final ExpectedWriteOptionsCombination autoFlush(Boolean autoFlush) {
this.autoFlush = autoFlush;
return this;
}

@Override
void assertOptionsEqual(WriteOptionsCombination that) {
super.assertOptionsEqual(that);
Expand Down Expand Up @@ -1224,6 +1230,33 @@ public void ionWriterBlockSize() throws Exception {
assertTrue(expectedCombinations.isEmpty());
}

@Test
public void autoFlush() throws Exception {
List<WriteOptionsCombination> optionsCombinations = parseOptionsCombinations(
"write",
"--auto-flush",
"true",
"--auto-flush",
"false",
"--io-type",
"buffer",
"binaryStructs.10n"
);
assertEquals(2, optionsCombinations.size());
List<ExpectedWriteOptionsCombination> expectedCombinations = new ArrayList<>(2);

expectedCombinations.add(ExpectedWriteOptionsCombination.defaultOptions().autoFlush(true));
expectedCombinations.add(ExpectedWriteOptionsCombination.defaultOptions().autoFlush(false));

for (WriteOptionsCombination optionsCombination : optionsCombinations) {
expectedCombinations.removeIf(candidate -> nullSafeEquals(candidate.autoFlush, optionsCombination.autoFlush));

assertWriteTaskExecutesCorrectly("binaryStructs.10n", optionsCombination, Format.ION_BINARY, IoType.BUFFER);
assertWriteTaskExecutesCorrectly("textStructs.ion", optionsCombination, Format.ION_BINARY, IoType.BUFFER);
}
assertTrue(expectedCombinations.isEmpty());
}

@Test
public void writeAllTypes() throws Exception {
List<WriteOptionsCombination> optionsCombinations = parseOptionsCombinations(
Expand Down
Loading