Coder Social home page Coder Social logo

Comments (3)

achille-roussel avatar achille-roussel commented on June 13, 2024

I’m not particularly fond of the factory suggestion. The reason there’s a lock is because the random number generators in math/rand are not safe for concurrent use, and those in crypto/rand are super expansive in terms of CPU time, so the cost of synchronizing on a mutex is very low in comparison.

That being said, I haven’t run any benchmarks to test the performance of the crypto/rand generator when used in parallel from multiple goroutines, so that may be a good starting point.

We use this package a lot at Segment and we’ve never observed contention on this lock in any production service, so I’m not sure changing the API would be worth it.

from ksuid.

dahankzter avatar dahankzter commented on June 13, 2024

No perhaps you are right that in a service where you anyway hit databases and such it is not hot spot but in general the idiom is to put random sources and such are generally in a sync.Pool. As for scalability on truly multi core systems I think you can measure it quite easily but of course it needs testing.

The idea was to explore if there is a simple way to allow for the caller to decide this. When the lock is hard wired in the library it is impossible to get around.

I am not sure of the actual usage of the library but if it can be done in a non breaking way perhaps you would be open to it?

from ksuid.

achille-roussel avatar achille-roussel commented on June 13, 2024

Sure, if we can make the change with no API break there’s no reason not to.

We could also modify the constraints (like requiring the rander to be concurrent-safe), I’d really like to have a real world example showing that this lock is an contention point before making this kind of change tho.

A program can also use ksuid.FromParts if it needs to generate the radom payload itself.

from ksuid.

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.