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

Non-blocking UUID generation for Spans #3325

Closed
Andrevmatias opened this issue Apr 4, 2024 · 12 comments
Closed

Non-blocking UUID generation for Spans #3325

Andrevmatias opened this issue Apr 4, 2024 · 12 comments
Assignees
Labels
Platform: Android Platform: Java Sync: Jira apply to auto-create a Jira shadow ticket

Comments

@Andrevmatias
Copy link

Andrevmatias commented Apr 4, 2024

Problem Statement

The UUID generation for Spans is made using UUID.randomUUID() deep within the library and can't be replaced easily.

UUID.randomUUID() can be a blocking method depending on the Java distribution and OS configurations and it's resulting in a lot of our threads being blocked, impairing the system performance. We don't have control over the servers were our system is installed.

Also, the Spans and Transactions are created for every request regardless of whether it will be sent to Sentry. It occurs before the sampling process and is created even if sentry.traces-sample-rate is 0 or null. This creates a lot of UUIDs that I think are not even necessary.

Solution Brainstorm

  • Allow to set a non-blocking UUID generation fo Spans on Sentry initialization options
  • Expose the UUID generation method as a spring component/service so it can be overwritten
  • Create UUIDs just for the events that are effectively sent to Sentry
  • Allow to disable instrumentation completely through configuration without disabling sending other types of events.

┆Issue is synchronized with this Jira Improvement by Unito

@adinauer
Copy link
Member

adinauer commented Apr 8, 2024

Hello @Andrevmatias thanks for opening this issue. We'll add this to the backlog but can't say when we'll get to it.

@kozaxinan
Copy link

kozaxinan commented May 19, 2024

Hi we also see lots of CPU usage for Span creation. UUID generation and then string manipulation takes some time. There are lots of spans during Android app creation and navigating that accumulate easily.

I support creating UUID in the background thread before sending idea. or any expensive operation about that part should be in the background thread.

Screenshot 2024-05-27 at 22 53 34

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 May 19, 2024
@Angelodaniel Angelodaniel added the Sync: Jira apply to auto-create a Jira shadow ticket label May 28, 2024
@markushi
Copy link
Member

markushi commented May 29, 2024

In theory this should be straightforward:

  • Instead of generating the UUIDs in the constructor, lazily evaluate them (so they get actually generated at protocol serialization time), and use object references (like we do already for SpanId)

To consider:

  • equals methods
  • toString()

@markushi markushi moved this from Needs Discussion to Needs Investigation in Mobile & Cross Platform SDK May 29, 2024
@Angelodaniel
Copy link
Member

Hey Team, it would really help to have reduced impact on performance from the sentry library. Is there any update on this? cc @markushi

@kahest kahest moved this from Needs Investigation to Needs Discussion in Mobile & Cross Platform SDK Aug 6, 2024
@getsantry getsantry bot removed the status in GitHub Issues with 👀 3 Aug 6, 2024
@kahest
Copy link
Member

kahest commented Aug 6, 2024

@Angelodaniel thx for the ping, we'll revisit prio for this

@stefanosiano
Copy link
Member

@lbloder Can you have a look at this?

@adinauer
Copy link
Member

Reminder to check which improvements make sense to port to v7

@lbloder
Copy link
Collaborator

lbloder commented Oct 18, 2024

Hi @Andrevmatias, @kozaxinan,
I'm currently testing some optimizations for UUID Generation, could you tell me which Android/Java Version you're using?

@kozaxinan from which android version does your profile chart come from?

I'm asking because apparently UUID.toString() has pretty bad performance on Java 8 and below. Java 9 and upwards should be a lot faster by default.

@kozaxinan
Copy link

Our minimum API is 23. I used a device with API 34 for this.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Oct 18, 2024
@Andrevmatias
Copy link
Author

Andrevmatias commented Oct 19, 2024

We are using Java 17. We implemented the Sentry instrumentation only because we upgraded the JDK from 8. We are aware of the Java 8 UUID problems.

Our main problem is that our software does a lot of operations per second and all of them are generating UUIDs now. Most of the times, needlessly.

@adinauer
Copy link
Member

Thanks @Andrevmatias we're currently testing some improvements to speed up the ID generation.

@adinauer
Copy link
Member

We have just released 8.0.0-beta.2 of the Java SDK, which improves ID generation. If you decide to give it a try, feedback would be great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: Android Platform: Java Sync: Jira apply to auto-create a Jira shadow ticket
Projects
Archived in project
Archived in project
Archived in project
Development

No branches or pull requests

8 participants