3 ms·
depending on scale and architecture, either behavior can be better. it’s easier to shard when writes occur randomly over the overall space. it’s easier to coale
by lazide 3y ago
depending on scale and architecture, either behavior can be better. it’s easier to shard when writes occur randomly over the overall space. it’s easier to coalesce when writes all happen in a given place (head or tail)
- remram 3y agoIf that is the case then why shouldn't the storage system hash the IDs itself, to spread them as it requires?
- lazide 3y agoBecause sometimes you want some data to be collocated, while the rest sharded. For instance, you might use a random object ID as a prefix value in the index, followed by attribute ID which isn’t. Or a modified time, so you can have a history of values which can be read out linearly. If using it directly, that means Objects and their data are sharded randomly across, but when looking for an objects attributes (or attribute by time), their index entries are always co-located and you can read them out linearly with good performance. If blindly hashing keys to distribute them, you can’t do that. Also, you can’t really do a linear read at all, since no data will be ‘associatable’ with others, as the index value is randomized, and what is stored in the index has no related to the key provided by the user. You can only do a straight get, not a read. That is very limiting, and expensive with large data sets as most algorithms benefit greatly from having ordered data. (Well, you could do a read, but you’d get back entries in completely random order) Needless to say, this is ‘advanced’ usage and requires pretty deep understanding of your data and indexing/write/read patterns, which is why random hashing is the most common hash map behavior.
- remram 3y agoSounds like it should be an attribute of the index and not require a change in the data. To me, anyway. CREATE INDEX ... USING HASH;
- lazide 3y agoI’ve never seen that kind of optimization on a dataset that would fit on a database server of any kind. Tens of PB or EB usually, but sometimes only several hundred TB if it’s high load/in-memory only.
- andromeduck 3y agoJust swizzle the ID.
- Dylan16807 3y agoBeing random within each shard is still bad for write performance. Going fully random seems like a bad way to accomplish this goal. Why not keep the timestamp bits to use when appropriate, but use some of the random bits for shard selection?
- lazide 3y agoOnly when writing all at once and when you know what the shard boundaries are and the number of shards (and boundaries) are stable. If they’re changing, growing, et c. you can’t tell where they’re at predictably and random is the least likely to cause problems and allow sub-sharding dynamically. Very large real world datasets are unlikely to be static long enough, and equipment stable enough, to not consider this effect.
- Dylan16807 3y ago> If they’re changing, growing, et c. you can’t tell where they’re at predictably and random is the least likely to cause problems and allow sub-sharding dynamically. I'm confused by your reply, because I never suggested not to use random bits for sharding. I'm just saying that 60+ random bits should be enough to shard, change, grow, and sub-shard with. You don't need 122.
- lazide 3y agoI never said anything about bit or key length at all? Let alone how much was random or not? Perhaps you’re confused?
- Dylan16807 3y agoLet's start over. People were talking about the value of time+random UUIDs versus all-random UUIDs, and how those behave. You said that sometimes the random behavior is preferable. In response to that, I was saying that even if you want to sort randomly at some particular step, you should use the time+random format, because other steps might not want to sort randomly. You should directly choose to use the random part, instead of indirectly forcing it by making the entire UUID random. Then you said "Only when writing all at once and when you know what the shard boundaries are and the number of shards (and boundaries) are stable." I can't figure out how that relates to my post. I thought you were worried about insufficient random bits to use for sharding, but apparently that wasn't your concern. So I have no idea what your concern is. If you have a use case for randomness, use the random half of the UUID.