Comments (3)
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.
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.
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)
- cmd template should use text/template to avoid escaping HOT 1
- Wrong epoch date in README? HOT 3
- How it works with MySQL HOT 5
- Is it possible to generate KSUID from SQL? HOT 2
- Min/Max KSUID private HOT 1
- [Request] Add Go mod support HOT 1
- KSUID from string? HOT 1
- KSUID is not nanosecond-aware HOT 1
- How do I convert from `string` to `ksuid.KSUID` format? HOT 1
- Passing a timestamp before the epoch to FromParts does not return an error
- What happens after 100 years? HOT 3
- What is the differences between Sync and Async? HOT 1
- Postgres extension written in rust to generate ksuid HOT 2
- [Question]: Could I pass my own payload to ksuid?
- [Question]: I know that is not possible to use more than 16 bit payload, but what's the reason?
- GUID comparison HOT 2
- KSUID order not predictable HOT 5
- Parse accepts argument containing non-alphanumeric characters HOT 1
- KSUIDs do not sort properly. HOT 1
- Customizable epochStamp for KSUIDs Generated from Past Dates
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 ksuid.