A unique ID generator that's a hundredfold faster than a UUID

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed. # Preface in game development, we often have to set a globally unique ID for a Request, object, or something else. The common choices are random numbers, timestamps, UUID, and Redis generation IDs, which can either be duplicated or too slow, so I developed wuid, a very fast unique ID generator. [Wuid] (Https://github.com/edwingeng/wuid) is 10-135 times faster than UUID, 4,600 times times faster than using Redis to generate IDs. # core Design [Wuid] (HTTPS://GITHUB.COM/EDWINGENG/WUID) sequentially generates a 64-bit integer whose high 24 bits are loaded from external storage and automatically plus 1 per load. Currently supported external storage includes: Redis, MySQL, MongoDB. # benchmarks "Benchmarkwuid 100000000 10.3 ns/op 0 b/op 0 allocs/opbenchmarkrand 50000000 24.6 ns/op 0 B/op 0 allocs/opBe Nchmarktimestamp 100000000 12.3 ns/op 0 b/op 0 allocs/opbenchmarkuuid_v1 20000000 107 ns/op 0 B/op 0 Allocs/opBenchmarkUUI D_V2 20000000 106 ns/op 0 b/op 0 allocs/opbenchmarkuuid_v3 5000000 359 ns/op 144 b/op 4 allocs/opbenchmarkuuid_v4 1000000 1376 ns/op 16 B/op 1 allocs/opBenchmarkUUID_V5 3000000 424 ns/op 176 B/op 4 allocs/opBenchmarkRedis 30000 46501 ns/op 176 B/op 5 allocs/opbenchmarksnowflake 5000000 244 ns/op 0 b/op 0 allocs/op ' # Features-extremely fast-thread safety-guaranteed to be unique within the same room-guaranteed across time unique-by sharing external storage or set section ID, which can be globally unique-generates 100 million id-low per second40 bits are about to be exhausted when automatically acquiring new high 24-bit # using example ' Goimport ' Github.com/edwingeng/wuid/redis "//SETUPG: = Wuid. Newwuid ("Default", nil) G.loadh24fromredis ("127.0.0.1:6379", "", "wuid")//generatefor I: = 0; I < 10; i++ {fmt. Println (G.next ())} "' # Portal [Https://github.com/edwingeng/wuid] (HTTPS://GITHUB.COM/EDWINGENG/WUID) 628 reads  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.