This repository has been archived by the owner on Oct 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
242 additions
and
0 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
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
116 changes: 116 additions & 0 deletions
116
src/main/java/com/cloudant/fdblucene/benchmark/GroupSearchBenchmark.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,116 @@ | ||
package com.cloudant.fdblucene.benchmark; | ||
|
||
import java.util.Collection; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.apache.lucene.index.Term; | ||
import org.apache.lucene.search.CachingCollector; | ||
import org.apache.lucene.search.TermQuery; | ||
import org.apache.lucene.search.Sort; | ||
import org.apache.lucene.search.SortField; | ||
import org.apache.lucene.search.SortField.Type; | ||
|
||
import org.apache.lucene.search.grouping.FirstPassGroupingCollector; | ||
import org.apache.lucene.search.grouping.TermGroupSelector; | ||
import org.openjdk.jmh.annotations.*; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
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 org.openjdk.jmh.annotations.Scope; | ||
|
||
public class GroupSearchBenchmark { | ||
|
||
@State(Scope.Benchmark) | ||
public static class FDBGroupSearchBenchmark { | ||
|
||
private FDBSearchSetup fdbSetup; | ||
|
||
@BenchmarkMode(Mode.Throughput) | ||
@Fork(1) | ||
@Warmup(iterations = 3, time = 10, timeUnit = TimeUnit.SECONDS) | ||
@Measurement(iterations = 3, time = 10, timeUnit = TimeUnit.MINUTES) | ||
@Timeout(time = 5, timeUnit = TimeUnit.MINUTES) | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
@Benchmark | ||
@Group("searchFDBByGroup") | ||
@GroupThreads(1) | ||
public void searchFDBByGroup(Blackhole blackhole) throws Exception { | ||
int randomSearchPosition = fdbSetup.random.nextInt(fdbSetup.searchTermList.size()); | ||
String term = fdbSetup.searchTermList.get(randomSearchPosition); | ||
Sort groupSort = new Sort(SortField.FIELD_SCORE, | ||
new SortField("_id", Type.STRING)); | ||
FirstPassGroupingCollector c1 = new FirstPassGroupingCollector( | ||
new TermGroupSelector("group100"), groupSort, fdbSetup.topNDocs); | ||
boolean cacheScores = true; | ||
double maxCacheRAMMB = 4.0; | ||
CachingCollector cachedCollector = CachingCollector.create(c1, cacheScores, maxCacheRAMMB); | ||
fdbSetup.searcher.search(new TermQuery(new Term("body", term)), cachedCollector); | ||
Collection topGroups = c1.getTopGroups(0); | ||
if (topGroups == null) { | ||
// No groups matched | ||
return; | ||
} | ||
blackhole.consume(topGroups.size()); | ||
} | ||
|
||
@Setup(Level.Trial) | ||
public void setup() throws Exception { | ||
fdbSetup = new FDBSearchSetup(); | ||
fdbSetup.setSearchType(BenchmarkUtil.SearchTypeEnum.ByGroup); | ||
fdbSetup.startFDBNetworking(); | ||
fdbSetup.createReader(); | ||
} | ||
} | ||
|
||
@State(Scope.Benchmark) | ||
public static class NioGroupSearchBenchmark { | ||
|
||
private NIOSSearchSetup nioSetup; | ||
|
||
@BenchmarkMode(Mode.Throughput) | ||
@Fork(1) | ||
@Warmup(iterations = 3, time = 10, timeUnit = TimeUnit.SECONDS) | ||
@Measurement(iterations = 3, time = 10, timeUnit = TimeUnit.MINUTES) | ||
@Timeout(time = 5, timeUnit = TimeUnit.MINUTES) | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
@Benchmark | ||
@Group("searchNIOSByGroup") | ||
@GroupThreads(1) | ||
public void searchNIOSByGroup(Blackhole blackhole) throws Exception { | ||
int randomSearchPosition = nioSetup.random.nextInt(nioSetup.searchTermList.size()); | ||
String term = nioSetup.searchTermList.get(randomSearchPosition); | ||
Sort groupSort = new Sort(SortField.FIELD_SCORE, | ||
new SortField("_id", Type.STRING)); | ||
FirstPassGroupingCollector c1 = new FirstPassGroupingCollector( | ||
new TermGroupSelector("group100"), groupSort, nioSetup.topNDocs); | ||
boolean cacheScores = true; | ||
double maxCacheRAMMB = 4.0; | ||
CachingCollector cachedCollector = CachingCollector.create(c1, cacheScores, maxCacheRAMMB); | ||
nioSetup.searcher.search(new TermQuery(new Term("body", term)), cachedCollector); | ||
Collection topGroups = c1.getTopGroups(0); | ||
if (topGroups == null) { | ||
blackhole.consume(topGroups); | ||
return; | ||
} | ||
blackhole.consume(topGroups.size()); | ||
} | ||
|
||
@Setup(Level.Trial) | ||
public void setup() throws Exception { | ||
nioSetup = new NIOSSearchSetup(); | ||
nioSetup.setSearchType(BenchmarkUtil.SearchTypeEnum.ByGroup); | ||
nioSetup.setupNIOS(); | ||
nioSetup.createReader(); | ||
} | ||
} | ||
|
||
public static void main(final String[] args) throws RunnerException { | ||
final Options opt = new OptionsBuilder().include(GroupSearchBenchmark.class.getSimpleName()).build(); | ||
new Runner(opt).run(); | ||
} | ||
|
||
} | ||
|
||
|
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