-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New feature suggestion: request-id plugin supports "snowflake" algorithm #4209
Comments
This is a feature to be implemented, and as far as I know there is no suitable implementation of the snowflake algorithm in the lua language, see also this comment: Lines 296 to 299 in ac21146
|
I have my own request-id plugin implements a snowflake algorithm using https://github.com/stuartcarnie/lua-snowflake |
@dickens7 |
I am now doing it as a standalone plugin, so I will submit a version first |
@dickens7 |
And there is a question, how can it handle more than 1024 workers? |
no problem
|
This is a problem. Now only the error log is printed. Subsequent worker_number is nil and an exception will be thrown. |
What about forking that library and modify it? machine bits: 10 We can change it to machine bits: 16 (65535 workers) |
Or we could implement it like sonyflake to change the time interval from 1ms to 10ms, and then we would have ~80 years. But not sure if 512 per 10ms is enough for us |
It' OK, as it's not possible that a single worker can handle about |
I just made a simple benchmark, and found the max value of count in a ms is 511, which is the default backlog of the TCP socket. Since the number can be increased, now I recommend using machine bits: 16 The epoch needs to be divided by 2 years so that we don't need to update it in 2023. Also need to notify people if they have customized the backlog. @dickens7 |
the first bit should stay at 0 and actually only use 63bit Sonyflake definition
You might need to fetch 2 bits to do a dial back, to deal with the time callback problem
The start_time is designed to be configurable |
ok. |
10 bits for 10 msec is not enough as I proved. Maybe it is faster to change lua-snowflake to support this (only need to change some constants). |
I will fork lua-snowflake and change it according to this algorithm definition
|
Great! It would be better if you can make the bit numbers configurable. The fork is done: https://github.com/api7/lua-snowflake |
We can do it in the future |
@spacewander |
Add support for snowflake algorithm to Request-ID plugin, or provide a separate snowflake algorithm plugin.
The text was updated successfully, but these errors were encountered: