-
Notifications
You must be signed in to change notification settings - Fork 559
Sampler Performance Testing #175
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
reyang
merged 15 commits into
open-telemetry:master
from
ziqizh:nholbrook/performance_testing
Jul 23, 2020
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
bc2141a
Add initial benchmark tests
nholbrook d5f5129
Add newline to eof
nholbrook 6bb791b
Reformat BUILD file
nholbrook bcf0a8a
Add comments
nholbrook bf1540b
Add tests to measure span creation time
nholbrook de090b3
Update comments
nholbrook c2af432
Merge remote-tracking branch 'upstream/master' into nholbrook/perform…
nholbrook bb4a468
Move duplicated tests to helper function
nholbrook d346166
Update helper functions
nholbrook bf19404
Merge branch 'master' into nholbrook/performance_testing
nholbrook a974812
Format benchmark
nholbrook dddf019
Merge remote-tracking branch 'upstream/master' into nholbrook/perform…
nholbrook 2b9c463
Merge branch 'nholbrook/performance_testing' of github.com:ziqizh/ope…
nholbrook b92ec79
Format additional files
nholbrook 2ebaebd
Merge branch 'master' into nholbrook/performance_testing
reyang 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
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 |
|---|---|---|
| @@ -1,8 +1,20 @@ | ||
| foreach(testname tracer_provider_test span_data_test simple_processor_test | ||
| tracer_test always_off_sampler_test always_on_sampler_test | ||
| parent_or_else_sampler_test probability_sampler_test) | ||
| foreach( | ||
| testname | ||
| tracer_provider_test | ||
| span_data_test | ||
| simple_processor_test | ||
| tracer_test | ||
| always_off_sampler_test | ||
| always_on_sampler_test | ||
| parent_or_else_sampler_test | ||
| probability_sampler_test) | ||
| add_executable(${testname} "${testname}.cc") | ||
| target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES} | ||
| ${CMAKE_THREAD_LIBS_INIT} opentelemetry_common opentelemetry_trace) | ||
| target_link_libraries( | ||
| ${testname} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} | ||
| opentelemetry_common opentelemetry_trace) | ||
| gtest_add_tests(TARGET ${testname} TEST_PREFIX trace. TEST_LIST ${testname}) | ||
| endforeach() | ||
|
|
||
| add_executable(sampler_benchmark sampler_benchmark.cc) | ||
| target_link_libraries(sampler_benchmark benchmark::benchmark | ||
| ${CMAKE_THREAD_LIBS_INIT} opentelemetry_trace) |
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,180 @@ | ||
| #include "opentelemetry/sdk/trace/sampler.h" | ||
| #include "opentelemetry/sdk/trace/samplers/always_off.h" | ||
|
nholbrook marked this conversation as resolved.
|
||
| #include "opentelemetry/sdk/trace/samplers/always_on.h" | ||
| #include "opentelemetry/sdk/trace/samplers/parent_or_else.h" | ||
| #include "opentelemetry/sdk/trace/samplers/probability.h" | ||
| #include "opentelemetry/sdk/trace/simple_processor.h" | ||
| #include "opentelemetry/sdk/trace/span_data.h" | ||
| #include "opentelemetry/sdk/trace/tracer.h" | ||
|
|
||
| #include <cstdint> | ||
|
|
||
| #include <benchmark/benchmark.h> | ||
|
|
||
| using namespace opentelemetry::sdk::trace; | ||
| namespace nostd = opentelemetry::nostd; | ||
| namespace common = opentelemetry::common; | ||
| using opentelemetry::trace::SpanContext; | ||
|
|
||
| /** | ||
| * A mock exporter that switches a flag once a valid recordable was received. | ||
| */ | ||
| class MockSpanExporter final : public SpanExporter | ||
|
nholbrook marked this conversation as resolved.
|
||
| { | ||
| public: | ||
| MockSpanExporter(std::shared_ptr<std::vector<std::unique_ptr<SpanData>>> spans_received) noexcept | ||
| : spans_received_(spans_received) | ||
| {} | ||
|
|
||
| std::unique_ptr<Recordable> MakeRecordable() noexcept override | ||
| { | ||
| return std::unique_ptr<Recordable>(new SpanData); | ||
| } | ||
|
|
||
| ExportResult Export(const nostd::span<std::unique_ptr<Recordable>> &recordables) noexcept override | ||
| { | ||
| for (auto &recordable : recordables) | ||
| { | ||
| auto span = std::unique_ptr<SpanData>(static_cast<SpanData *>(recordable.release())); | ||
| if (span != nullptr) | ||
| { | ||
| spans_received_->push_back(std::move(span)); | ||
| } | ||
| } | ||
|
|
||
| return ExportResult::kSuccess; | ||
| } | ||
|
|
||
| void Shutdown(std::chrono::microseconds timeout = std::chrono::microseconds(0)) noexcept override | ||
| {} | ||
|
|
||
| private: | ||
| std::shared_ptr<std::vector<std::unique_ptr<SpanData>>> spans_received_; | ||
| }; | ||
|
nholbrook marked this conversation as resolved.
|
||
|
|
||
| namespace | ||
| { | ||
| // Sampler constructor used as a baseline to compare with other samplers | ||
| void BM_AlwaysOffSamplerConstruction(benchmark::State &state) | ||
|
nholbrook marked this conversation as resolved.
|
||
| { | ||
| while (state.KeepRunning()) | ||
| { | ||
| benchmark::DoNotOptimize(AlwaysOffSampler()); | ||
| } | ||
| } | ||
| BENCHMARK(BM_AlwaysOffSamplerConstruction); | ||
|
|
||
| // Sampler constructor used as a baseline to compare with other samplers | ||
| void BM_AlwaysOnSamplerConstruction(benchmark::State &state) | ||
| { | ||
| while (state.KeepRunning()) | ||
| { | ||
| benchmark::DoNotOptimize(AlwaysOnSampler()); | ||
| } | ||
| } | ||
| BENCHMARK(BM_AlwaysOnSamplerConstruction); | ||
|
|
||
| void BM_ParentOrElseSamplerConstruction(benchmark::State &state) | ||
| { | ||
| while (state.KeepRunning()) | ||
| { | ||
| benchmark::DoNotOptimize(ParentOrElseSampler(std::make_shared<AlwaysOnSampler>())); | ||
| } | ||
| } | ||
| BENCHMARK(BM_ParentOrElseSamplerConstruction); | ||
|
|
||
| void BM_ProbabilitySamplerConstruction(benchmark::State &state) | ||
| { | ||
| while (state.KeepRunning()) | ||
| { | ||
| benchmark::DoNotOptimize(ProbabilitySampler(0.01)); | ||
| } | ||
| } | ||
| BENCHMARK(BM_ProbabilitySamplerConstruction); | ||
|
|
||
| // Sampler Helper Function | ||
| void BenchmarkShouldSampler(Sampler &sampler, benchmark::State &state) | ||
| { | ||
| opentelemetry::trace::TraceId trace_id; | ||
| opentelemetry::trace::SpanKind span_kind = opentelemetry::trace::SpanKind::kInternal; | ||
|
|
||
| using M = std::map<std::string, int>; | ||
| M m1 = {{}}; | ||
| opentelemetry::trace::KeyValueIterableView<M> view{m1}; | ||
|
|
||
| while (state.KeepRunning()) | ||
| { | ||
| benchmark::DoNotOptimize(sampler.ShouldSample(nullptr, trace_id, "", span_kind, view)); | ||
| } | ||
| } | ||
|
|
||
| // Sampler used as a baseline to compare with other samplers | ||
| void BM_AlwaysOffSamplerShouldSample(benchmark::State &state) | ||
| { | ||
| AlwaysOffSampler sampler; | ||
|
|
||
| BenchmarkShouldSampler(sampler, state); | ||
| } | ||
| BENCHMARK(BM_AlwaysOffSamplerShouldSample); | ||
|
|
||
| // Sampler used as a baseline to compare with other samplers | ||
| void BM_AlwaysOnSamplerShouldSample(benchmark::State &state) | ||
| { | ||
| AlwaysOnSampler sampler; | ||
|
|
||
| BenchmarkShouldSampler(sampler, state); | ||
| } | ||
| BENCHMARK(BM_AlwaysOnSamplerShouldSample); | ||
|
|
||
| void BM_ParentOrElseSamplerShouldSample(benchmark::State &state) | ||
| { | ||
| ParentOrElseSampler sampler(std::make_shared<AlwaysOnSampler>()); | ||
|
|
||
| BenchmarkShouldSampler(sampler, state); | ||
| } | ||
| BENCHMARK(BM_ParentOrElseSamplerShouldSample); | ||
|
|
||
| void BM_ProbabilitySamplerShouldSample(benchmark::State &state) | ||
| { | ||
| ProbabilitySampler sampler(0.01); | ||
|
|
||
| BenchmarkShouldSampler(sampler, state); | ||
| } | ||
| BENCHMARK(BM_ProbabilitySamplerShouldSample); | ||
|
|
||
| // Sampler Helper Function | ||
| void BenchmarkSpanCreation(std::shared_ptr<Sampler> sampler, benchmark::State &state) | ||
| { | ||
| std::shared_ptr<std::vector<std::unique_ptr<SpanData>>> spans_received( | ||
| new std::vector<std::unique_ptr<SpanData>>); | ||
|
|
||
| std::unique_ptr<SpanExporter> exporter(new MockSpanExporter(spans_received)); | ||
| auto processor = std::make_shared<SimpleSpanProcessor>(std::move(exporter)); | ||
| auto tracer = std::shared_ptr<opentelemetry::trace::Tracer>(new Tracer(processor, sampler)); | ||
|
|
||
| while (state.KeepRunning()) | ||
| { | ||
| auto span = tracer->StartSpan("span"); | ||
|
|
||
| span->SetAttribute("attr1", 3.1); | ||
|
|
||
| span->End(); | ||
| } | ||
| } | ||
|
|
||
| // Test to measure performance for span creation | ||
| void BM_SpanCreation(benchmark::State &state) | ||
| { | ||
| BenchmarkSpanCreation(std::move(std::make_shared<AlwaysOnSampler>()), state); | ||
| } | ||
| BENCHMARK(BM_SpanCreation); | ||
|
|
||
| // Test to measure performance overhead for no-op span creation | ||
| void BM_NoopSpanCreation(benchmark::State &state) | ||
| { | ||
| BenchmarkSpanCreation(std::move(std::make_shared<AlwaysOffSampler>()), state); | ||
| } | ||
| BENCHMARK(BM_NoopSpanCreation); | ||
|
|
||
| } // namespace | ||
| BENCHMARK_MAIN(); | ||
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.