Repository navigation
Add self-serve PetClinic macro-benchmark harness (macrobenchmark) #11956
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
Merged
gh-worker-dd-mergequeue-cf854d
merged 31 commits into
master
from
dougqh/petclinic-bench-harness
Nov 13, 2026
+1,334
−75
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
508573e
Add self-serve PetClinic macro-benchmark harness
dougqh 13e2f67
Gate wrk on a real HTTP 200 + abort on socket connect errors
dougqh 11c53ee
Fix ps process lookup to target PID directly in run-perf-test.sh
dougqh 0d6b891
Add repeats support to run-perf-test.sh for less-noisy throughput
dougqh 1a74ef7
Discard the benchmarked server's stdout so error-endpoint stack trace…
dougqh 2a4747b
Download released agents from GitHub releases, falling back to Maven …
dougqh d45a924
Add a Datadog Agent stub for macro benchmarks
dougqh 3e76ca5
Report p99 and young GCs per endpoint, and support upstream headers a…
dougqh 54bc17a
Run PetClinic against the Agent stub with upstream headers by default
dougqh 0534818
Drop agent CPU and RSS columns the harness never measured, and tidy r…
dougqh fa9a364
Find the built PetClinic jar in one place
dougqh 74452e8
Weight JFR allocation samples by their bytes in analyze-jfr.sh
dougqh e26ff36
Fix the shared perf runner for the Jetty and Play apps, JDK 8 and Linux
dougqh 2e622d2
Pick up JAVA_HOME or the java on PATH for PetClinic, and narrow the i…
dougqh eacf000
Attribute JFR samples to the tracer by any datadog frame on the stack…
dougqh c0b250e
Report KB allocated per request per endpoint, from the GC log
dougqh a9d91b3
Run PetClinic sweeps in multiple fresh-JVM passes with rotated varian…
dougqh b116bf9
Own JFR samples by the first non-JDK frame, not any datadog frame on …
dougqh a621a97
Pass Play's JVM options to it intact
dougqh adf2000
Send the Agent state header from the Agent stub
dougqh 9bd7f8b
Stop the PetClinic sweep when an agent jar can't be built or downloaded
dougqh 6874d24
Make the perf runner stop cleanly when a run goes wrong
dougqh 1d0f89f
Keep whole thread names and count the perf-test apps as app in analyz…
dougqh a6d5878
Keep agent jar paths with spaces as one JVM argument
dougqh 6fa5537
Resolve PERF_SETTINGS to an absolute path before the sweep
dougqh 80bdb64
Count JFR events without a stack in analyze-jfr totals
dougqh 78d1efa
Run PetClinic extracted with the resource chain off, so it isn't lock…
dougqh 44aa8b1
Don't run PetClinic's /oups error endpoint by default
dougqh 0dd05fe
Read macOS CPU time correctly and tighten the Agent stub's Javadoc
dougqh 50abb1a
Group PetClinic run medians by a stable variant ID, not by version
dougqh 64543dd
Keep variant IDs from splitting CSV fields
dougqh 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 hidden or 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
138 changes: 138 additions & 0 deletions
138
dd-java-agent/benchmark-integration/agent-stub/AgentStub.java
This file contains hidden or 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,138 @@ | ||
| import com.sun.net.httpserver.HttpExchange; | ||
| import com.sun.net.httpserver.HttpServer; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.io.OutputStream; | ||
| import java.net.InetSocketAddress; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.security.MessageDigest; | ||
| import java.security.NoSuchAlgorithmException; | ||
| import java.util.Map; | ||
| import java.util.TreeMap; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.concurrent.Executors; | ||
| import java.util.concurrent.atomic.AtomicLongArray; | ||
|
|
||
| /** | ||
| * Local Datadog Agent stub for benchmarks. It reads and discards payloads so Agent processing and | ||
| * rejection do not affect the tracer's writer and heap measurements by default. | ||
| * | ||
| * <p>Serves {@code agent-info.json}, captured from Agent 7.80.3, for feature discovery, including | ||
| * client-side stats, unsampled-trace dropping and peer tags. Remote Config is not advertised. Every | ||
| * response includes {@code Datadog-Agent-State}, the SHA-256 of that file, so trace responses match | ||
| * the discovered state and do not trigger repeated discovery. | ||
| * | ||
| * <p>{@code GET /_stats} reports received requests and bytes per endpoint as {@code <path> | ||
| * <requests> <bytes>}. The runner uses this to check that each agent variant delivered traces. | ||
| * | ||
| * <pre>java AgentStub.java [port] [agent-info.json]</pre> | ||
| * | ||
| * <p>Defaults: port 8126 and {@code ./agent-info.json}. {@code STUB_SAMPLE_RATE} sets the {@code | ||
| * rate_by_service} response (default 1). {@code STUB_DELAY_MS} delays trace and stats responses; | ||
| * {@code STUB_ERROR_CODE} sets their response status to simulate a degraded Agent. | ||
| */ | ||
|
dougqh marked this conversation as resolved.
Resolved
|
||
| public class AgentStub { | ||
| private static final Map<String, AtomicLongArray> RECEIVED = new ConcurrentHashMap<>(); | ||
| private static String agentState; | ||
|
|
||
| public static void main(String[] args) throws IOException { | ||
| int port = args.length > 0 ? Integer.parseInt(args[0]) : 8126; | ||
| byte[] info = Files.readAllBytes(Path.of(args.length > 1 ? args[1] : "agent-info.json")); | ||
| agentState = sha256Hex(info); | ||
| double sampleRate = Double.parseDouble(env("STUB_SAMPLE_RATE", "1")); | ||
| long delayMs = Long.parseLong(env("STUB_DELAY_MS", "0")); | ||
| int errorCode = Integer.parseInt(env("STUB_ERROR_CODE", "0")); | ||
| byte[] tracesResponse = | ||
| ("{\"rate_by_service\":{\"service:,env:\":" + sampleRate + "}}") | ||
| .getBytes(StandardCharsets.UTF_8); | ||
|
|
||
| HttpServer server = HttpServer.create(new InetSocketAddress("127.0.0.1", port), 64); | ||
| server.setExecutor(Executors.newFixedThreadPool(8)); | ||
| server.createContext( | ||
| "/", | ||
| exchange -> { | ||
| try (exchange) { | ||
| String path = exchange.getRequestURI().getPath(); | ||
| if ("GET".equals(exchange.getRequestMethod())) { | ||
| if (path.equals("/info")) { | ||
| reply(exchange, 200, info); | ||
| } else if (path.equals("/_stats")) { | ||
| reply(exchange, 200, stats()); | ||
| } else { | ||
| reply(exchange, 404, new byte[0]); | ||
| } | ||
| return; | ||
| } | ||
| long bytes = drain(exchange.getRequestBody()); | ||
| AtomicLongArray counts = RECEIVED.computeIfAbsent(path, p -> new AtomicLongArray(2)); | ||
| counts.incrementAndGet(0); | ||
| counts.addAndGet(1, bytes); | ||
| boolean payload = path.endsWith("/traces") || path.endsWith("/stats"); | ||
| if (payload && delayMs > 0) { | ||
| Thread.sleep(delayMs); | ||
| } | ||
| if (payload && errorCode != 0) { | ||
| reply(exchange, errorCode, "{\"error\":\"stub degraded mode\"}".getBytes()); | ||
| } else if (path.endsWith("/traces")) { | ||
| reply(exchange, 200, tracesResponse); | ||
| } else if (path.startsWith("/telemetry/") || path.startsWith("/evp_proxy/")) { | ||
| reply(exchange, 202, new byte[0]); | ||
| } else { | ||
| reply(exchange, 200, new byte[0]); | ||
| } | ||
| } catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| } | ||
| }); | ||
| server.start(); | ||
| System.out.println("agent stub listening on 127.0.0.1:" + port); | ||
| } | ||
|
|
||
| private static byte[] stats() { | ||
| StringBuilder out = new StringBuilder(); | ||
| new TreeMap<>(RECEIVED) | ||
| .forEach((path, c) -> out.append(path).append(' ').append(c.get(0)).append(' ') | ||
| .append(c.get(1)).append('\n')); | ||
| return out.toString().getBytes(StandardCharsets.UTF_8); | ||
| } | ||
|
|
||
| private static long drain(InputStream body) throws IOException { | ||
| byte[] buffer = new byte[64 * 1024]; | ||
| long total = 0; | ||
| for (int n; (n = body.read(buffer)) > 0; ) { | ||
| total += n; | ||
| } | ||
| return total; | ||
| } | ||
|
|
||
| private static void reply(HttpExchange exchange, int status, byte[] body) throws IOException { | ||
| exchange.getResponseHeaders().set("Content-Type", "application/json"); | ||
| exchange.getResponseHeaders().set("Datadog-Agent-State", agentState); | ||
| exchange.sendResponseHeaders(status, body.length == 0 ? -1 : body.length); | ||
|
dougqh marked this conversation as resolved.
Resolved
|
||
| if (body.length > 0) { | ||
| try (OutputStream out = exchange.getResponseBody()) { | ||
| out.write(body); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** Lowercase hex, matching how the tracer hashes the {@code /info} body. */ | ||
| private static String sha256Hex(byte[] bytes) { | ||
| try { | ||
| StringBuilder hex = new StringBuilder(64); | ||
| for (byte b : MessageDigest.getInstance("SHA-256").digest(bytes)) { | ||
| hex.append(Character.forDigit((b >> 4) & 0xF, 16)).append(Character.forDigit(b & 0xF, 16)); | ||
| } | ||
| return hex.toString(); | ||
| } catch (NoSuchAlgorithmException e) { | ||
| throw new IllegalStateException(e); | ||
| } | ||
| } | ||
|
|
||
| private static String env(String name, String fallback) { | ||
| String value = System.getenv(name); | ||
| return value == null || value.isEmpty() ? fallback : value; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.