-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…12171) * Enable Fuzzy codec for doc id fields using a bloom filter (cherry picked from commit 0a88963) Signed-off-by: mgodwan <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
39fa660
commit 4bf568f
Showing
24 changed files
with
1,538 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
67 changes: 67 additions & 0 deletions
67
...src/main/java/org/opensearch/benchmark/index/codec/fuzzy/FilterConstructionBenchmark.java
This file contains 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,67 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.benchmark.index.codec.fuzzy; | ||
|
||
import org.apache.lucene.util.BytesRef; | ||
import org.opensearch.common.UUIDs; | ||
import org.opensearch.index.codec.fuzzy.FuzzySet; | ||
import org.opensearch.index.codec.fuzzy.FuzzySetFactory; | ||
import org.opensearch.index.codec.fuzzy.FuzzySetParameters; | ||
import org.opensearch.index.mapper.IdFieldMapper; | ||
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 java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
|
||
@Fork(3) | ||
@Warmup(iterations = 2) | ||
@Measurement(iterations = 5, time = 60, timeUnit = TimeUnit.SECONDS) | ||
@BenchmarkMode(Mode.AverageTime) | ||
@OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
@State(Scope.Benchmark) | ||
public class FilterConstructionBenchmark { | ||
|
||
private List<BytesRef> items; | ||
|
||
@Param({ "1000000", "10000000", "50000000" }) | ||
private int numIds; | ||
|
||
@Param({ "0.0511", "0.1023", "0.2047" }) | ||
private double fpp; | ||
|
||
private FuzzySetFactory fuzzySetFactory; | ||
private String fieldName; | ||
|
||
@Setup | ||
public void setupIds() { | ||
this.fieldName = IdFieldMapper.NAME; | ||
this.items = IntStream.range(0, numIds).mapToObj(i -> new BytesRef(UUIDs.base64UUID())).collect(Collectors.toList()); | ||
FuzzySetParameters parameters = new FuzzySetParameters(() -> fpp); | ||
this.fuzzySetFactory = new FuzzySetFactory(Map.of(fieldName, parameters)); | ||
} | ||
|
||
@Benchmark | ||
public FuzzySet buildFilter() throws IOException { | ||
return fuzzySetFactory.createFuzzySet(items.size(), fieldName, () -> items.iterator()); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
...marks/src/main/java/org/opensearch/benchmark/index/codec/fuzzy/FilterLookupBenchmark.java
This file contains 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,80 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.benchmark.index.codec.fuzzy; | ||
|
||
import org.apache.lucene.util.BytesRef; | ||
import org.opensearch.common.UUIDs; | ||
import org.opensearch.index.codec.fuzzy.FuzzySet; | ||
import org.opensearch.index.codec.fuzzy.FuzzySetFactory; | ||
import org.opensearch.index.codec.fuzzy.FuzzySetParameters; | ||
import org.opensearch.index.mapper.IdFieldMapper; | ||
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.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Random; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
|
||
@Fork(3) | ||
@Warmup(iterations = 2) | ||
@Measurement(iterations = 5, time = 60, timeUnit = TimeUnit.SECONDS) | ||
@BenchmarkMode(Mode.AverageTime) | ||
@OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
@State(Scope.Benchmark) | ||
public class FilterLookupBenchmark { | ||
|
||
@Param({ "50000000", "1000000" }) | ||
private int numItems; | ||
|
||
@Param({ "1000000" }) | ||
private int searchKeyCount; | ||
|
||
@Param({ "0.0511", "0.1023", "0.2047" }) | ||
private double fpp; | ||
|
||
private FuzzySet fuzzySet; | ||
private List<BytesRef> items; | ||
private Random random = new Random(); | ||
|
||
@Setup | ||
public void setupFilter() throws IOException { | ||
String fieldName = IdFieldMapper.NAME; | ||
items = IntStream.range(0, numItems).mapToObj(i -> new BytesRef(UUIDs.base64UUID())).collect(Collectors.toList()); | ||
FuzzySetParameters parameters = new FuzzySetParameters(() -> fpp); | ||
fuzzySet = new FuzzySetFactory(Map.of(fieldName, parameters)).createFuzzySet(numItems, fieldName, () -> items.iterator()); | ||
} | ||
|
||
@Benchmark | ||
public void contains_withExistingKeys(Blackhole blackhole) throws IOException { | ||
for (int i = 0; i < searchKeyCount; i++) { | ||
blackhole.consume(fuzzySet.contains(items.get(random.nextInt(items.size()))) == FuzzySet.Result.MAYBE); | ||
} | ||
} | ||
|
||
@Benchmark | ||
public void contains_withRandomKeys(Blackhole blackhole) throws IOException { | ||
for (int i = 0; i < searchKeyCount; i++) { | ||
blackhole.consume(fuzzySet.contains(new BytesRef(UUIDs.base64UUID()))); | ||
} | ||
} | ||
} |
This file contains 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 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 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 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 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
Oops, something went wrong.