Skip to content

Conversation

@felixbarny
Copy link
Member

@felixbarny felixbarny commented Apr 23, 2018

Benchmarking shows that serializing payloads with dsl-json is x2.4 faster and requires -86% less allocations.

DSL-JSON is a nice library which focuses on fast and garbage free JSON serialization. It only has a small byte[] buffer, which is reused and otherwise directly writes into a OutputStream, so there are no temporary objects created. It also has a mode where it can automatically serialize annotated POJOs. I opted for a more manual approach to have more control about the resulting JSON (see hasContent() checks and explicitly serializing TransactionId with UUIDConverter.serialize(id.getMostSignificantBits(), id.getLeastSignificantBits(), jw);)

My recent additions to dsl-json ngs-doo/dsl-json#48 and ngs-doo/dsl-json#49 make it possible to also serialize StringBuilders and transaction ids in the UUID format in a garbage free way. The only thing which requires allocations now is creating a ISO date formatted string for the Transaction.timestamp and creating Map.entrySet().iterator()s for iterating over custom Context.tags. I'm not quite sure why JIT can't replace the iterator heap allocations with stack allocations, but maybe JMH's GC profiler also reports stack allocations in gc.alloc.rate.norm. Regarding the timestamp serialization, there is an open issue about adding support for epoch timestamps: elastic/apm-server#850. That would make the JSON serialization essentially completely garbage free.

As an additional benefit, the total size of the agent jar drops from 2.8 to 1.2 mb as the replaced Jackson library is much heavier.

This PR is currently blocked until dsl-json 1.7.4 is released.

Log JSON on trace level

Signed-off-by: Felix Barnsteiner <felix.barnsteiner@elastic.co>
(closes elastic#23)

Signed-off-by: Felix Barnsteiner <felix.barnsteiner@elastic.co>
@felixbarny felixbarny closed this Apr 25, 2018
@felixbarny felixbarny reopened this Apr 25, 2018
@zube zube bot closed this Apr 25, 2018
@zube zube bot reopened this Apr 25, 2018
@zube zube bot added [zube]: Inbox and removed [zube]: Done labels Apr 25, 2018
@codecov-io
Copy link

Codecov Report

Merging #69 into master will increase coverage by 1.25%.
The diff coverage is 81.16%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master      #69      +/-   ##
============================================
+ Coverage     75.29%   76.55%   +1.25%     
- Complexity      547      637      +90     
============================================
  Files            71       71              
  Lines          1919     2354     +435     
  Branches        146      187      +41     
============================================
+ Hits           1445     1802     +357     
- Misses          397      448      +51     
- Partials         77      104      +27
Impacted Files Coverage Δ Complexity Δ
...co/elastic/apm/impl/transaction/TransactionId.java 78.78% <ø> (ø) 15 <0> (ø) ⬇️
.../java/co/elastic/apm/impl/error/ExceptionInfo.java 58.82% <ø> (ø) 7 <0> (ø) ⬇️
...ain/java/co/elastic/apm/impl/ElasticApmTracer.java 79.2% <ø> (ø) 33 <0> (ø) ⬇️
...n/java/co/elastic/apm/impl/error/ErrorCapture.java 60.86% <ø> (ø) 8 <0> (ø) ⬇️
...a/co/elastic/apm/impl/transaction/Transaction.java 71.91% <ø> (+1.12%) 26 <0> (-1) ⬇️
...o/elastic/apm/impl/error/TransactionReference.java 71.42% <ø> (ø) 3 <0> (ø) ⬇️
...main/java/co/elastic/apm/impl/payload/Service.java 90.9% <ø> (ø) 14 <0> (ø) ⬇️
...c/apm/impl/stacktrace/StacktraceConfiguration.java 100% <ø> (ø) 4 <0> (ø) ⬇️
...e/src/main/java/co/elastic/apm/impl/error/Log.java 0% <ø> (ø) 0 <0> (ø) ⬇️
...n/java/co/elastic/apm/impl/transaction/SpanId.java 77.77% <ø> (ø) 11 <0> (ø) ⬇️
... and 32 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c8cf440...02d10f6. Read the comment docs.

@felixbarny felixbarny merged commit 4d32c87 into elastic:master Apr 25, 2018
@zube zube bot added [zube]: Done and removed [zube]: Inbox labels Apr 25, 2018
@felixbarny felixbarny deleted the dsl-json branch April 25, 2018 05:58
@alvarolobato alvarolobato added this to the Beta milestone Apr 25, 2018
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.

3 participants