Skip to content

Commit 3d9b6f8

Browse files
committed
Replace GzipSink with DeflateOutputStream
- Add Reporter#getReported - Fix benachmarking with JDBC mock (still not enabled by default) - Remove Moshi JSON benchmarks
1 parent acf4949 commit 3d9b6f8

20 files changed

+2050
-338
lines changed

apm-agent-benchmarks/pom.xml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,6 @@
6060
<version>1.4.22.Final</version>
6161
</dependency>
6262

63-
<dependency>
64-
<groupId>com.squareup.moshi</groupId>
65-
<artifactId>moshi</artifactId>
66-
<version>1.5.0</version>
67-
</dependency>
68-
<dependency>
69-
<groupId>com.squareup.moshi</groupId>
70-
<artifactId>moshi-adapters</artifactId>
71-
<version>1.5.0</version>
72-
</dependency>
7363
<dependency>
7464
<groupId>com.fasterxml.jackson.core</groupId>
7565
<artifactId>jackson-databind</artifactId>

apm-agent-benchmarks/src/main/java/co/elastic/apm/benchmark/ElasticApmContinuousBenchmark.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public abstract class ElasticApmContinuousBenchmark extends AbstractBenchmark {
103103
protected HttpServlet httpServlet;
104104
private Undertow server;
105105
private ElasticApmTracer tracer;
106+
private long receivedPayloads = 0;
106107

107108
public ElasticApmContinuousBenchmark(boolean apmEnabled) {
108109
this.apmEnabled = apmEnabled;
@@ -112,7 +113,10 @@ public ElasticApmContinuousBenchmark(boolean apmEnabled) {
112113
public void setUp(Blackhole blackhole) throws SQLException {
113114
server = Undertow.builder()
114115
.addHttpListener(0, "127.0.0.1")
115-
.setHandler(exchange -> exchange.setStatusCode(200).endExchange()).build();
116+
.setHandler(exchange -> {
117+
receivedPayloads++;
118+
exchange.setStatusCode(200).endExchange();
119+
}).build();
116120
server.start();
117121
int port = ((InetSocketAddress) server.getListenerInfo().get(0).getAddress()).getPort();
118122
tracer = new ElasticApmTracerBuilder()
@@ -143,6 +147,9 @@ public void tearDown() {
143147
server.stop();
144148
tracer.stop();
145149
ElasticApmAgent.reset();
150+
System.out.println("Reported: " + tracer.getReporter().getReported());
151+
System.out.println("Dropped: " + tracer.getReporter().getDropped());
152+
System.out.println("receivedPayloads = " + receivedPayloads);
146153
}
147154

148155
private MockHttpServletRequest createRequest() {
@@ -236,7 +243,7 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro
236243
// makes sure the jdbc query and the reporting can't be eliminated by JIT
237244
// setting it as the http status code so that there are no allocations necessary
238245
// for example converting to string
239-
response.setStatus(reporter.getDropped());
246+
response.setStatus((int) reporter.getDropped());
240247
} catch (Exception e) {
241248
throw new ServletException(e);
242249
}

apm-agent-benchmarks/src/main/java/co/elastic/apm/benchmark/reporter/AbstractHttpJacksonReporterBenchmark.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import co.elastic.apm.report.serialize.PayloadSerializer;
2525
import com.fasterxml.jackson.databind.ObjectMapper;
2626
import com.fasterxml.jackson.module.afterburner.AfterburnerModule;
27-
import okio.Buffer;
2827
import org.openjdk.jmh.annotations.Setup;
2928
import org.openjdk.jmh.profile.GCProfiler;
3029
import org.openjdk.jmh.runner.Runner;
@@ -51,9 +50,6 @@ public static void main(String[] args) throws RunnerException {
5150
@Setup
5251
public void setUp() throws Exception {
5352
super.setUp();
54-
Buffer buffer = new Buffer();
55-
getPayloadSerializer().serializePayload(buffer, payload);
56-
System.out.println("Size of payload in bytes: " + buffer.readByteString().toByteArray().length);
5753
}
5854

5955
@Override

apm-agent-benchmarks/src/main/java/co/elastic/apm/benchmark/reporter/AbstractHttpReporterBenchmark.java

Lines changed: 7 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@
2525
import co.elastic.apm.report.serialize.PayloadSerializer;
2626
import io.undertow.Undertow;
2727
import okhttp3.OkHttpClient;
28-
import okio.Buffer;
29-
import okio.BufferedSink;
30-
import okio.ByteString;
31-
import okio.Source;
32-
import okio.Timeout;
3328
import org.openjdk.jmh.annotations.Benchmark;
3429
import org.openjdk.jmh.annotations.Setup;
3530
import org.openjdk.jmh.annotations.TearDown;
@@ -39,18 +34,17 @@
3934
import java.io.IOException;
4035
import java.io.OutputStream;
4136
import java.net.InetSocketAddress;
42-
import java.nio.charset.Charset;
4337

4438
public abstract class AbstractHttpReporterBenchmark extends AbstractReporterBenchmark {
4539
private Undertow server;
4640
private int port;
4741
private PayloadSerializer payloadSerializer;
48-
private NoopBufferedSink noopBufferedSink;
42+
private BlackholeOutputStream blackholeOutputStream;
4943

5044
@Setup
5145
public void setUp(Blackhole blackhole) throws Exception {
5246
super.setUp();
53-
noopBufferedSink = new NoopBufferedSink(blackhole);
47+
blackholeOutputStream = new BlackholeOutputStream(blackhole);
5448
server = Undertow.builder()
5549
.addHttpListener(0, "127.0.0.1")
5650
.setHandler(exchange -> exchange.setStatusCode(200).endExchange()).build();
@@ -80,185 +74,22 @@ public void tearDown() {
8074
@Benchmark
8175
@Threads(1)
8276
public void testSerialization() throws IOException {
83-
payloadSerializer.serializePayload(noopBufferedSink, payload);
77+
payloadSerializer.serializePayload(blackholeOutputStream, payload);
8478
}
8579

86-
@SuppressWarnings("ConstantConditions")
87-
private static class NoopBufferedSink implements BufferedSink {
80+
private static class BlackholeOutputStream extends OutputStream {
8881

8982
private final Blackhole blackhole;
9083

91-
private NoopBufferedSink(Blackhole blackhole) {
84+
private BlackholeOutputStream(Blackhole blackhole) {
9285
this.blackhole = blackhole;
9386
}
9487

9588
@Override
96-
public Buffer buffer() {
97-
return null;
98-
}
99-
100-
@Override
101-
public BufferedSink write(ByteString byteString) throws IOException {
102-
blackhole.consume(byteString);
103-
return this;
104-
}
105-
106-
@Override
107-
public BufferedSink write(byte[] source) throws IOException {
108-
blackhole.consume(source);
109-
return this;
110-
}
111-
112-
@Override
113-
public BufferedSink write(byte[] source, int offset, int byteCount) throws IOException {
114-
blackhole.consume(source);
115-
return this;
116-
}
117-
118-
@Override
119-
public long writeAll(Source source) throws IOException {
120-
blackhole.consume(source);
121-
return 0;
122-
}
123-
124-
@Override
125-
public BufferedSink write(Source source, long byteCount) throws IOException {
126-
blackhole.consume(source);
127-
return this;
128-
}
129-
130-
@Override
131-
public BufferedSink writeUtf8(String string) throws IOException {
132-
blackhole.consume(string);
133-
return this;
134-
}
135-
136-
@Override
137-
public BufferedSink writeUtf8(String string, int beginIndex, int endIndex) throws IOException {
138-
blackhole.consume(string);
139-
return this;
140-
}
141-
142-
@Override
143-
public BufferedSink writeUtf8CodePoint(int codePoint) throws IOException {
144-
blackhole.consume(codePoint);
145-
return this;
146-
}
147-
148-
@Override
149-
public BufferedSink writeString(String string, Charset charset) throws IOException {
150-
blackhole.consume(string);
151-
return this;
152-
}
153-
154-
@Override
155-
public BufferedSink writeString(String string, int beginIndex, int endIndex, Charset charset) throws IOException {
156-
blackhole.consume(string);
157-
return this;
158-
}
159-
160-
@Override
161-
public BufferedSink writeByte(int b) throws IOException {
89+
public void write(int b) {
16290
blackhole.consume(b);
163-
return this;
164-
}
165-
166-
@Override
167-
public BufferedSink writeShort(int s) throws IOException {
168-
blackhole.consume(s);
169-
return this;
170-
}
171-
172-
@Override
173-
public BufferedSink writeShortLe(int s) throws IOException {
174-
blackhole.consume(s);
175-
return this;
176-
}
177-
178-
@Override
179-
public BufferedSink writeInt(int i) throws IOException {
180-
blackhole.consume(i);
181-
return this;
182-
}
183-
184-
@Override
185-
public BufferedSink writeIntLe(int i) throws IOException {
186-
blackhole.consume(i);
187-
return this;
18891
}
18992

190-
@Override
191-
public BufferedSink writeLong(long v) throws IOException {
192-
blackhole.consume(v);
193-
return this;
194-
}
195-
196-
@Override
197-
public BufferedSink writeLongLe(long v) throws IOException {
198-
blackhole.consume(v);
199-
return this;
200-
}
201-
202-
@Override
203-
public BufferedSink writeDecimalLong(long v) throws IOException {
204-
blackhole.consume(v);
205-
return this;
206-
}
207-
208-
@Override
209-
public BufferedSink writeHexadecimalUnsignedLong(long v) throws IOException {
210-
blackhole.consume(v);
211-
return this;
212-
}
213-
214-
@Override
215-
public void flush() throws IOException {
216-
217-
}
218-
219-
@Override
220-
public BufferedSink emit() throws IOException {
221-
return this;
222-
}
223-
224-
@Override
225-
public BufferedSink emitCompleteSegments() throws IOException {
226-
return this;
227-
}
228-
229-
@Override
230-
public OutputStream outputStream() {
231-
return new OutputStream() {
232-
@Override
233-
public void write(int b) throws IOException {
234-
blackhole.consume(b);
235-
}
236-
237-
@Override
238-
public void write(byte[] b) throws IOException {
239-
blackhole.consume(b);
240-
}
241-
242-
@Override
243-
public void write(byte[] b, int off, int len) throws IOException {
244-
blackhole.consume(b);
245-
}
246-
};
247-
}
248-
249-
@Override
250-
public void write(Buffer source, long byteCount) throws IOException {
251-
blackhole.consume(source);
252-
}
253-
254-
@Override
255-
public Timeout timeout() {
256-
return null;
257-
}
258-
259-
@Override
260-
public void close() throws IOException {
261-
262-
}
26393
}
94+
26495
}

apm-agent-benchmarks/src/main/java/co/elastic/apm/benchmark/reporter/HttpMoshiReporterBenchmark.java

Lines changed: 0 additions & 42 deletions
This file was deleted.

apm-agent-benchmarks/src/main/java/co/elastic/apm/benchmark/reporter/HttpNoopJsonReporterBenchmark.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public static void main(String[] args) throws RunnerException {
3636

3737
@Override
3838
protected PayloadSerializer getPayloadSerializer() {
39-
return (sink, payload) -> {
40-
sink.writeByte('{');
41-
sink.writeByte('}');
39+
return (os, payload) -> {
40+
os.write('{');
41+
os.write('}');
4242
};
4343
}
4444
}

apm-agent-benchmarks/src/main/java/co/elastic/apm/benchmark/reporter/NoopReporterBenchmark.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ public static void main(String[] args) throws RunnerException {
4040
}
4141

4242
protected PayloadSender getPayloadSender() {
43-
return Payload::recycle;
43+
return new PayloadSender() {
44+
@Override
45+
public void sendPayload(Payload payload) {
46+
payload.recycle();
47+
}
48+
49+
@Override
50+
public long getReported() {
51+
return 0;
52+
}
53+
54+
@Override
55+
public long getDropped() {
56+
return 0;
57+
}
58+
};
4459
}
4560
}

0 commit comments

Comments
 (0)