Comments (5)
i thought to use the last part of the kubernetes pod hostname together with the gethashcode which generates an integer but that is not in the range of the 10 available bits
To make something in range you can also do hashcode % 1024
but that is very likely going to give collisions.
the last part of the ip address
You can take the last 10 bits. As long as all IP's are in the same subnet that should work I suppose.
from idgen.
I thought of using the Process.ID which should be unique enough
I'm quite sure it's not unique at all; process ID's are very predictable (and usually a multiple of 4 so you'd waste 75% unless you divide by 4 - not sure if this is true for Azure functions though).
I thought of converting a GUID to an int (via a byte[]) but both are too large
You could take 10 bits (any 10) of a GUID and use those. But the chances of a collision are quite high. You really, really want to make sure no two generators use the same generator ID because that will cause collisions and if you have that then you might as well just try to generate random ID's (which will also result in collisions).
What you want is to coordinate the handing out of generator ID's. If you can't use an instance id (I don't know enough about azure functions to know if that's a thing) then you'll have to create a service or something that 'hands out' generator-id's for the generators ensuring you don't hand out an ID that's already in use.
(Also: what's up with the empty image below your post?)
from idgen.
Thanks for the response @RobThree. I'm not quite sure about the image, it was supposed to be a clip from the exception; not really needed.
The instance id (InvocationId) of the Az Funcs is a GUID, so not directly usable. I thought about managing the generator ids via some kind of factory but wanted to check in with you before heading in that direction. It'll be tricky though in a high volume distributed service where I'm trying to keep the points of failure to a minimum. Sequence is not a requisite for us, uniqueness is. Any experience you have with a factory pattern for IdGen would be useful.
from idgen.
Any experience you have with a factory pattern for IdGen would be useful.
I usually have generators that are long(er) lived; spun up instances of services. I take/hand-out a generator-id whenever a new generator is "spun up"; it being 'costly' doesn't matter so much since they're around for a long(er) time. In essence you can keep track of the generators in a 'coordinator service' that binds a generator id to, say, a hostname or whatever.
Even better (and actually the most common usecase for me): I put the generator-id in the configuration of a service. That way you don't need a coordinator (you could consider manually configuring generator id's as coordination though). But that isn't very 'dynamic'.
from idgen.
Hi All, i am facing the same issue in my kubernetes cluster. I need to generate an integer between 0 en 1023. My pods spin up automatically based on a configuration file in ArgoCd. We can increase/decrease the running number of pods when we want. First i thought to use the last part of the kubernetes pod hostname together with the gethashcode which generates an integer but that is not in the range of the 10 available bits. I am now thinking at the last part of the ip address, as i want to avoid adding a sidecontainer to coordinate the generation of ids. That's my last resort :-)
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.