Giter Club home page Giter Club logo

Comments (8)

phatboyg avatar phatboyg commented on September 28, 2024

If it doesn't work for your use case, don't use it.

The goal was not just unique, but ordered identifiers.

from newid.

codematrix avatar codematrix commented on September 28, 2024

Hi @phatboyg,

I'm only stating that fact that GUIDs should guarantee uniqueness. Order and sequence can still be maintained with a high degree of quasi-uniqueness using a different and much faster technique. This is not just in my case, this is everyone's best interest. GUIDs have the assumption of being unique.

You just mentioned that:

The goal was not just unique, but ordered identifiers.

The order part your is maintained, but the most important part is uniqueness, which is not guaranteed with your current implementation. I think you should mention this limitation in your docs. Users of this library may not be aware of this.

Anyways, I'll close this issue.

from newid.

phatboyg avatar phatboyg commented on September 28, 2024

That's just it though, they are unique. If you are seeing a case where they aren't, I'd like to know about it.

And I'm going to add a method to create multiple ids in a single call, which basically cuts the time down significantly to generate 1,000,000 identifiers. So if you ask for 10, you can get 10. Or maybe I can keep an internal buffer and just allocate them more quickly. Maybe. Hmm.

from newid.

codematrix avatar codematrix commented on September 28, 2024

Hi @phatboyg,

Here's the code sample that was used to show collisions.

    static void Main(string[] args)
    {
        var c1 = new ConcurrentBag<Guid>();

        Parallel.For(0, 5000000, (i) =>
        {
            c1.Add(NewId.NextGuid());
        });

        var groups = c1.GroupBy(g => g).Where(x => x.Count() != 1).ToList();
        var maxGrouping = groups.Max(x => x.Count());
        
        Console.WriteLine($"Collisions: {groups.Count()}");
        Console.WriteLine($"MaxGroupCollisions: {maxGrouping}");
    }

I know in most cases GUIDs will be generated on different PODs and threads. However, in our case, we have a conversation queue that can only be read by a single service. We can experience anywhere between 450K - 800K messages a daily that need to be logged using unique sequential GUIDs.

Hope this help,

codematrix

from newid.

phatboyg avatar phatboyg commented on September 28, 2024

800k messages a day is nothing, as you said about, you can generate 5 million ids in about 300 milliseconds. And using your exact code, I didn't get a single duplicate in my test, so...

Well, not exact, I used an array (Guid[]) and use result[i] to store the results, instead of adding them to a bag (much slower).

from newid.

phatboyg avatar phatboyg commented on September 28, 2024

There is a develop package that has a ton of tweaks in it if you want to test it out.

from newid.

codematrix avatar codematrix commented on September 28, 2024

Sure thing, will do. I'll provide some feedback - it might take a couple days. Just got swamp with a new RFP hence why I didn't respond to the last reply.

from newid.

phatboyg avatar phatboyg commented on September 28, 2024

No worries, I've tweaked performance and moved to a SpinLock, as well as making it possible to ask for a block of ids as an array, to allocate 100's of them at once, versus one call at a time.

from newid.

Related Issues (15)

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.