Skip to content

Commit

Permalink
Adding some initial benchmarks for deserializing traces from msgpack
Browse files Browse the repository at this point in the history
Deserializing msgpack bytes into an internal representation is currently
inefficient. Before work starts on fixing the performance issues we want
to set some baseline benchmarks.
  • Loading branch information
ekump committed Jul 15, 2024
1 parent b54fa8b commit bbc9f26
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions trace-utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[package]
name = "datadog-trace-utils"
authors = ["David Lee <david.lee@datadoghq.com>"]
edition.workspace = true
version.workspace = true
rust-version.workspace = true
Expand All @@ -9,6 +8,10 @@ license.workspace = true
[lib]
bench = false

[[bench]]
name = "main"
harness = false

[dependencies]
anyhow = "1.0"
hyper = { version = "0.14", features = ["client", "server"] }
Expand All @@ -34,9 +37,10 @@ testcontainers = { version = "0.17.0", optional = true }
cargo_metadata = { version = "0.18.1", optional = true }

[dev-dependencies]
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
serde_json = "1.0"
criterion = "0.5.1"
httpmock = { version = "0.7.0"}
serde_json = "1.0"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

[features]
test-utils = ["httpmock", "testcontainers", "cargo_metadata"]
test-utils = ["httpmock", "testcontainers", "cargo_metadata"]
63 changes: 63 additions & 0 deletions trace-utils/benches/deserialization.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/
// SPDX-License-Identifier: Apache-2.0

use criterion::{criterion_group, Criterion};
use datadog_trace_utils::tracer_header_tags::TracerHeaderTags;
use datadog_trace_utils::tracer_payload::{
TraceEncoding, TracerPayloadCollection, TracerPayloadParams,
};
use serde_json::json;

pub fn deserialize_msgpack_to_internal(c: &mut Criterion) {
let span_data1 = json!([{
"service": "test-service",
"name": "test-service-name",
"resource": "test-service-resource",
"trace_id": 111,
"span_id": 222,
"parent_id": 100,
"start": 1,
"duration": 5,
"error": 0,
"meta": {},
"metrics": {},
}]);

let span_data2 = json!([{
"service": "test-service",
"name": "test-service-name",
"resource": "test-service-resource",
"trace_id": 111,
"span_id": 333,
"parent_id": 100,
"start": 1,
"duration": 5,
"error": 1,
"meta": {},
"metrics": {},
}]);

let data =
rmp_serde::to_vec(&vec![span_data1, span_data2]).expect("Failed to serialize test spans.");
let tracer_header_tags = &TracerHeaderTags::default();

c.bench_function(
"benching deserializing traces from msgpack to their internal representation ",
|b| {
b.iter(|| {
let params = TracerPayloadParams::new(
&data,
tracer_header_tags,
Box::new(|_chunk, _root_span_index| {}),
false,
TraceEncoding::V04,
);

let result: Result<TracerPayloadCollection, _> = params.try_into();
assert!(result.is_ok())
})
},
);
}

criterion_group!(benches, deserialize_msgpack_to_internal);
8 changes: 8 additions & 0 deletions trace-utils/benches/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/
// SPDX-License-Identifier: Apache-2.0

use criterion::criterion_main;

mod deserialization;

criterion_main!(deserialization::benches);

0 comments on commit bbc9f26

Please sign in to comment.