Improve benchmark-overhead-jmh consistency (#3680)

* Improve benchmark-overhead-jmh consistency

* HttpURLConnection
This commit is contained in:
Trask Stalnaker 2021-07-27 14:01:10 -07:00 committed by GitHub
parent ed9e1a0cb3
commit d46d73d4b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 14 deletions

View File

@ -9,13 +9,8 @@ plugins {
dependencies {
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
// inclusion of this artifact inside of :testing-common
jmhCompileOnly(project(path = ":testing:armeria-shaded-for-testing", configuration = "shadow"))
testImplementation("org.assertj:assertj-core")
}
tasks {
@ -42,7 +37,10 @@ tasks {
val args = listOf(
"-javaagent:${shadowTask.archiveFile.get()}",
"-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
jvmArgsPrepend.add(args.joinToString(" "))

View File

@ -6,7 +6,10 @@
package io.opentelemetry.javaagent.benchmark.servlet;
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 org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
@ -28,12 +31,13 @@ public class ServletBenchmark {
HelloWorldApplication.main();
}
// using shaded armeria http client from testing-common artifact since it won't be instrumented
private WebClient client;
private URL client;
private byte[] buffer;
@Setup
public void setup() {
client = WebClient.builder().build();
public void setup() throws IOException {
client = new URL("http://localhost:8080");
buffer = new byte[8192];
}
@TearDown
@ -42,7 +46,16 @@ public class ServletBenchmark {
}
@Benchmark
public Object execute() {
return client.get("http://localhost:8080").aggregate().join();
public void execute() throws IOException {
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) {}
}
}

View File

@ -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