In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to achieve a reduced version of snowflake algorithm and multithreaded concurrent testing". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. let's study and learn "how to achieve a reduced version of snowflake algorithm and multithreaded concurrent testing"!
When we design data tables, there are usually ID fields, and there are many ways to generate ID, such as database self-increment, UUID, snowflake algorithm and so on.
Taking into account the future data growth, sub-database sub-table, distributed and other requirements, we choose the snowflake algorithm to generate ID.
The development of Web system requires the interaction between the back end and the front end. The maximum integer supported by the front end JavaScript is 53 bits. If the integer exceeds 53 bits, the precision will be lost. The original snowflake algorithm will exceed 53 bits. We use the scaled-down version of Snow Flower algorithm to reduce the number of bits to 53 bits.
The limit of the original Snowflake algorithm is to generate 4059 id values per node per millisecond, that is to say, the limit is 023,4059,4152,357 id values per millisecond, and the reduced limit is 15,131071tons 1,966,065 distributed id per second, which is enough for our daily use in development.
Package cn.gintone.asso.util;/** * @ description: a scaled-down version of the snowflake algorithm * @ author:Elon He * @ create:2020-10-06 * / public class SnowflakeMini {/ * start time cut (1970-01-01) * / private final static long twepoch = 0L; / * Machine id, with a range of 1 to 15 * / private final static long workerId = 1L / * the number of bits occupied by the machine id, accounting for 4 digits * / private final static long workerIdBits = 4L; / * the maximum supported machine id, the result is 15 * / private final static long maxWorkerId = ~ (- 1L)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.