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

Can hb_id always be unique? #325

Closed
sidepelican opened this issue Dec 28, 2023 · 7 comments
Closed

Can hb_id always be unique? #325

sidepelican opened this issue Dec 28, 2023 · 7 comments

Comments

@sidepelican
Copy link
Contributor

Currently, hb_id is an integer sequence value in each process.
I don't fully understand why current hb_id' works like this, but for logging I would prefer it to be unique across all processes.

This creates extra work when I query logs associated with specific requests.
This is because logs are taken from each application server and put together (like in CloudWatch).

Vapor uses UUID, but Hummingbird is not.
Maybe this is because it doesn't depend on Foundation.
I think making a random string that's as long with UUID, with something like SystemRandomNumberGenerator, might be good.

@adam-fowler
Copy link
Member

adam-fowler commented Dec 28, 2023

hb_id is generated from an incrementing 64 bit atomic. You would need to have 9223372036854775807 requests to your server before the id generated a duplicate.

@adam-fowler
Copy link
Member

adam-fowler commented Dec 28, 2023

Or are you concerned about ids across multiple processes?

Rereading your issue it appears this is the case. I can look into changing this.

@sidepelican
Copy link
Contributor Author

Yes, I'm assuming to run application in environments like ECS or Cloud Run.

@adam-fowler
Copy link
Member

adam-fowler commented Dec 28, 2023

Just using a single 64 bit value random number will increase the likely hold of clashes. I might break this into two 64 bit values. A randomly generated number per server and the incrementing value.

And combine them into one id

@sidepelican
Copy link
Contributor Author

UUIDv4 is 122 bit.
The proposed value is 128 bit but the half bits have bias.

I would prefer to have a completely random 128-bit value,
but it is possible that sequential values would have better performance than generating random numbers.

I think both are effective.

@adam-fowler
Copy link
Member

#326

@sidepelican
Copy link
Contributor Author

#326 seems to be merged. thanks!

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

2 participants