This is a creation in Article, where the information may have evolved or changed.
Objective
In game development, we often have to set a globally unique ID for a request, an 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.
The wuid is 100 times times faster than the UUID, 4,600 times times faster than the Redis generation ID.
Core Design
The wuid sequence generates a 64-bit integer whose high 24 bits are loaded from the external storage and automatically plus 1 per load.
Currently supported external storage includes: Redis, MySQL, MongoDB.
Benchmarks
Benchmarkwuid 200000000 9.38 ns/op 0 b/op 0 allocs/opbenchmarkwuid-4 20000000 0 9.19 ns/op 0 b/op 0 allocs/opbenchmarkrand 100000000 21.6 ns/op 0 B/op 0 allocs/opbenchmarkrand-4 100000000 21.9 ns/op 0 b/op 0 Allocs/opbenchm Arktimestamp 2000000 669 ns/op 0 b/op 0 allocs/opbenchmarktimestamp-4 2000000 664 ns/op 0 b/op 0 allocs/opbenchmarkuuid_v1 2000000 888 ns/op 0 B/OP 0 allocs/opbenchmarkuuid_v1-4 2000000 871 ns/op 0 b/op 0 Allocs/opbenchmarkuui D_V2 2000000 904 ns/op 0 b/op 0 allocs/opbenchmarkuuid_v2-4 2000000 8 Ns/op 0 b/op 0 allocs/opbenchmarkuuid_v4 1000000 1325 ns/op 1 Allocs/opbenchmarkuUid_v4-4 1000000 1287 ns/op b/op 1 Allocs/opbenchmarkredis 30000 4 3970 ns/op 176 b/op 5 allocs/opbenchmarkredis-4 30000 42279 ns/op 176 b/op 5 allocs/op
Characteristics
- Extremely fast speed
- Thread Safety
- Guaranteed to be unique within the same room
- Guaranteed across time only
- Low 40 bits are about to be exhausted when the new high 24 bit is automatically acquired
Using the example
import "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())}
Transmission Door
Https://github.com/edwingeng/wuid