3 ms·
The failure on overflow is weird. Since it starts at a random point and can't overflow, even if you generate a small number of IDs per millisecond you have a c
by Dylan16807 8y ago
The failure on overflow is weird.
Since it starts at a random point and can't overflow, even if you generate a small number of IDs per millisecond you have a constant 1/2^79 chance of failing. The chance is small but reachable for a large network. (bitcoin does 2^88 hashes a day)
It could have just wrapped with no problem, because there's no possible node that could generate 2^80 IDs by itself. And if you have multiple nodes it doesn't help there either.
- daveFNbuck 8y agoOne of the constraints is that lexicographic sorting must order the nodes by generation time. This precludes wrapping. It's a little weird that they didn't just reserve or add some bits for sorting within milliseconds before or instead of having to increment the randomness.
- jonas21 8y agoYeah, they could have constrained the random value to always start with the highest bit set to 0. Then they would be guaranteed to be able to generate 2^79 values per millisecond. But that's sort of an implementation detail. You could write an implementation that did that and still be compatible with all other implementations.
- Dylan16807 8y ago> One of the constraints is that lexicographic sorting must order the nodes by generation time. This precludes wrapping. I suppose, if you're particularly worried about the one-node situation. > It's a little weird that they didn't just reserve or add some bits for sorting within milliseconds before or instead of having to increment the randomness. There's no particular reason to make the fields separate. If you mask out the top bit of the random number then they can share and also make overflow effectively impossible. It's also worth noting that there are two bits that go completely unused. They could eat overflow if the layout was slightly rearranged.
- daveFNbuck 8y ago> I suppose, if you're particularly worried about the one-node situation This algorithm doesn't work if you have multiple nodes, so I don't think any other situation is relevant here. > There's no particular reason to make the fields separate. If you mask out the top bit of the random number then they can share and also make overflow effectively impossible Yes, this is what I meant by reserving some bits. > It's also worth noting that there are two bits that go completely unused. They could eat overflow if the layout was slightly rearranged. Yeah, it's super weird they didn't do that. I guess they just really like having a power of two number of bits.
- Dylan16807 8y ago> This algorithm doesn't work if you have multiple nodes Then what's the random part for? > Yes, this is what I meant by reserving some bits. What I'm saying is, if you separate it out into an increment-field and a random-field, then you need a lot of bits and you need to fundamentally change how it works. If you merely make sure your random number starts below some threshold, you only need 1 bit, or a small fraction of a bit. You would still increment the random number, but you wouldn't have to worry about hitting the max value if you always start between 0 and 2^79.9, for example.
- daveFNbuck 8y ago> Then what's the random part for? It's for multiple nodes, which is why this algorithm doesn't make any sense for their use case.
- hiccuphippo 8y agoRegarding multiple nodes, Wouldn't each node generate a different random number? It mentions not requiring a MAC but it should use some way to seed the rng differently per node, right? However this would defeat the lexicographic sorting.
- BeeOnRope 8y agoYes, each node would have different random values, but sorting works because time is at the start of the UUID so "more significant", and sort order within a millisecond is not guaranteed.
- staticassertion 8y agoBitcoin does 2^88 a day but from what I can tell the overflow issue means you'd have to do that much in a millisecond. Seems unlikely?
- Dylan16807 8y agoThe value starts at a random point and can't overflow. This means that in a particular millisecond you might start at ZZZZZZZZZZZZZHJ and hit an error after a few hundred IDs. Your chance of hitting an issue is (roughly) proportional to the total number of IDs you generate.
- BeeOnRope 8y agoThey also say "Within the same millisecond, sort order is not guaranteed" but the carry behavior seems to be intended to preserve order even with a millisecond. I guess they mean order is not guaranteed between different UUID generators with different random parts.
- floatingatoll 8y agoHow many milliseconds of downtime per day would be 99th percentile likely to occur in the scenario you describe? What percentage of milliseconds in the day would that be?
- Dylan16807 8y agoWith a code path that's never been tested? It could potentially be a huge problem.
- floatingatoll 8y agoAssuming the coded algorithm works as specified, it’s possible to specify in probability terms what the likelihood of an algorithm outage are. It’s turtles all the way down from there, but it’s still valuable to scope “best case scenario” with probability math regardless of potential bugs in code.
- Dylan16807 8y agoIt's possible to do the analysis, but instead of trusting that it gets done I'd rather use a slightly different method that only has a success path.
- IanCal 8y ago> (bitcoin does 2^88 hashes a day) Does it? At 50M TH/s (https://www.blockchain.com/en/charts/hash-rate https://www.blockchain.com/en/charts/hash-rate) that's 10^8 TH/s, or 10^8.10^12 = 10^20 hashes per second. There's less than 10^5 seconds so surely that's only 10^25 per day. If I've messed up each of these numbers by an order of magnitude, that would leave it still well under 10^30. 2^88 is absolutely enormous.
- Dylan16807 8y agoOkay, I checked what I calculated earlier. I accidentally entered the scientific notation wrong so that was actually the number of hashes in 100 days. 10^25 is close to right for one day, and 10^25 is equal to 2^83 2^88 is both absolutely enormous and a real number that bitcoin hits in less than a year. So the point stands that a large deployment could rarely hit a 2^79 random failure case.
- IanCal 8y agoFair enough, I'd mentally worked out the 10^ -> 2^ conversion entirely wrong, sorry about that.