mirror of
https://github.com/elastic/logstash.git
synced 2025-06-28 01:37:28 -04:00
Adds a JMH benchmark to test BufferedTokenizerExt class (#16564)
Adds a JMH benchmark to measure the peformances of BufferedTokenizerExt. Update also Gradle build script to remove CMS GC flags and fix deprecations for Gradle 9.0. Co-authored-by: João Duarte <jsvd@users.noreply.github.com>
This commit is contained in:
parent
85493ce864
commit
b6f16c8b81
2 changed files with 87 additions and 5 deletions
|
@ -50,7 +50,7 @@ jar {
|
|||
}
|
||||
|
||||
ext {
|
||||
jmh = 1.22
|
||||
jmh = 1.37
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
@ -79,17 +79,15 @@ tasks.register("jmh", JavaExec) {
|
|||
|
||||
dependsOn=[':logstash-core-benchmarks:clean', ':logstash-core-benchmarks:shadowJar']
|
||||
|
||||
main = "-jar"
|
||||
mainClass = "-jar"
|
||||
|
||||
def include = project.properties.get('include', '')
|
||||
|
||||
doFirst {
|
||||
args = [
|
||||
"-Djava.io.tmpdir=${buildDir.absolutePath}",
|
||||
"-XX:+UseConcMarkSweepGC", "-XX:CMSInitiatingOccupancyFraction=75",
|
||||
"-XX:+UseCMSInitiatingOccupancyOnly", "-XX:+DisableExplicitGC",
|
||||
"-XX:+HeapDumpOnOutOfMemoryError", "-Xms2g", "-Xmx2g",
|
||||
shadowJar.archivePath,
|
||||
shadowJar.archiveFile.get().asFile,
|
||||
include
|
||||
]
|
||||
}
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
package org.logstash.benchmark;
|
||||
|
||||
import org.jruby.RubyArray;
|
||||
import org.jruby.RubyString;
|
||||
import org.jruby.runtime.ThreadContext;
|
||||
import org.jruby.runtime.builtin.IRubyObject;
|
||||
import org.logstash.RubyUtil;
|
||||
import org.logstash.common.BufferedTokenizerExt;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||
import org.openjdk.jmh.annotations.Fork;
|
||||
import org.openjdk.jmh.annotations.Level;
|
||||
import org.openjdk.jmh.annotations.Measurement;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.annotations.OperationsPerInvocation;
|
||||
import org.openjdk.jmh.annotations.OutputTimeUnit;
|
||||
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.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.logstash.RubyUtil.RUBY;
|
||||
|
||||
@Warmup(iterations = 3, time = 100, timeUnit = TimeUnit.MILLISECONDS)
|
||||
@Measurement(iterations = 10, time = 100, timeUnit = TimeUnit.MILLISECONDS)
|
||||
@Fork(1)
|
||||
@BenchmarkMode(Mode.Throughput)
|
||||
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||
@State(Scope.Thread)
|
||||
public class BufferedTokenizerExtBenchmark {
|
||||
|
||||
private BufferedTokenizerExt sut;
|
||||
private ThreadContext context;
|
||||
private RubyString singleTokenPerFragment;
|
||||
private RubyString multipleTokensPerFragment;
|
||||
private RubyString multipleTokensSpreadMultipleFragments_1;
|
||||
private RubyString multipleTokensSpreadMultipleFragments_2;
|
||||
private RubyString multipleTokensSpreadMultipleFragments_3;
|
||||
|
||||
@Setup(Level.Invocation)
|
||||
public void setUp() {
|
||||
sut = new BufferedTokenizerExt(RubyUtil.RUBY, RubyUtil.BUFFERED_TOKENIZER);
|
||||
context = RUBY.getCurrentContext();
|
||||
IRubyObject[] args = {};
|
||||
sut.init(context, args);
|
||||
singleTokenPerFragment = RubyUtil.RUBY.newString("a".repeat(512) + "\n");
|
||||
|
||||
multipleTokensPerFragment = RubyUtil.RUBY.newString("a".repeat(512) + "\n" + "b".repeat(512) + "\n" + "c".repeat(512) + "\n");
|
||||
|
||||
multipleTokensSpreadMultipleFragments_1 = RubyUtil.RUBY.newString("a".repeat(512) + "\n" + "b".repeat(512) + "\n" + "c".repeat(256));
|
||||
multipleTokensSpreadMultipleFragments_2 = RubyUtil.RUBY.newString("c".repeat(256) + "\n" + "d".repeat(512) + "\n" + "e".repeat(256));
|
||||
multipleTokensSpreadMultipleFragments_3 = RubyUtil.RUBY.newString("f".repeat(256) + "\n" + "g".repeat(512) + "\n" + "h".repeat(512) + "\n");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Benchmark
|
||||
public final void onlyOneTokenPerFragment(Blackhole blackhole) {
|
||||
RubyArray<RubyString> tokens = (RubyArray<RubyString>) sut.extract(context, singleTokenPerFragment);
|
||||
blackhole.consume(tokens);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Benchmark
|
||||
public final void multipleTokenPerFragment(Blackhole blackhole) {
|
||||
RubyArray<RubyString> tokens = (RubyArray<RubyString>) sut.extract(context, multipleTokensPerFragment);
|
||||
blackhole.consume(tokens);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Benchmark
|
||||
public final void multipleTokensCrossingMultipleFragments(Blackhole blackhole) {
|
||||
RubyArray<RubyString> tokens = (RubyArray<RubyString>) sut.extract(context, multipleTokensSpreadMultipleFragments_1);
|
||||
blackhole.consume(tokens);
|
||||
|
||||
tokens = (RubyArray<RubyString>) sut.extract(context, multipleTokensSpreadMultipleFragments_2);
|
||||
blackhole.consume(tokens);
|
||||
|
||||
tokens = (RubyArray<RubyString>) sut.extract(context, multipleTokensSpreadMultipleFragments_3);
|
||||
blackhole.consume(tokens);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue