-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: mgodwan <mgodwan@amazon.com>
- Loading branch information
Showing
2 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...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,56 @@ | ||
/* | ||
* 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.openjdk.jmh.annotations.*; | ||
import org.opensearch.common.UUIDs; | ||
import org.opensearch.index.codec.fuzzy.*; | ||
import org.opensearch.index.mapper.IdFieldMapper; | ||
|
||
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(1) | ||
@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()); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...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,81 @@ | ||
/* | ||
* 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.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 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 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(1) | ||
@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 = "id"; | ||
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()))); | ||
} | ||
} | ||
} |