-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Fork TDigest library #96086
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
Fork TDigest library #96086
Changes from all commits
Commits
Show all changes
72 commits
Select commit
Hold shift + click to select a range
3c6c424
Initial import for TDigest forking.
kkrik-es d719767
Fix MedianTest.
kkrik-es e816b57
Fix Dist.
kkrik-es 0079943
Fix AVLTreeDigest.quantile to match Dist for uniform centroids.
kkrik-es 0a18e70
Update docs/changelog/96086.yaml
kkrik-es 96ea462
Fix `MergingDigest.quantile` to match `Dist` on uniform distribution.
kkrik-es 56350ee
Add merging to TDigestState.hashCode and .equals.
kkrik-es d731aee
Fix style violations for tdigest library.
kkrik-es 18c1cd5
Fix typo.
kkrik-es f96b4d2
Fix more style violations.
kkrik-es 6d0201b
Fix more style violations.
kkrik-es 9d48856
Fix remaining style violations in tdigest library.
kkrik-es 68e489f
Update results in docs based on the forked tdigest.
kkrik-es 2b3b463
Fix YAML tests in aggs module.
kkrik-es 0d6ea1e
Fix YAML tests in x-pack/plugin.
kkrik-es 98c1146
Skip failing V7 compat tests in modules/aggregations.
kkrik-es d49ed67
Fix TDigest library unittests.
kkrik-es 13f17e6
Remove YAML test versions for older releases.
kkrik-es 5d9ae8e
Fix test failures in docs and mixed cluster.
kkrik-es 1ad14f8
Reduce buffer sizes in MergingDigest to avoid oom.
kkrik-es af93c26
Exclude more failing V7 compatibility tests.
kkrik-es d82ec3e
Update results for JdbcCsvSpecIT tests.
kkrik-es c9ab354
Update results for JdbcDocCsvSpecIT tests.
kkrik-es c19de44
Revert unrelated change.
kkrik-es 9753468
More test fixes.
kkrik-es a23ae32
Use version skips instead of blacklisting in mixed cluster tests.
kkrik-es 054cd90
Switch TDigestState back to AVLTreeDigest.
kkrik-es 2ccefde
Update docs and tests with AVLTreeDigest output.
kkrik-es 3801358
Update flaky test.
kkrik-es 52ae1ff
Remove dead code, esp around tracking of incoming data.
kkrik-es 6c05469
Update docs/changelog/96086.yaml
kkrik-es 082ac3c
Delete docs/changelog/96086.yaml
kkrik-es 5352c96
Remove explicit compression calls.
kkrik-es 90b21bc
Merge remote-tracking branch 'upstream/fix/95903' into fix/95903
kkrik-es 0003908
Revert "Remove explicit compression calls."
kkrik-es 91fd594
Remove explicit compression calls to MedianAbsoluteDeviation input.
kkrik-es 4ff173a
Add unittests for AVL and merging digest accuracy.
kkrik-es 281bfc7
Fix spotless violations.
kkrik-es e382efa
Delete redundant tests and benchmarks.
kkrik-es 60ec86f
Fix spotless violation.
kkrik-es fc512a7
Use the old implementation of AVLTreeDigest.
kkrik-es 8bd54c8
Merge branch 'main' into fix/95903
kkrik-es e53bcc8
Update docs with latest percentile results.
kkrik-es 6b29dc7
Update docs with latest percentile results.
kkrik-es b66664c
Merge branch 'main' into fix/95903
kkrik-es fe3facd
Remove repeated compression calls.
kkrik-es 7389bdc
Update more percentile results.
kkrik-es 0ff89ae
Use approximate percentile values in integration tests.
kkrik-es 497202b
Fix expected percentile value in test.
kkrik-es 093abb7
Revert in-place node updates in AVL tree.
kkrik-es b0c7870
Add SortingDigest and HybridDigest.
kkrik-es 40f1861
Remove deps to the 3.2 library.
kkrik-es 248560d
Remove unused licenses for tdigest.
kkrik-es 2336b11
Revert changes for SortingDigest and HybridDigest.
kkrik-es ec87dea
Remove unused Histogram classes and unit tests.
kkrik-es 5e06d79
Remove Comparison class, not used.
kkrik-es 3e12dd4
Merge branch 'main' into fix/95903
kkrik-es 063ef27
Small fixes.
kkrik-es c028d9c
Merge branch 'main' into fix/95903
kkrik-es dc739af
Add javadoc and tests.
kkrik-es 17b03cf
Remove special logic for singletons in the boundaries.
kkrik-es 079a8c3
Revert changes to expected values in tests.
kkrik-es 47414c7
Revert changes to expected values in tests.
kkrik-es b8f7c00
Merge branch 'main' into fix/95903
kkrik-es 7718dbb
Tentatively restore percentile rank expected results.
kkrik-es 4df40da
Use cdf version from 3.2
kkrik-es 77c13eb
Revert "Tentatively restore percentile rank expected results."
kkrik-es 4724905
Revert remaining changes compared to main.
kkrik-es 64950c4
Revert excluded V7 compat tests.
kkrik-es 7251150
Exclude V7 compat tests still failing.
kkrik-es 4a78005
Exclude V7 compat tests still failing.
kkrik-es 97ad6a9
Restore bySize function in TDigest and subclasses.
kkrik-es 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
79 changes: 79 additions & 0 deletions
79
benchmarks/src/main/java/org/elasticsearch/benchmark/tdigest/SortBench.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,79 @@ | ||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. 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. | ||
| * | ||
| * This project is based on a modification of https://github.com/tdunning/t-digest which is licensed under the Apache 2.0 License. | ||
| */ | ||
|
|
||
| package org.elasticsearch.benchmark.tdigest; | ||
|
|
||
| import org.elasticsearch.tdigest.Sort; | ||
| 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.Threads; | ||
| import org.openjdk.jmh.annotations.Warmup; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Random; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| /** Explores the performance of Sort on pathological input data. */ | ||
| @BenchmarkMode(Mode.AverageTime) | ||
| @OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
| @Warmup(iterations = 10, time = 3, timeUnit = TimeUnit.SECONDS) | ||
| @Measurement(iterations = 20, time = 2, timeUnit = TimeUnit.SECONDS) | ||
| @Fork(1) | ||
| @Threads(1) | ||
| @State(Scope.Thread) | ||
| public class SortBench { | ||
| private final int size = 100000; | ||
| private final double[] values = new double[size]; | ||
|
|
||
| @Param({ "0", "1", "-1" }) | ||
| public int sortDirection; | ||
|
|
||
| @Setup | ||
| public void setup() { | ||
| Random prng = new Random(999983); | ||
| for (int i = 0; i < size; i++) { | ||
| values[i] = prng.nextDouble(); | ||
| } | ||
| if (sortDirection > 0) { | ||
| Arrays.sort(values); | ||
| } else if (sortDirection < 0) { | ||
| Arrays.sort(values); | ||
| Sort.reverse(values, 0, values.length); | ||
| } | ||
| } | ||
|
|
||
| @Benchmark | ||
| public void quicksort() { | ||
| int[] order = new int[size]; | ||
| for (int i = 0; i < size; i++) { | ||
| order[i] = i; | ||
| } | ||
| Sort.sort(order, values, null, values.length); | ||
| } | ||
| } |
131 changes: 131 additions & 0 deletions
131
benchmarks/src/main/java/org/elasticsearch/benchmark/tdigest/TDigestBench.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,131 @@ | ||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. 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. | ||
| * | ||
| * This project is based on a modification of https://github.com/tdunning/t-digest which is licensed under the Apache 2.0 License. | ||
| */ | ||
|
|
||
| package org.elasticsearch.benchmark.tdigest; | ||
|
|
||
| import org.elasticsearch.tdigest.AVLTreeDigest; | ||
| import org.elasticsearch.tdigest.MergingDigest; | ||
| import org.elasticsearch.tdigest.TDigest; | ||
| 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.Threads; | ||
| import org.openjdk.jmh.annotations.Warmup; | ||
| import org.openjdk.jmh.profile.GCProfiler; | ||
| import org.openjdk.jmh.profile.StackProfiler; | ||
| import org.openjdk.jmh.runner.Runner; | ||
| import org.openjdk.jmh.runner.RunnerException; | ||
| import org.openjdk.jmh.runner.options.Options; | ||
| import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
|
|
||
| import java.util.Random; | ||
| import java.util.concurrent.ThreadLocalRandom; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.function.Supplier; | ||
|
|
||
| @BenchmarkMode(Mode.AverageTime) | ||
| @OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
| @Warmup(iterations = 3, time = 3, timeUnit = TimeUnit.SECONDS) | ||
| @Measurement(iterations = 5, time = 2, timeUnit = TimeUnit.SECONDS) | ||
| @Fork(1) | ||
| @Threads(1) | ||
| @State(Scope.Thread) | ||
| public class TDigestBench { | ||
|
|
||
| public enum TDigestFactory { | ||
| MERGE { | ||
| @Override | ||
| TDigest create(double compression) { | ||
| return new MergingDigest(compression, (int) (10 * compression)); | ||
| } | ||
| }, | ||
| AVL_TREE { | ||
| @Override | ||
| TDigest create(double compression) { | ||
| return new AVLTreeDigest(compression); | ||
| } | ||
| }; | ||
|
|
||
| abstract TDigest create(double compression); | ||
| } | ||
|
|
||
| @Param({ "100", "300" }) | ||
| double compression; | ||
|
|
||
| @Param({ "MERGE", "AVL_TREE" }) | ||
| TDigestFactory tdigestFactory; | ||
|
|
||
| @Param({ "NORMAL", "GAUSSIAN" }) | ||
| String distribution; | ||
|
|
||
| Random random; | ||
| TDigest tdigest; | ||
|
|
||
| double[] data = new double[1000000]; | ||
|
|
||
| @Setup | ||
| public void setUp() { | ||
| random = ThreadLocalRandom.current(); | ||
| tdigest = tdigestFactory.create(compression); | ||
|
|
||
| Supplier<Double> nextRandom = () -> distribution.equals("GAUSSIAN") ? random.nextGaussian() : random.nextDouble(); | ||
| for (int i = 0; i < 10000; ++i) { | ||
| tdigest.add(nextRandom.get()); | ||
| } | ||
|
|
||
| for (int i = 0; i < data.length; ++i) { | ||
| data[i] = nextRandom.get(); | ||
| } | ||
| } | ||
|
|
||
| @State(Scope.Thread) | ||
| public static class ThreadState { | ||
| int index = 0; | ||
| } | ||
|
|
||
| @Benchmark | ||
| @BenchmarkMode(Mode.AverageTime) | ||
| @OutputTimeUnit(TimeUnit.MICROSECONDS) | ||
| public void add(ThreadState state) { | ||
| if (state.index >= data.length) { | ||
| state.index = 0; | ||
| } | ||
| tdigest.add(data[state.index++]); | ||
| } | ||
|
|
||
| public static void main(String[] args) throws RunnerException { | ||
| Options opt = new OptionsBuilder().include(".*" + TDigestBench.class.getSimpleName() + ".*") | ||
| .warmupIterations(5) | ||
| .measurementIterations(5) | ||
| .addProfiler(GCProfiler.class) | ||
| .addProfiler(StackProfiler.class) | ||
| .build(); | ||
|
|
||
| new Runner(opt).run(); | ||
| } | ||
| } |
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
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
2 changes: 1 addition & 1 deletion
2
server/licenses/t-digest-LICENSE.txt → libs/tdigest/LICENSE.txt
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| Apache License | ||
| Apache License | ||
| Version 2.0, January 2004 | ||
| http://www.apache.org/licenses/ | ||
|
|
||
|
|
||
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,28 @@ | ||
| Elastic-t-digest | ||
|
|
||
| Copyright 2023 Elasticsearch B.V. | ||
|
|
||
| -- | ||
| This project is based on a modification of https://github.com/tdunning/t-digest which is licensed under the Apache 2.0 License. | ||
|
|
||
| Licensed to Elasticsearch B.V. under one or more contributor | ||
| license agreements. See the NOTICE file distributed with | ||
| this work for additional information regarding copyright | ||
| ownership. Elasticsearch B.V. 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. | ||
|
|
||
| -- | ||
| The code for the t-digest was originally authored by Ted Dunning | ||
|
|
||
| Adrien Grand contributed the heart of the AVLTreeDigest (https://github.com/jpountz) |
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,41 @@ | ||
| import org.elasticsearch.gradle.internal.conventions.precommit.LicenseHeadersTask | ||
|
|
||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. 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. | ||
| */ | ||
| apply plugin: 'elasticsearch.build' | ||
| apply plugin: 'elasticsearch.publish' | ||
|
|
||
| dependencies { | ||
| testImplementation(project(":test:framework")) { | ||
| exclude group: 'org.elasticsearch', module: 'elasticsearch-tdigest' | ||
| } | ||
| testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1' | ||
| } | ||
|
|
||
| tasks.named('forbiddenApisMain').configure { | ||
| // t-digest does not depend on core, so only jdk signatures should be checked | ||
| replaceSignatureFiles 'jdk-signatures' | ||
| } | ||
|
|
||
| ext.projectLicenses.set(['The Apache Software License, Version 2.0': 'http://www.apache.org/licenses/LICENSE-2.0']) | ||
| licenseFile.set(rootProject.file('licenses/APACHE-LICENSE-2.0.txt')) | ||
|
|
||
| tasks.withType(LicenseHeadersTask.class).configureEach { | ||
| approvedLicenses = ['Apache', 'Generated', 'Vendored'] | ||
| } | ||
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,22 @@ | ||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. 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. | ||
| */ | ||
|
|
||
| module org.elasticsearch.tdigest { | ||
| exports org.elasticsearch.tdigest; | ||
| } |
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.
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.
Keep in mind that once this is merged, we'll also need to open a pull request to the release manager to ensure this new artifact is published as part of our release process.
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.
Thanks, is there documentation or some example about what the PR should contain?
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.
Here's an example PR: https://github.com/elastic/infra/pull/38270/files