Comments (11)
it's solved 😄
from idgen.
Which version are you using? (See #18)
The nodes aren't (usually) supposed to know about eachother; however: to synchronise their clocks you could/should use NTP.
from idgen.
I have read this post #18 before.
version: 2.1.0
You can try this code:
var idGenerator1 = new IdGen.IdGenerator(10, new DateTime(2017, 12, 8, 0, 0, 0, DateTimeKind.Utc));
await Task.Delay(20 * 1000);
var idGenerator2 = new IdGen.IdGenerator(9, new DateTime(2017, 12, 8, 0, 0, 0, DateTimeKind.Utc));
var list = new List<(int, long)>();
list.Add((0, idGenerator1.CreateId()));
list.Add((1, idGenerator2.CreateId()));
await Task.Delay(1);
list.Add((2, idGenerator2.CreateId()));
await Task.Delay(5);
list.Add((3, idGenerator1.CreateId()));
the data in list index2 is always greater than index3
from idgen.
Uh... you may have found a bug...
I'm currently looking into it. As a workaround, you may try this:
var ts = new DefaultTimeSource(new DateTime(2017, 12, 8, 0, 0, 0, DateTimeKind.Utc), TimeSpan.FromMilliseconds(1));
var idGenerator1 = new IdGen.IdGenerator(10, ts);
System.Threading.Thread.Sleep(20 * 1000);
var idGenerator2 = new IdGen.IdGenerator(9, ts);
This seems to ensure the same timesource is used.
from idgen.
Hmm, ok, so here's a bit of undefined behaviour I hadn't thought about...
It took me a while to realize... Every IdGenerator shares the same, underlying, stopwatch which is used as a timesource. However, each IdGenerator gets it's own instance of a (Default)TimeSource. And those stored, internally, an offset (when it is created) which was specific to the instance but should be shared among instances too.
In some perspective it's 'correct' behavior but I don't think it's very intuitive (hence your issue). So I've fixed it in 3935623 and will push an update to NuGet shortly.
from idgen.
I have pushed v2.2 to NuGet (may be a few minutes before it's available) should be available now. Please let me know if you still experience issues with this version.
Thanks for reporting this issue! 👍
from idgen.
That's great, thank you for such a quick response, I will have a try.
from idgen.
Why not use static constructor to start Stopwatch
? Every DefaultTimeSource
instances will start Stopwatch
, although it will not have any impact.
from idgen.
Because CA1810: Initialize reference type static fields inline 😉
Yes, the stopwatch is 'started' (actually 'resumed') every new instance but, as you said, it doesn't have any impact.
If you have sound reasoning for moving to a static constructor I'm open for discussion 😉
from idgen.
Thank you for giving me a lesson.
from idgen.
You're welcome. But more importantly: Is your problem solved now? 😉
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 13
- 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.