Comments (5)
Are you sure (i.e. did you confirm) the _machineId
differs on each machine?
static void Main(string[] args)
{
var a = new IdGenerator(1, new IdGeneratorOptions(sequenceOverflowStrategy: SequenceOverflowStrategy.SpinWait));
var b = new IdGenerator(2, new IdGeneratorOptions(sequenceOverflowStrategy: SequenceOverflowStrategy.SpinWait));
for (int i = 0; i < 10; i++)
{
var a_id = a.CreateId();
var b_id = b.CreateId();
Console.WriteLine($"A: {a_id} {Convert.ToString(a_id, 2)}");
Console.WriteLine($"B: {b_id} {Convert.ToString(b_id, 2)}");
}
}
As you can see in the above screenshot the red part contains the _machineId
(10 bits), the blue the sequence number (12 bits) and the green part the timestamp.
The values you show seem hand-crafted (probably to demonstrate the problem). Can you please show actual values?
from idgen.
Oh, wait, nevermind. I think I understood the question wrong. I think I understand now. But I will still need actual generated values (and the corresponding generator (or "machine") id along with it) to see if there's an actual problem or not.
I think what you're seeing is correct. Only part of the ID is a timestamp. There's no guarantee the ID's are all sequential since the machines/generators don't communicate between eachother. The only 'guarantee' you have, concerning ID sequences, is that for a single generator, the values are sequential. IdGen also guarantees that there are no collisions (as long as no sequence overflows occur and machine/generator ID's are different where they need to be etc.) without actually having to coordinate the IdGenerators or requiring communication between those generators. So ID's generated by different generators (on different machines) may not be, and most likely won't be, 100% sequential.
from idgen.
Oh, wait, nevermind. I think I understood the question wrong. I think I understand now. But I will still need actual generated values (and the corresponding generator (or "machine") id along with it) to see if there's an actual problem or not.
I think what you're seeing is correct. Only part of the ID is a timestamp. There's no guarantee the ID's are all sequential since the machines/generators don't communicate between eachother. The only 'guarantee' you have, concerning ID sequences, is that for a single generator, the values are sequential. IdGen also guarantees that there are no collisions (as long as no sequence overflows occur and machine/generator ID's are different where they need to be etc.) without actually having to coordinate the IdGenerators or requiring communication between those generators. So ID's generated by different generators (on different machines) may not be, and most likely won't be, 100% sequential.
Thank you for your explanation, the actual _machineId(GeneratorId) I use is 601/604, but if I want to ensure that the serial numbers generated are continuous in this scenario, is there any suggestion? For example, I need to store the ID generated each time in Redis and check whether they need to be regenerated. But this will have an impact on the generation speed for concurrent accesses.
Thanks for your reply.
from idgen.
If you need sequential, "continuous", ID's then IdGen is not for you. IdGen is, as the first line in the documentation states: "... a low-latency, distributed, uncoordinated, (roughly) time ordered, compact and highly available Id generation system". For Id's to be continuous you always need some form of coordination.
from idgen.
Ok, I understood. Thanks.
from idgen.
Related Issues (20)
- Drop support for netstandard 1.1 HOT 5
- Non-generic IIdGenerator HOT 5
- Avoid spending a sign bit by using ulongs HOT 13
- Tag 3.0.3 is missing HOT 1
- Documentation about generatorId collisions when id structure changes HOT 9
- IdGen is generating 17bit Id instead of 16bit? What should we change in the method so that it generate 16 bit Id instead of 17 bit now and in the future it continuous to generate 16 bit Id? HOT 11
- Is there a way to shorten the number of digits generated for an id? HOT 5
- Handling uniqueness ID across multiple instance of same service HOT 6
- IdGenerator does not contain a definition for 'Take' HOT 1
- Consider adding IdGenerator#CreateFromDateTime HOT 5
- Public Method Comments HOT 1
- SpinWait drastically slows continous ID generation rate for small tick length HOT 10
- Could we log how often we overflow sequence IDs and have to spinwait? HOT 1
- Concurrency issues with instances scale up HOT 2
- Use dependabot to keep references up to date HOT 1
- Sequence input for CreateId() HOT 3
- IIdGenerator is registered as a singleton, but duplicate IDs are still generated HOT 4
- Debugging InvalidSystemClockExceptions HOT 15
- Is there a way to generate id from the past HOT 1
- How to use this in distributed computing ? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from idgen.