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(opentelemetry): Bucket spans for cleanup #14154

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

fmorett
Copy link

@fmorett fmorett commented Oct 31, 2024

  • If you've added code that should be tested, please add tests.
  • Ensure your code lints and the test suite passes (yarn lint) & (yarn test).

We had a huge performance problem with a overhead of 5x or so in CPU Load. We investigated the issue and saw that the cleanup logic for OTEL ran on every span end. Thats why we rewrote this to run only once every interval.

I do not guarantee that this code is perfect, this is just a hint, that there is something wrong currently.

@AbhiPrasad
Copy link
Member

Hey @fmorett thank you for the PR.

I opened a GH issue in #14177 for this so that we can discuss further as a group and see what other users think as well.

We'll try to get a maintainer assigned to this ASAP - appreciate your patience in the meantime.

@lforst lforst self-requested a review November 12, 2024 11:48
@lforst lforst self-assigned this Nov 12, 2024
@lforst lforst changed the title perf(otel): Only cleanup old spans every interval once perf(opentelemetry): Bucket spans for cleanup Nov 12, 2024
@lforst lforst requested a review from mydea November 12, 2024 13:49
}

/** Try to flush any pending spans immediately. */
public flush(): void {
this._clearTimeout();

const openSpanCount = this._finishedSpans.length;
const finishedSpans: ReadableSpan[] = [];
this._finishedSpanBuckets.forEach(bucket => {
Copy link
Member

Choose a reason for hiding this comment

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

l: Can we instead add a get _finishSpans(): ReadableSpan[] getter on the exporter class and use this? This makes it easier to test this as well as we can just access this in tests too? 🤔

Copy link
Member

@lforst lforst Nov 14, 2024

Choose a reason for hiding this comment

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

I will not add a public function for this. This is an implementation detail that should not be exposed. I can however extract this functionality into a private fn, which I also do not particularly like since we do this operation exactly one time (apart from in tests, which is whatever).

Copy link
Member

Choose a reason for hiding this comment

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

yeah I do not mean a public function, but just making it a private method on the class, then it is also not exposed but we can use it in tests. right now we duplicate the logic in the test so if that runs apart we may not notice (it's really a nit so feel free to disregard). In the tests we could then do, instead of:

const finishedSpans1 = [];
    exporter['_finishedSpanBuckets'].forEach((bucket: any) => {
      if (bucket) {
        finishedSpans1.push(...bucket.spans);
      }
    });

just

const finishedSpans1 = exporter['_finishedSpans'];

or something like this.

public constructor(options?: { timeout?: number }) {
this._finishedSpans = [];
this._timeout = options?.timeout || DEFAULT_TIMEOUT;
private _finishedSpanBuckets: (FinishedSpanBucket | undefined)[];
Copy link
Member

Choose a reason for hiding this comment

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

l: Could we add comments to these explaining what they do here, e.g. why do we keep the spansToBucketEntry etc? it all makes sense to me, but for the sake of our future selves :D

Copy link
Member

Choose a reason for hiding this comment

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

👍 added a comment

@lforst lforst requested a review from mydea November 14, 2024 10:19
@mydea
Copy link
Member

mydea commented Nov 14, 2024

@fmorett any chance you could test @lforst 's updated implementation in this PR and see if that actually fixes/improves the overhead? FWIW I think it is a good change regardless, but would be cool to know if this actually fixes the problem or if another problem remains.

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.

4 participants