-
Notifications
You must be signed in to change notification settings - Fork 860
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
Jetty-based benchmark for memory usage #329
Merged
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
19fc7a6
Jetty-based benchmark for memory usage
pmm-sumo cb9ffd6
Fix formatting
pmm-sumo 623be2a
Fix headers
pmm-sumo 561e44e
Remove unnecessary code
pmm-sumo 1312abc
Remove unnecessary code
pmm-sumo 83e023a
Remove unnecessary code
pmm-sumo 2fb6811
Formatting and code cleanup
pmm-sumo 6344a6b
Formatting fix
pmm-sumo fae9094
Merge branch 'master' into memory-churn-benchmark
trask File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
68 changes: 68 additions & 0 deletions
68
benchmark/src/jmh/java/io/opentelemetry/benchmark/HttpBenchmark.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,68 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.opentelemetry.benchmark; | ||
|
||
import io.opentelemetry.benchmark.classes.HttpClass; | ||
import org.eclipse.jetty.server.Server; | ||
import org.eclipse.jetty.util.component.AbstractLifeCycle; | ||
import org.openjdk.jmh.annotations.*; | ||
|
||
public class HttpBenchmark { | ||
|
||
@State(Scope.Benchmark) | ||
public static class BenchmarkState { | ||
@Setup(Level.Trial) | ||
public void doSetup() { | ||
try { | ||
jettyServer = new HttpClass().buildJettyServer(); | ||
jettyServer.start(); | ||
// Make sure it's actually running | ||
while (!AbstractLifeCycle.STARTED.equals(jettyServer.getState())) { | ||
Thread.sleep(500); | ||
} | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@TearDown(Level.Trial) | ||
public void doTearDown() { | ||
try { | ||
jettyServer.stop(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} finally { | ||
jettyServer.destroy(); | ||
} | ||
} | ||
|
||
HttpClass http = new HttpClass(); | ||
Server jettyServer; | ||
} | ||
|
||
@Benchmark | ||
public void testMakingRequest(BenchmarkState state) { | ||
state.http.executeRequest(); | ||
} | ||
|
||
@Fork( | ||
jvmArgsAppend = { | ||
"-javaagent:/path/to/opentelemetry-auto-instr-java/java-agent/build/libs/opentelemetry-auto.jar", | ||
"-javaagent:/path/to/opentelemetry-auto-instr-java/java-agent/build/libs/opentelemetry-auto.jar", | ||
pmm-sumo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"-Dota.exporter.jar=/path/to/opentelemetry-auto-instr-java/auto-exporters/logging/build/libs/opentelemetry-auto-exporters-logging-or-other-exporter.jar" | ||
}) | ||
public static class WithAgent extends ClassRetransformingBenchmark {} | ||
} |
67 changes: 67 additions & 0 deletions
67
benchmark/src/jmh/java/io/opentelemetry/benchmark/UsedMemoryProfiler.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,67 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.opentelemetry.benchmark; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import org.openjdk.jmh.*; | ||
pmm-sumo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import org.openjdk.jmh.annotations.*; | ||
import org.openjdk.jmh.infra.*; | ||
import org.openjdk.jmh.profile.*; | ||
import org.openjdk.jmh.results.*; | ||
|
||
public class UsedMemoryProfiler implements InternalProfiler { | ||
private long totalHeapBefore; | ||
private long usedHeapBefore; | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Used memory heap profiler"; | ||
} | ||
|
||
@Override | ||
public void beforeIteration(BenchmarkParams benchmarkParams, IterationParams iterationParams) { | ||
System.gc(); | ||
System.runFinalization(); | ||
|
||
totalHeapBefore = Runtime.getRuntime().totalMemory(); | ||
usedHeapBefore = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); | ||
} | ||
|
||
@Override | ||
public Collection<? extends Result> afterIteration( | ||
BenchmarkParams benchmarkParams, IterationParams iterationParams, IterationResult result) { | ||
|
||
long totalHeap = Runtime.getRuntime().totalMemory(); | ||
long usedHeap = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); | ||
|
||
Collection<ScalarResult> results = new ArrayList<>(); | ||
results.add( | ||
new ScalarResult("·heap.total.before", totalHeapBefore, "bytes", AggregationPolicy.AVG)); | ||
pmm-sumo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
results.add( | ||
new ScalarResult("·heap.used.before", usedHeapBefore, "bytes", AggregationPolicy.AVG)); | ||
results.add(new ScalarResult("·heap.total.after", totalHeap, "bytes", AggregationPolicy.AVG)); | ||
results.add(new ScalarResult("·heap.used.after", usedHeap, "bytes", AggregationPolicy.AVG)); | ||
results.add( | ||
new ScalarResult( | ||
"·heap.total.change", totalHeap - totalHeapBefore, "bytes", AggregationPolicy.AVG)); | ||
results.add( | ||
new ScalarResult( | ||
"·heap.used.change", usedHeap - usedHeapBefore, "bytes", AggregationPolicy.AVG)); | ||
|
||
return results; | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
benchmark/src/jmh/java/io/opentelemetry/benchmark/classes/HttpClass.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,88 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.opentelemetry.benchmark.classes; | ||
|
||
import com.google.api.client.http.GenericUrl; | ||
import com.google.api.client.http.HttpRequest; | ||
import com.google.api.client.http.HttpRequestFactory; | ||
import com.google.api.client.http.javanet.NetHttpTransport; | ||
import java.io.IOException; | ||
import java.net.InetSocketAddress; | ||
import javax.servlet.ServletConfig; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import org.eclipse.jetty.server.Server; | ||
import org.eclipse.jetty.servlet.ServletContextHandler; | ||
|
||
public class HttpClass { | ||
private String contextPath = "/path"; | ||
private Integer port = 18888; | ||
|
||
public Server buildJettyServer() { | ||
System.setProperty("org.eclipse.jetty.util.log.class", "org.eclipse.jetty.util.log.StdErrLog"); | ||
System.setProperty("org.eclipse.jetty.LEVEL", "WARN"); | ||
|
||
Server jettyServer = new Server(new InetSocketAddress("localhost", port)); | ||
ServletContextHandler servletContext = new ServletContextHandler(); | ||
|
||
servletContext.addServlet(HttpClassServlet.class, contextPath); | ||
jettyServer.setHandler(servletContext); | ||
return jettyServer; | ||
} | ||
|
||
@WebServlet | ||
public static class HttpClassServlet extends HttpServlet { | ||
@Override | ||
public void init(final ServletConfig config) throws ServletException { | ||
super.init(config); | ||
} | ||
|
||
pmm-sumo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@Override | ||
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) | ||
throws ServletException, IOException { | ||
try { | ||
Thread.sleep(10); | ||
} catch (Exception e) { | ||
} | ||
resp.setContentType("application/json"); | ||
resp.setStatus(HttpServletResponse.SC_OK); | ||
resp.getWriter().println("{ \"status\": \"ok\"}"); | ||
} | ||
|
||
@Override | ||
protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) | ||
throws ServletException, IOException { | ||
doGet(req, resp); | ||
} | ||
pmm-sumo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
private HttpRequestFactory requestFactory = new NetHttpTransport().createRequestFactory(); | ||
|
||
public void executeRequest() { | ||
String url = "http://localhost:" + port + contextPath; | ||
|
||
try { | ||
HttpRequest request = requestFactory.buildGetRequest(new GenericUrl(url)); | ||
request.setThrowExceptionOnExecuteError(false); | ||
request.execute(); | ||
} catch (Exception ex) { | ||
ex.printStackTrace(); | ||
pmm-sumo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is cool, I hadn't seen custom profiler before.