tangledbytes / nodejs-snowflake

Generate time sortable 64 bits unique ids for distributed systems (inspired from twitter snowflake)
https://www.npmjs.com/package/nodejs-snowflake
Apache License 2.0
176 stars 15 forks source link

Add support for older node versions #5

Closed tangledbytes closed 3 years ago

tangledbytes commented 4 years ago

Currently the build fails if the node version is older than current LTS version (v12.17.0)

xuxucode commented 4 years ago

Why does machine id have 12 bits?

tangledbytes commented 4 years ago

Why does machine id have 12 bits?

@xuxucode actually the snowflake ids that are currently being generated is of strictly 64 bit (and that's the advantage of using nodejs-snowflake). Out of this 64 bit,

On my system that has Intel i5-7200U processor (not a very powerful processor) and 8GB RAM I am able to generate close to 750k unique ids per second. If I reduce even one bit from the last 10 bits (I call them sequence bits) then the max number of ids/sec that I'd be able to generate even if my thread is not maxing out would be 512k. I simply had no extra space available so 12 bit for machine id and 10 bit for sequence id seemed like a sweet spot as now although I am maxing out my thread I am still safe and generating unique ids and even if you are running it on a very powerful machine, hitting 1024 ids/millisecond would be difficult and even you will do, nodejs-snowflake would still manage to generate unique ids although not more than 1.024M ids/sec.