-
Notifications
You must be signed in to change notification settings - Fork 946
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
[compaction]Add local sample config for sort compaction #3081
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1056,6 +1056,27 @@ public class CoreOptions implements Serializable { | |
+ "If the data size allocated for the sorting task is uneven,which may lead to performance bottlenecks, " | ||
+ "the config can be set to size."); | ||
|
||
public static final ConfigOption<Integer> SORT_COMPACTION_LOCAL_SAMPLE_SIZE = | ||
key("sort-compaction.local-sample.size") | ||
.intType() | ||
.noDefaultValue() | ||
.withDescription( | ||
"The size of local sample for sort-compaction.By default,the value is the sink parallelism * 1000."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the parameter could be magnification. int localSampleSize = parallelism * magnification. magnification should be greater than or equal to 20 |
||
|
||
public static final ConfigOption<Integer> SORT_COMPACTION_GLOBAL_SAMPLE_SIZE = | ||
key("sort-compaction.global-sample.size") | ||
.intType() | ||
.noDefaultValue() | ||
.withDescription( | ||
"The size of global sample for sort-compaction.By default,the value is the sink parallelism * 1000."); | ||
|
||
public static final ConfigOption<Integer> SORT_RANGE = | ||
key("sort-compaction.range.size") | ||
.intType() | ||
.noDefaultValue() | ||
.withDescription( | ||
"The range for sort-compaction.By default,the value is the sink parallelism * 10."); | ||
|
||
private final Options options; | ||
|
||
public CoreOptions(Map<String, String> options) { | ||
|
@@ -1126,6 +1147,18 @@ public boolean sortBySize() { | |
return options.get(SORT_RANG_STRATEGY) == RangeStrategy.SIZE; | ||
} | ||
|
||
public Optional<Integer> getLocalSampleSize() { | ||
return options.getOptional(SORT_COMPACTION_LOCAL_SAMPLE_SIZE); | ||
} | ||
|
||
public Optional<Integer> getGlobalSampleSize() { | ||
return options.getOptional(SORT_COMPACTION_GLOBAL_SAMPLE_SIZE); | ||
} | ||
|
||
public Optional<Integer> getSortRange() { | ||
return options.getOptional(SORT_RANGE); | ||
} | ||
|
||
public static FileFormat createFileFormat( | ||
Options options, ConfigOption<FileFormatType> formatOption) { | ||
String formatIdentifier = options.get(formatOption).toString(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,8 +99,13 @@ public static <KEY> DataStream<RowData> sortStreamByKey( | |
"The adaptive batch scheduler is not supported. Please set the sink parallelism using the key: " | ||
+ FlinkConnectorOptions.SINK_PARALLELISM.key()); | ||
} | ||
final int sampleSize = sinkParallelism * 1000; | ||
final int rangeNum = sinkParallelism * 10; | ||
final int localSampleSize = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. localSampleSize = sinkParallelism * sampleSignification There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done~ |
||
options.getLocalSampleSize().orElseGet(() -> sinkParallelism * 1000); | ||
final int globalSampleSize = | ||
options.getGlobalSampleSize().orElseGet(() -> sinkParallelism * 1000); | ||
final int rangeNum = options.getSortRange().orElseGet(() -> sinkParallelism * 10); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there is no need to make localSampleSize and globalSampleSize different, if you want a performance improvement when parallelism is large, just add one parameter of sampleSize option. 20 or 2000 times, default 1000. rangeNum still sinkParallelism * 10. |
||
|
||
validateSampleConfig(localSampleSize, globalSampleSize, rangeNum, sinkParallelism); | ||
|
||
int keyFieldCount = sortKeyType.getFieldCount(); | ||
int valueFieldCount = valueRowType.getFieldCount(); | ||
|
@@ -144,7 +149,8 @@ public Tuple2<KEY, RowData> map(RowData value) { | |
inputWithKey, | ||
shuffleKeyComparator, | ||
keyTypeInformation, | ||
sampleSize, | ||
localSampleSize, | ||
globalSampleSize, | ||
rangeNum, | ||
sinkParallelism, | ||
valueRowType, | ||
|
@@ -188,6 +194,22 @@ public InternalRow map(InternalRow value) { | |
.setParallelism(sinkParallelism); | ||
} | ||
|
||
private static void validateSampleConfig( | ||
int localSampleSize, int globalSampleSize, int rangeNum, int sinkParallelism) { | ||
if (globalSampleSize < rangeNum) { | ||
throw new IllegalArgumentException( | ||
String.format( | ||
"The global sample size %d should be greater than rangeNum %d.", | ||
globalSampleSize, rangeNum)); | ||
} | ||
if (sinkParallelism * localSampleSize < globalSampleSize) { | ||
throw new IllegalArgumentException( | ||
String.format( | ||
"The sum size %d of local sample must be greater than the global sample %d.", | ||
localSampleSize * sinkParallelism, globalSampleSize)); | ||
} | ||
} | ||
|
||
/** Abstract key from a row data. */ | ||
interface KeyAbstract<KEY> extends Serializable { | ||
default void open() {} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SORT_COMPACTION_SAMPLE_MAGNIFICATION