Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Open source | Why use the ns4_gear_idgen ID generator?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Introduction: Yixin officially opened up nextsystem4 (hereinafter referred to as "NS4") series modules on March 29th, 2019. The open source NS4 series module is a distributed business system solution around the current payment system, which is bulky, high code coupling and high maintenance cost. The NS4 series framework allows the creation of complex processes / business flows, and the implementation of business service nodes can be concatenated and distributed. It is compact and lightweight, and realizes the independent operation of "off-container" (does not rely on tomcat, jetty and other containers). The design idea of NS4 series framework is to separate business from logic. Developers can achieve a business system with complex logic, efficient performance and stable function through simple configuration and business implementation. Click to view the overall introduction of the framework

The NS4 series includes four open source modules, namely: ns4_frame distributed service framework (details: open source | ns4_frame distributed service framework development guide), ns4_gear_idgen ID generator component (NS4 framework Demo example), ns4_gear_watchdog monitoring system component (service daemon, application performance monitoring, data collection, automatic alarm system) and ns4_chatbot communication component.

Among them, ns4_gear_idgen (ID generator) is based on the ns4_frame framework, which supports distributed deployment and generates a globally unique ID, in which the length, prefix, suffix, step size and binary can be freely configured according to their own business, and the NS4.0 framework can be tested through ns4_gear_idgen. This paper focuses on the advantages of ns4_gear_idgen (ID Generator) scheme.

Open source address of the project: https://github.com/newsettle/ns4_gear_idgen

I. introduction

In complex systems, it is often necessary to use a meaningful and ordered sequence number as a globally unique ID to identify a large amount of data (such as order accounts).

II. Introduction to the industry solution 2.1 timestamp scheme

Take the current milliseconds / microseconds as the ID, such as System.currentTimeMillis ()

Advantages

Generate ID locally without making remote calls and have a low latency. The generated ID trend is increasing. The generated ID is an integer, and the query efficiency is high after indexing.

Shortcoming

If the concurrency is too high, a duplicate ID will be generated. Cannot be highly available, there is a single point of failure problem. It is not flexible enough to achieve ID isolation for different businesses. 2.2 UUID scenario

The standard form of UUID (Universally Unique Identifier) consists of 32 hexadecimal digits, divided into five segments by hyphens and 36 characters in the form of 8-4-4-4-12. Example: 550e8400mure29bMur41d4mura716446655440000. So far, there are five ways to generate UUID in the industry. For more information, please see the UUID specification A Universally Unique IDentifier (UUID) URN Namespace published by IETF.

Advantages

Very high performance: locally generated, no network consumption.

Shortcoming

Not easy to store: UUID is too long, 16 bytes and 128bits, usually expressed as a 36-length string, which is not suitable for many scenarios. Information insecure: the algorithm for generating UUID based on MAC addresses may cause MAC address disclosure, which has been used to find the location of people with Melissa's disease. Unordered ID: there is no order before ID.

When ID is used as a primary key, there will be some problems in a specific environment. For example, in the case of DB primary key, UUID is very unsuitable:

A: MySQL officials clearly recommend that the primary key should be as short as possible [4]. The UUID of 36 characters does not meet the requirements.

All indexes other than the clustered index are known as secondary indexes. In InnoDB, each record in a secondary index contains the primary key columns for the row, as well as the columns specified for the secondary index. InnoDB uses this primary key value to search for the row in the clustered index. If the primary key is long, the secondary indexes use more space, so it is advantageous to have a short primary key.

B: bad for MySQL index. As the primary key of the database, the disorder of UUID under the InnoDB engine may cause frequent changes in the data location and seriously affect the performance. 2.3 Snowflake scenario

Generally speaking, this scheme is an algorithm for generating ID by dividing namespaces (UUID is also calculated, because it is more common, so it is analyzed separately). This scheme divides the 64-bit into multiple segments to mark the machine, time, etc., such as 64-bit in snowflake. The following figure (picture from the network) shows:

The time of 41-bit can be expressed (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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report