Improve benchmark-overhead-jmh consistency (#3680)
* Improve benchmark-overhead-jmh consistency * HttpURLConnection
This commit is contained in:
parent
ed9e1a0cb3
commit
d46d73d4b3
|
@ -9,13 +9,8 @@ plugins {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
jmhImplementation("org.springframework.boot:spring-boot-starter-web:2.5.2")
|
jmhImplementation("org.springframework.boot:spring-boot-starter-web:2.5.2")
|
||||||
jmhImplementation(project(":testing-common")) {
|
|
||||||
exclude("ch.qos.logback")
|
|
||||||
}
|
|
||||||
|
|
||||||
// this only exists to make Intellij happy since it doesn't (currently at least) understand our
|
testImplementation("org.assertj:assertj-core")
|
||||||
// inclusion of this artifact inside of :testing-common
|
|
||||||
jmhCompileOnly(project(path = ":testing:armeria-shaded-for-testing", configuration = "shadow"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
|
@ -42,7 +37,10 @@ tasks {
|
||||||
val args = listOf(
|
val args = listOf(
|
||||||
"-javaagent:${shadowTask.archiveFile.get()}",
|
"-javaagent:${shadowTask.archiveFile.get()}",
|
||||||
"-Dotel.traces.exporter=none",
|
"-Dotel.traces.exporter=none",
|
||||||
"-Dotel.metrics.exporter=none"
|
"-Dotel.metrics.exporter=none",
|
||||||
|
// avoid instrumenting HttpURLConnection for now since it is used to make the requests
|
||||||
|
// and this benchmark is focused on servlet overhead for now
|
||||||
|
"-Dotel.instrumentation.http-url-connection.enabled=false"
|
||||||
)
|
)
|
||||||
// see https://github.com/melix/jmh-gradle-plugin/issues/200
|
// see https://github.com/melix/jmh-gradle-plugin/issues/200
|
||||||
jvmArgsPrepend.add(args.joinToString(" "))
|
jvmArgsPrepend.add(args.joinToString(" "))
|
||||||
|
|
|
@ -6,7 +6,10 @@
|
||||||
package io.opentelemetry.javaagent.benchmark.servlet;
|
package io.opentelemetry.javaagent.benchmark.servlet;
|
||||||
|
|
||||||
import io.opentelemetry.javaagent.benchmark.servlet.app.HelloWorldApplication;
|
import io.opentelemetry.javaagent.benchmark.servlet.app.HelloWorldApplication;
|
||||||
import io.opentelemetry.testing.internal.armeria.client.WebClient;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import org.openjdk.jmh.annotations.Benchmark;
|
import org.openjdk.jmh.annotations.Benchmark;
|
||||||
import org.openjdk.jmh.annotations.BenchmarkMode;
|
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||||
|
@ -28,12 +31,13 @@ public class ServletBenchmark {
|
||||||
HelloWorldApplication.main();
|
HelloWorldApplication.main();
|
||||||
}
|
}
|
||||||
|
|
||||||
// using shaded armeria http client from testing-common artifact since it won't be instrumented
|
private URL client;
|
||||||
private WebClient client;
|
private byte[] buffer;
|
||||||
|
|
||||||
@Setup
|
@Setup
|
||||||
public void setup() {
|
public void setup() throws IOException {
|
||||||
client = WebClient.builder().build();
|
client = new URL("http://localhost:8080");
|
||||||
|
buffer = new byte[8192];
|
||||||
}
|
}
|
||||||
|
|
||||||
@TearDown
|
@TearDown
|
||||||
|
@ -42,7 +46,16 @@ public class ServletBenchmark {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
public Object execute() {
|
public void execute() throws IOException {
|
||||||
return client.get("http://localhost:8080").aggregate().join();
|
HttpURLConnection connection = (HttpURLConnection) client.openConnection();
|
||||||
|
InputStream inputStream = connection.getInputStream();
|
||||||
|
drain(inputStream);
|
||||||
|
inputStream.close();
|
||||||
|
connection.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("StatementWithEmptyBody")
|
||||||
|
private void drain(InputStream inputStream) throws IOException {
|
||||||
|
while (inputStream.read(buffer) != -1) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
# infinite keep alive helps a little with benchmark variance
|
||||||
|
server.tomcat.keep-alive-timeout=-1
|
||||||
|
server.tomcat.max-keep-alive-requests=-1
|
Loading…
Reference in New Issue