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

Heavily contended lock in TraceIDGenerator.generateID #767

Open
ankon opened this issue Aug 10, 2023 · 0 comments
Open

Heavily contended lock in TraceIDGenerator.generateID #767

ankon opened this issue Aug 10, 2023 · 0 comments

Comments

@ankon
Copy link

ankon commented Aug 10, 2023

func (tg *TraceIDGenerator) generateID(len int) string {
var bits [maxIDByteLen]byte
tg.Lock()
defer tg.Unlock()
tg.rnd.Read(bits[:len])
return hex.EncodeToString(bits[:len])
}

In a heavily used server a lot of segments end at the same time, and from what see in the profiles this lock is a problem.

  1. Can it be avoided at all? For instance, using some magic "per-thread" generator (as much as that is possible, but possibly just having more than one rand instance might work?)
  2. If it cannot be avoided, can it be made smaller? I see that it uses defer to unlock, which means it unlocks after the conversion of the bits to the hex representation needed in the ID. Maybe it can be explicitly unlocked at least before that?

image

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