JSON Serialization Performance #2541
Labels
help wanted
Good for taking. Extra help will be provided by maintainers
Stale
triage/accepted
Indicates an issue or PR is ready to be actively worked on.
I have been exploring the use of different json libraries to optimize the performance of my custom pipeline and exporter to write traces and logs to files. My primary concern was serialization speed, which the OtlpHttpExporter was struggling with while logging extensively. While the
nlohmann::json
library is intuitive and easy to use, it's not very fast for serializing. This is particularly evident when writing a lot of logs. The switch to therapidjson
library brought a significant 40-50% performance improvement to my logging system.In order to benchmark the serialization impact, I modified the
OtlpHttpClient
to immediately returnExportResult::kSuccess
after converting the proto message to json and dumping it to a string. I then modifiedexample_otlp_http
with the following:Result for
nlohmann::json
implementation: 127145 millisecondsResult for
rapidjson
implementation : 82763 millisecondsThe code is available at: https://github.com/perhapsmaple/opentelemetry-cpp/tree/json-benchmark
Not final - I think some more changes could be made to make it a little bit more efficient
I think this is an easy avenue for improvement, and we should consider benchmarking more thoroughly with both libraries. Happy to hear your thoughts and feedback.
The text was updated successfully, but these errors were encountered: