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

span-reporter span id generation is very slow. #18

Open
rohitprg opened this issue Oct 11, 2021 · 0 comments
Open

span-reporter span id generation is very slow. #18

rohitprg opened this issue Oct 11, 2021 · 0 comments

Comments

@rohitprg
Copy link

rohitprg commented Oct 11, 2021

Span reporter uses UUID.randomUUID() to generate the span id, which internally uses SecureRandom and is very slow.

Whereas tracer server like Jaeger uses Java6CompatibleThreadLocalRandom.current().nextLong() which is 10 times faster with no contention(one thread) and around 50 to 100 times faster with contention (multilple threads) compared to UUID.randomUUID().

Instead of creating its own span id, span reporter can get the span id from the tracing implementation i.e. wspan.context().toSpanId(). Could span-reporter use random instead of uuid or something like below??

@Override
public Span start() {
    Span wspan = wrapped.start();
    String spanId;
    SpanContext spanContext = wspan.context();
    if (spanContext != null) {
        spanId = spanContext.toSpanId();
    } else {
        spanId = UUID.randomUUID().toString();
        wspan.setBaggageItem(BAGGAGE_SPANID_KEY, spanId);
    }

This is a picture profiled on my production server. The cost comes from the following areas:

SpanBuilderR.start():
    UUID.randomUUID(): 17%
    Adding the custom id to baggageItems: 13%
    UUID.toString(): 2%
SpanBuilderR.addReference: when we set a span as a child of another span we need to search the baggage items for the custom span id: 2%

Providing an option to use the tracing implementations span id will completely remove this cost.

@rohitprg rohitprg changed the title span-reporter span id generation is very slow span-reporter span id generation is very slow. Oct 11, 2021
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

No branches or pull requests

1 participant