Comments (6)
The reason being blocking a thread takes away a thread that could have processed another request.
For long-running tasks or being memory-, cache- or I/O bound. But IdGen is CPU bound and not long running and the locks aren't for any long running tasks. If you have changed this in your local copy, could you benchmark it compared to this version and share your results?
from idgen.
Why not use the specific generator to generate an Id? Just create an instance of each generator (I'd keep them around, maybe in an array or dictionary or...) and call CreateId()
on the generator that you want?
from idgen.
I did think by doing that, but our logic is a bit complex so we'd have to maintain an array of 16+ generators. Not unreasonable, but thought if we could just pass generator Id in createId, it'll be a lot cleaner code.
from idgen.
Another feature would be to replace the lock with SemaphoreSlim(1,1) - which allows WaitAsync, and make the method CreateId async, so that it can be used in asp.net without affecting performance.
from idgen.
I did think by doing that, but our logic is a bit complex so we'd have to maintain an array of 16+ generators. Not unreasonable, but thought if we could just pass generator Id in createId, it'll be a lot cleaner code.
It may be cleaner code in your case but I think it clouds the code for the general usecase. You're using IdGen's generator ID "creatively" to 'bend' it to encode some other info into the Id; I don't think that's the case we should design for.
Another feature would be to replace the lock with SemaphoreSlim(1,1) - which allows WaitAsync, and make the method CreateId async, so that it can be used in asp.net without affecting performance.
There's nothing async about the method; and making it async doesn't magically improve performance somehow. The method is fast (there's probably some room for improvement) and I don't see how making it async would improve matters. It's like asking for a Guid.NewGuidAsync()
.
from idgen.
It may be cleaner code in your case but I think it clouds the code for the general usecase. You're using IdGen's generator ID "creatively" to 'bend' it to encode some other info into the Id; I don't think that's the case we should design for.
If you look at other derivates of Snowflake , e.g. Instagram, discord, they all took the format but adopted it, mainly the middle part (generator Id) to their own usage. It's upto you if the change is worth it or not. I decided to just made a local copy of this project and modified the code and locking to fit our usage.
There's nothing async about the method; and making it async doesn't magically improve performance somehow. The method is fast (there's probably some room for improvement) and I don't see how making it async would improve matters. It's like asking for a
Guid.NewGuidAsync()
.
In asp.net any thread blocking call is strongly discouraged, which is exactly what 'lock' does. The reason being blocking a thread takes away a thread that could have processed another request. That's the reason why SemaphoreSlim was introduced, so you can await on the semaphore by calling WaitAsync, without actually blocking a thread.
These are just my suggestions, still the project was really helpful for us. 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 10
- 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.