Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic jmh overhead test #3672

Merged
merged 8 commits into from
Jul 26, 2021
Merged

Add basic jmh overhead test #3672

merged 8 commits into from
Jul 26, 2021

Conversation

trask
Copy link
Member

@trask trask commented Jul 25, 2021

I did a bit of profiling, and planning to submit a couple of (micro) optimizations, so want to first submit the test I'm using for profiling/measurement.

Benchmark                                                               Score      Error   Units
ServletBenchmark.execute                                              139.343 ±    0.138   us/op
ServletBenchmark.execute:execute·p0.50                                125.696              us/op
ServletBenchmark.execute:·gc.alloc.rate.norm                        29111.284 ± 7057.135    B/op
ServletWithAgentDisabledBenchmark.execute                             119.724 ±    0.112   us/op
ServletWithAgentDisabledBenchmark.execute:execute·p0.50               110.464              us/op
ServletWithAgentDisabledBenchmark.execute:·gc.alloc.rate.norm       25580.861 ± 5803.009    B/op
ServletWithOnePercentSamplingBenchmark.execute                        138.331 ±    0.135   us/op
ServletWithOnePercentSamplingBenchmark.execute:execute·p0.50          124.928              us/op
ServletWithOnePercentSamplingBenchmark.execute:·gc.alloc.rate.norm  28508.222 ± 6843.209    B/op

id("me.champeau.jmh")
id("io.morethan.jmhreport")
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file is identical copy from opentelemetry-java repo

Comment on lines 51 to 52
// TODO(trask) is this ok? if it's ok, move to otel.jmh-conventions?
outputs.upToDateWhen { false }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gradle experts: is this ok? each time I run jmh task I actually want it to run. using --rerun-tasks takes a long time because it doesn't only rerun this one task

Comment on lines 29 to 37
val copyAgent by registering(Copy::class) {
into(file("$buildDir/agent"))
from(configurations.named("agentJar"))
rename { file: String ->
file.replace("-$version", "")
}

dependsOn(":javaagent:shadowJar")
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gradle experts: let me know if there is a more preferred way to get the opentelemetry-javaagent-all into a location that the jmh benchmark can depend on

@trask trask marked this pull request as ready for review July 26, 2021 02:51
profilers.add("gc")
val jmhIncludeSingleClass: String? by project
if (jmhIncludeSingleClass != null) {
includes.add(jmhIncludeSingleClass as String)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious: why this as String is needed? It is already clear that this is not null.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, the by syntax seems to result in something "dynamic". Seems like it might be a Gradle bug, but it makes kotlin not treat the null check as a type cast.

testing-overhead-jmh/build.gradle.kts Outdated Show resolved Hide resolved
profilers.add("gc")
val jmhIncludeSingleClass: String? by project
if (jmhIncludeSingleClass != null) {
includes.add(jmhIncludeSingleClass as String)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, the by syntax seems to result in something "dynamic". Seems like it might be a Gradle bug, but it makes kotlin not treat the null check as a type cast.

testing-overhead-jmh/build.gradle.kts Outdated Show resolved Hide resolved

import org.openjdk.jmh.annotations.Fork;

@Fork(jvmArgsAppend = "-Dotel.javaagent.enabled=false")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an idea: we could also run a benchmark with -Dotel.javaagent.experimental.use-noop-api=true to see how much overhead is added when no SDK at all is used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added 👍

public class ServletBenchmark {

static {
HelloWorldApplication.main();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering: why do we initialize the app in static {} and not @Setup?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added comment to explain

    // using static initializer instead of @Setup since only want to initialize the app under test
    // once regardless of @State and @Threads

@mateuszrzeszutek
Copy link
Member

Just thought about it now, but should we name the dir/module benchmark-overhead-jmh? Usually our testing... modules contain code that tests for correctness, we could keep everything that tests for performance in benchmark... modules.

@trask
Copy link
Member Author

trask commented Jul 26, 2021

Just thought about it now, but should we name the dir/module benchmark-overhead-jmh? Usually our testing... modules contain code that tests for correctness, we could keep everything that tests for performance in benchmark... modules.

ya, I like this, updated

@trask
Copy link
Member Author

trask commented Jul 26, 2021

here's a re-run, including the no-op api test:

Benchmark                                                               Score      Error   Units
ServletBenchmark.execute                                              138.941 ±    0.137   us/op
ServletBenchmark.execute:execute·p0.50                                125.824              us/op
ServletBenchmark.execute:·gc.alloc.rate.norm                        29090.156 ± 7065.042    B/op
ServletWithAgentDisabledBenchmark.execute                             122.255 ±    0.107   us/op
ServletWithAgentDisabledBenchmark.execute:execute·p0.50               112.768              us/op
ServletWithAgentDisabledBenchmark.execute:·gc.alloc.rate.norm       25585.117 ± 5811.971    B/op
ServletWithNoopApiBenchmark.execute                                   134.359 ±    0.127   us/op
ServletWithNoopApiBenchmark.execute:execute·p0.50                     121.344              us/op
ServletWithNoopApiBenchmark.execute:·gc.alloc.rate.norm             27834.075 ± 6578.200    B/op
ServletWithOnePercentSamplingBenchmark.execute                        136.299 ±    0.130   us/op
ServletWithOnePercentSamplingBenchmark.execute:execute·p0.50          123.264              us/op
ServletWithOnePercentSamplingBenchmark.execute:·gc.alloc.rate.norm  28484.639 ± 6846.715    B/op

@trask trask merged commit 59e4647 into open-telemetry:main Jul 26, 2021
@trask trask deleted the overhead-testing-jmh branch July 26, 2021 19:55
@trask trask mentioned this pull request Jul 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants