Skip to content
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

perf(export): do not allocate arrays if resource has no pending async attributes #4550

Merged
merged 4 commits into from
Mar 25, 2024

Conversation

Samuron
Copy link
Contributor

@Samuron Samuron commented Mar 17, 2024

Which problem is this PR solving?

OpenTelemetry is producing too much overhead for scenarios with significant load. One of the example is BatchSpanExporter, that is allocating array of batch size only to check is it has any pending attributes.

Fixes # (issue)

Short description of the changes

Replaced map & filter with a simple loop.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Benchmarks:

Before
create spans (10 attributes) x 689,041 ops/sec ±1.54% (92 runs sampled)
BatchSpanProcessor process span x 660,065 ops/sec ±1.08% (95 runs sampled)

After:
create spans (10 attributes) x 688,731 ops/sec ±1.15% (94 runs sampled)
BatchSpanProcessor process span x 673,550 ops/sec ±1.01% (93 runs sampled)

  • Test A

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

@Samuron Samuron requested a review from a team March 17, 2024 06:35
Copy link

linux-foundation-easycla bot commented Mar 17, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@Samuron Samuron force-pushed the batch_span_allocations branch from 130b958 to c5b52e2 Compare March 17, 2024 06:40
@Samuron
Copy link
Contributor Author

Samuron commented Mar 17, 2024

I am not sure that the benchmarks are very representational though, they fluctuate a lot and the numbers are suspiciously close to just creating spans

@Samuron Samuron force-pushed the batch_span_allocations branch from c30f8ff to d38b316 Compare March 17, 2024 11:59
Copy link

codecov bot commented Mar 18, 2024

Codecov Report

Merging #4550 (670bfbb) into main (f9a0d3e) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4550      +/-   ##
==========================================
- Coverage   92.84%   92.84%   -0.01%     
==========================================
  Files         328      327       -1     
  Lines        9487     9471      -16     
  Branches     2035     2032       -3     
==========================================
- Hits         8808     8793      -15     
+ Misses        679      678       -1     
Files Coverage Δ
...dk-trace-base/src/export/BatchSpanProcessorBase.ts 95.31% <100.00%> (+1.09%) ⬆️

... and 1 file with indirect coverage changes

@Samuron Samuron force-pushed the batch_span_allocations branch 2 times, most recently from dbc220e to 9daef95 Compare March 18, 2024 10:30
Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Please also add a changelog entry under CHANGELOG.md (scope is sdk-trace-base, enhancement).

Ad benchmarks: I think they're not too representative in his case as they all only use a single span. If there was a benchmark with thousands of spans I think the improvement may be more visible.

@Samuron Samuron force-pushed the batch_span_allocations branch from 9daef95 to 3fc1573 Compare March 20, 2024 11:41
@Samuron Samuron force-pushed the batch_span_allocations branch from 3fc1573 to a4f45c7 Compare March 20, 2024 12:43
CHANGELOG.md Outdated Show resolved Hide resolved
@pichlermarc pichlermarc merged commit 5fb65b4 into open-telemetry:main Mar 25, 2024
20 checks passed
Zirak pushed a commit to Zirak/opentelemetry-js that referenced this pull request Sep 14, 2024
… attributes (open-telemetry#4550)

* perf(eport): do not allocate arrays if resource has no pending async attributes

* perf(export): do not use splice if fit in one batch

* Update CHANGELOG.md

Co-authored-by: Marc Pichler <[email protected]>

---------

Co-authored-by: Marc Pichler <[email protected]>
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.

2 participants