sschiau / Particle

64 bit ID Generator
MIT License
133 stars 28 forks source link

Duplicated ID's for different $machine_id's #2

Closed bermi closed 10 years ago

bermi commented 10 years ago

After running the following test http://3v4l.org/eHKCc and getting the following output for 5.5.3 (and other versions)

Same machine same time
1395792668864
1395792668864
1395792668864
1395792668864
1395792668864
1395792668864
Different machine same time
1395792668864
1395792668864
1395792668864
1395792668864
1395792668864
1395792668864
Same machine different time
1395792668865
1395792668867
1395792668868
1395792668869
1395792668870
1395792668871

It looks like Particle will:

Using usleep(1000) between calls could prevent the same id's when running on the same process, but does not prevent two processes on the same machine from producing the same ID.

It looks like some implementations like https://github.com/T-PWK/flake-idgen are using a worker id, which could potentially be the pid of the process. This could solve the same server different process issue.

But the $machine_id issue seems like a bug to me unless I'm not using Particle correctly.

Are these known issues? Can they be addressed/prevented? Could the docs include details about these limitations?

Thanks

sschiau commented 10 years ago

@bermi what you wrote up is just UNIX time... not IDs

sschiau commented 10 years ago

@bermi check this http://3v4l.org/0MP6t

bermi commented 10 years ago

@sschiau you're right I messed the implementation! http://3v4l.org/LbspE shows a different ID.

I was under the impression that "Directly Sortable" on Particle (and twitter snowflake's) behaved the same way as flake-idgen, where their decimal representation of id's is sortable.

Is there a way to get a sortable ID using Particle?

sschiau commented 9 years ago

@bermi the last revision fixes that problem https://github.com/sschiau/Particle/tree/ff9ab56e92931194c00433f63699cfc094025006