-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-7632: Support Compression Level #10826
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
Changes from all commits
6c10e27
d493d41
db7d404
29dbaf2
89c1182
b334052
8ef745b
c951110
2c96abf
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.kafka.common.config.ConfigException; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.kafka.common.config.SecurityConfig; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.kafka.common.metrics.Sensor; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.kafka.common.record.CompressionConfig; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.kafka.common.record.CompressionType; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.kafka.common.security.auth.SecurityProtocol; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.kafka.common.serialization.Serializer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -216,6 +217,12 @@ public class ProducerConfig extends AbstractConfig { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| + " values are <code>none</code>, <code>gzip</code>, <code>snappy</code>, <code>lz4</code>, or <code>zstd</code>. " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| + "Compression is of full batches of data, so the efficacy of batching will also impact the compression ratio (more batching means better compression)."; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** <code>compression.level</code> */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public static final String COMPRESSION_LEVEL_CONFIG = "compression.level"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private static final String COMPRESSION_LEVEL_DOC = "The compression level for all data generated by the producer. The default level and valid value is up to " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| + "compression.type. (<code>none</code>, <code>snappy</code>: not available. <code>gzip</code>: 1~9. <code>lz4</code>: 1~17. " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| + "<code>zstd</code>: -131072~22."; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** <code>metrics.sample.window.ms</code> */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public static final String METRICS_SAMPLE_WINDOW_MS_CONFIG = CommonClientConfigs.METRICS_SAMPLE_WINDOW_MS_CONFIG; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -350,6 +357,7 @@ public class ProducerConfig extends AbstractConfig { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Importance.LOW, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ACKS_DOC) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .define(COMPRESSION_TYPE_CONFIG, Type.STRING, CompressionType.NONE.name, in(Utils.enumOptions(CompressionType.class)), Importance.HIGH, COMPRESSION_TYPE_DOC) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .define(COMPRESSION_LEVEL_CONFIG, Type.STRING, "", Importance.MEDIUM, COMPRESSION_LEVEL_DOC) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
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. The KIP says the default value is null.
Contributor
Author
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. Could you kindly review the discussion here? |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .define(BATCH_SIZE_CONFIG, Type.INT, 16384, atLeast(0), Importance.MEDIUM, BATCH_SIZE_DOC) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .define(PARTITIONER_ADPATIVE_PARTITIONING_ENABLE_CONFIG, Type.BOOLEAN, true, Importance.LOW, PARTITIONER_ADPATIVE_PARTITIONING_ENABLE_DOC) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .define(PARTITIONER_AVAILABILITY_TIMEOUT_MS_CONFIG, Type.LONG, 0, atLeast(0), Importance.LOW, PARTITIONER_AVAILABILITY_TIMEOUT_MS_DOC) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -583,6 +591,45 @@ public ProducerConfig(Map<String, Object> props) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| super(CONFIG, props); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CompressionConfig getCompressionConfig(CompressionType compressionType) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (getString(ProducerConfig.COMPRESSION_LEVEL_CONFIG).isEmpty()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
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. Since only 3 cases use the compression level, what about moving the if/else inside each case block?
Suggested change
Member
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. Why don't we push some of these things to the enum itself?
Contributor
Author
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. The reason why I did not choose a simple approach like The reason why I chose to use 1. Easy to switch the compression typeFor example, If we limit the scope of per-codec options like 2. Can provide a default level.As @ijuma pointed out, we can not provide a default compression level with For these reasons, I run the overall benchmarks in here with per-config options (see 'Final Notes' section.) If the reviewers prefer this scheme, I will happily change it.
Member
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. Thanks @dongjinleekr for the explanations. My suggested change was logically identical, it's just a bit shorter. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| switch (compressionType) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case NONE: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return CompressionConfig.NONE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case GZIP: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return CompressionConfig.gzip().build(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case SNAPPY: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return CompressionConfig.snappy().build(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case LZ4: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return CompressionConfig.lz4().build(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case ZSTD: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return CompressionConfig.zstd().build(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| default: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new IllegalArgumentException("Unknown compression type: " + compressionType.name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| switch (compressionType) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case NONE: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return CompressionConfig.NONE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case GZIP: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return CompressionConfig.gzip().level(Integer.parseInt(getString(ProducerConfig.COMPRESSION_LEVEL_CONFIG))).build(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case SNAPPY: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return CompressionConfig.snappy().build(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case LZ4: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return CompressionConfig.lz4().level(Integer.parseInt(getString(ProducerConfig.COMPRESSION_LEVEL_CONFIG))).build(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case ZSTD: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return CompressionConfig.zstd().level(Integer.parseInt(getString(ProducerConfig.COMPRESSION_LEVEL_CONFIG))).build(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| default: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new IllegalArgumentException("Unknown compression type: " + compressionType.name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public CompressionConfig getCompressionConfig() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CompressionType compressionType = CompressionType.forName(getString(ProducerConfig.COMPRESSION_TYPE_CONFIG)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return getCompressionConfig(compressionType); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ProducerConfig(Map<?, ?> props, boolean doLog) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| super(CONFIG, props, doLog); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
Should we include the defaults too?
Uh oh!
There was an error while loading. Please reload this page.
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.
I think the reason why @dongjinleekr didn't include those is that they may change at the compression library level.