Coder Social home page Coder Social logo

Comments (5)

RobThree avatar RobThree commented on August 18, 2024

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)}");
    }
}

image

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.

RobThree avatar RobThree commented on August 18, 2024

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.

ArvinHsieh avatar ArvinHsieh commented on August 18, 2024

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.

RobThree avatar RobThree commented on August 18, 2024

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.

ArvinHsieh avatar ArvinHsieh commented on August 18, 2024

Ok, I understood. Thanks.

from idgen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.