-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Adds long compression methods #3148
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
81e0943
add read
acslk 67c7b63
update deprecated guava calls
acslk d50fc52
add write and vsizeserde
acslk ad85067
add benchmark
acslk e2721f3
separate encoding and compression
acslk 20f2ace
add header and reformat
acslk 3132836
update doc
acslk 9090434
address PR comment
acslk eda3ead
fix buffer order
acslk e0b11d9
generate benchmark files
acslk dec5a0e
separate encoding strategy and format
acslk 7f8e32c
fix benchmark
acslk 660e78a
modify supplier write to channel
acslk 3f63314
add float NONE handling
acslk f0412dd
address PR comment
acslk 95fb994
address PR comment 2
acslk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
benchmarks/src/main/java/io/druid/benchmark/FloatCompressionBenchmark.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /* | ||
| * Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. Metamarkets licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package io.druid.benchmark; | ||
|
|
||
| // Run FloatCompressionBenchmarkFileGenerator to generate the required files before running this benchmark | ||
|
|
||
| import com.google.common.base.Supplier; | ||
| import com.google.common.io.Files; | ||
| import io.druid.segment.data.CompressedFloatsIndexedSupplier; | ||
| import io.druid.segment.data.IndexedFloats; | ||
| import org.openjdk.jmh.annotations.Benchmark; | ||
| import org.openjdk.jmh.annotations.BenchmarkMode; | ||
| import org.openjdk.jmh.annotations.Fork; | ||
| import org.openjdk.jmh.annotations.Measurement; | ||
| import org.openjdk.jmh.annotations.Mode; | ||
| import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
| import org.openjdk.jmh.annotations.Param; | ||
| import org.openjdk.jmh.annotations.Scope; | ||
| import org.openjdk.jmh.annotations.Setup; | ||
| import org.openjdk.jmh.annotations.State; | ||
| import org.openjdk.jmh.annotations.Warmup; | ||
| import org.openjdk.jmh.infra.Blackhole; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.net.URL; | ||
| import java.nio.ByteBuffer; | ||
| import java.nio.ByteOrder; | ||
| import java.util.Random; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| @State(Scope.Benchmark) | ||
| @Fork(value = 1) | ||
| @Warmup(iterations = 10) | ||
| @Measurement(iterations = 25) | ||
| @BenchmarkMode(Mode.AverageTime) | ||
| @OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
| public class FloatCompressionBenchmark | ||
| { | ||
| @Param("floatCompress/") | ||
| private static String dirPath; | ||
|
|
||
| @Param({"enumerate", "zipfLow", "zipfHigh", "sequential", "uniform"}) | ||
| private static String file; | ||
|
|
||
| @Param({"lz4", "none"}) | ||
| private static String strategy; | ||
|
|
||
| private Random rand; | ||
| private Supplier<IndexedFloats> supplier; | ||
|
|
||
| @Setup | ||
| public void setup() throws Exception | ||
| { | ||
| File dir = new File(dirPath); | ||
| File compFile = new File(dir, file + "-" + strategy); | ||
| rand = new Random(); | ||
| ByteBuffer buffer = Files.map(compFile); | ||
| supplier = CompressedFloatsIndexedSupplier.fromByteBuffer(buffer, ByteOrder.nativeOrder()); | ||
| } | ||
|
|
||
| @Benchmark | ||
| public void readContinuous(Blackhole bh) throws IOException | ||
| { | ||
| IndexedFloats indexedFloats = supplier.get(); | ||
| int count = indexedFloats.size(); | ||
| float sum = 0; | ||
| for (int i = 0; i < count; i++) { | ||
| sum += indexedFloats.get(i); | ||
| } | ||
| bh.consume(sum); | ||
| indexedFloats.close(); | ||
| } | ||
|
|
||
| @Benchmark | ||
| public void readSkipping(Blackhole bh) throws IOException | ||
| { | ||
| IndexedFloats indexedFloats = supplier.get(); | ||
| int count = indexedFloats.size(); | ||
| float sum = 0; | ||
| for (int i = 0; i < count; i += rand.nextInt(2000)) { | ||
| sum += indexedFloats.get(i); | ||
| } | ||
| bh.consume(sum); | ||
| indexedFloats.close(); | ||
| } | ||
|
|
||
| } | ||
195 changes: 195 additions & 0 deletions
195
benchmarks/src/main/java/io/druid/benchmark/FloatCompressionBenchmarkFileGenerator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,195 @@ | ||
| /* | ||
| * Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. Metamarkets licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package io.druid.benchmark; | ||
|
|
||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.common.io.ByteSink; | ||
| import io.druid.benchmark.datagen.BenchmarkColumnSchema; | ||
| import io.druid.benchmark.datagen.BenchmarkColumnValueGenerator; | ||
| import io.druid.segment.column.ValueType; | ||
| import io.druid.segment.data.CompressedObjectStrategy; | ||
| import io.druid.segment.data.CompressionFactory; | ||
| import io.druid.segment.data.FloatSupplierSerializer; | ||
| import io.druid.segment.data.TmpFileIOPeon; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.BufferedWriter; | ||
| import java.io.ByteArrayOutputStream; | ||
| import java.io.File; | ||
| import java.io.FileInputStream; | ||
| import java.io.FileOutputStream; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
| import java.io.OutputStream; | ||
| import java.io.OutputStreamWriter; | ||
| import java.io.Writer; | ||
| import java.net.URISyntaxException; | ||
| import java.net.URL; | ||
| import java.nio.ByteBuffer; | ||
| import java.nio.ByteOrder; | ||
| import java.nio.channels.FileChannel; | ||
| import java.nio.file.StandardOpenOption; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| public class FloatCompressionBenchmarkFileGenerator | ||
| { | ||
| public static final int ROW_NUM = 5000000; | ||
| public static final List<CompressedObjectStrategy.CompressionStrategy> compressions = | ||
| ImmutableList.of( | ||
| CompressedObjectStrategy.CompressionStrategy.LZ4, | ||
| CompressedObjectStrategy.CompressionStrategy.NONE | ||
| ); | ||
|
|
||
| private static String dirPath = "floatCompress/"; | ||
|
|
||
| public static void main(String[] args) throws IOException, URISyntaxException | ||
| { | ||
| if (args.length >= 1) { | ||
| dirPath = args[0]; | ||
| } | ||
|
|
||
| BenchmarkColumnSchema enumeratedSchema = BenchmarkColumnSchema.makeEnumerated("", ValueType.FLOAT, true, 1, 0d, | ||
| ImmutableList.<Object>of( | ||
| 0f, | ||
| 1.1f, | ||
| 2.2f, | ||
| 3.3f, | ||
| 4.4f | ||
| ), | ||
| ImmutableList.of( | ||
| 0.95, | ||
| 0.001, | ||
| 0.0189, | ||
| 0.03, | ||
| 0.0001 | ||
| ) | ||
| ); | ||
| BenchmarkColumnSchema zipfLowSchema = BenchmarkColumnSchema.makeZipf( | ||
| "", | ||
| ValueType.FLOAT, | ||
| true, | ||
| 1, | ||
| 0d, | ||
| -1, | ||
| 1000, | ||
| 1d | ||
| ); | ||
| BenchmarkColumnSchema zipfHighSchema = BenchmarkColumnSchema.makeZipf( | ||
| "", | ||
| ValueType.FLOAT, | ||
| true, | ||
| 1, | ||
| 0d, | ||
| -1, | ||
| 1000, | ||
| 3d | ||
| ); | ||
| BenchmarkColumnSchema sequentialSchema = BenchmarkColumnSchema.makeSequential( | ||
| "", | ||
| ValueType.FLOAT, | ||
| true, | ||
| 1, | ||
| 0d, | ||
| 1470187671, | ||
| 2000000000 | ||
| ); | ||
| BenchmarkColumnSchema uniformSchema = BenchmarkColumnSchema.makeContinuousUniform( | ||
| "", | ||
| ValueType.FLOAT, | ||
| true, | ||
| 1, | ||
| 0d, | ||
| 0, | ||
| 1000 | ||
| ); | ||
|
|
||
| Map<String, BenchmarkColumnValueGenerator> generators = new HashMap<>(); | ||
| generators.put("enumerate", new BenchmarkColumnValueGenerator(enumeratedSchema, 1)); | ||
| generators.put("zipfLow", new BenchmarkColumnValueGenerator(zipfLowSchema, 1)); | ||
| generators.put("zipfHigh", new BenchmarkColumnValueGenerator(zipfHighSchema, 1)); | ||
| generators.put("sequential", new BenchmarkColumnValueGenerator(sequentialSchema, 1)); | ||
| generators.put("uniform", new BenchmarkColumnValueGenerator(uniformSchema, 1)); | ||
|
|
||
| File dir = new File(dirPath); | ||
| dir.mkdir(); | ||
|
|
||
| // create data files using BenchmarkColunValueGenerator | ||
| for (Map.Entry<String, BenchmarkColumnValueGenerator> entry : generators.entrySet()) { | ||
| final File dataFile = new File(dir, entry.getKey()); | ||
| dataFile.delete(); | ||
| try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dataFile)))) { | ||
| for (int i = 0; i < ROW_NUM; i++) { | ||
| writer.write((Float) entry.getValue().generateRowValue() + "\n"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // create compressed files using all combinations of CompressionStrategy and FloatEncoding provided | ||
| for (Map.Entry<String, BenchmarkColumnValueGenerator> entry : generators.entrySet()) { | ||
| for (CompressedObjectStrategy.CompressionStrategy compression : compressions) { | ||
| String name = entry.getKey() + "-" + compression.toString(); | ||
| System.out.print(name + ": "); | ||
| File compFile = new File(dir, name); | ||
| compFile.delete(); | ||
| File dataFile = new File(dir, entry.getKey()); | ||
|
|
||
| TmpFileIOPeon iopeon = new TmpFileIOPeon(true); | ||
| FloatSupplierSerializer writer = CompressionFactory.getFloatSerializer( | ||
| iopeon, | ||
| "float", | ||
| ByteOrder.nativeOrder(), | ||
| compression | ||
| ); | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(dataFile))); | ||
|
|
||
| try (FileChannel output = FileChannel.open( | ||
| compFile.toPath(), | ||
| StandardOpenOption.CREATE_NEW, | ||
| StandardOpenOption.WRITE | ||
| )) { | ||
| writer.open(); | ||
| String line; | ||
| while ((line = br.readLine()) != null) { | ||
| writer.add(Float.parseFloat(line)); | ||
| } | ||
| final ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
| writer.closeAndConsolidate( | ||
| new ByteSink() | ||
| { | ||
| @Override | ||
| public OutputStream openStream() throws IOException | ||
| { | ||
| return baos; | ||
| } | ||
| } | ||
| ); | ||
| output.write(ByteBuffer.wrap(baos.toByteArray())); | ||
| } | ||
| finally { | ||
| iopeon.cleanup(); | ||
| br.close(); | ||
| } | ||
| System.out.print(compFile.length() / 1024 + "\n"); | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The JMH benchmarks should return the calculated value or feed them into a "blackhole", see:
"Dead Code" section:
http://java-performance.info/jmh/
http://hg.openjdk.java.net/code-tools/jmh/file/397891feda1b/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_09_Blackholes.java
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.
Used blackhole to consume sum instead of printing it in teardown.