A method, device, and storage medium for issuing unique IDs with high throughput
By using relative timestamps and multi-cache concurrent numbering technology in distributed systems, the throughput of the snowflake algorithm is improved, the problems of low single-machine throughput and out of order of IDs are solved, and efficient and stable unique ID generation is achieved.
Patent Information
- Application Number
- CN202210051878.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-17
- Publication Date
- 2025-08-05
- Estimated Expiration
- 2042-01-17
AI Technical Summary
In distributed systems with high throughput and time-series, the stand-alone throughput of existing snowflake algorithms is too low, resulting in chaotic ID order and excessive system pressure in multiple airport scenarios, making it difficult to meet high throughput requirements.
Use long type data to store unique IDs, use relative timestamps instead of absolute timestamps, calculate relative timestamps through formulas and write timestamp bits, generate unique IDs, and add digits to the sequence number to increase the number of generations. Use multi-cache concurrent issuance and incremental unique ID issuance process to solve the issuance bottleneck in extreme cases.
The throughput of the stand-alone snowflake algorithm is improved, timing and performance are ensured, the system unavailability problem caused by the elapse of waiting time is solved, and high availability and stability are achieved.
Smart Images

Figure CN114372100B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of distributed systems, and in particular to a high-throughput unique ID issuance method, device and storage medium. Background Art
[0002] In business development, a wide range of scenarios require unique IDs for identification: users, products, messages, and events all require globally unique IDs. Globally unique IDs are especially crucial in complex distributed business scenarios. ID generators are essential foundational components in distributed software systems. Software in scenarios with data sharding requires not only uniqueness but also time sequence for IDs. Existing solutions that guarantee time sequence are based on the snowflake algorithm and batch cache auto-increment MaxID.
[0003] The core idea of the snowflake algorithm is to divide the 64-bit field into multiple segments, each used to identify the machine, time, or a specific concurrent sequence. This ensures that each machine and the ID generated by the same machine are unique. However, timestamps occupy too many bits, which reduces the throughput of a single machine.
[0004] The core idea of batch caching with auto-incremented MaxID is to generate a batch of IDs each time and distribute them to different machines for consumption. This reduces database pressure and allows for a period of time after a failure. However, in a multi-machine scenario, IDs may become out of order (because processing falls on different instances and the cached ID ranges are different).
[0005] In scenarios where high throughput is required while ensuring time series, the throughput of a single Snowflake instance is too low, necessitating the expansion of more instances to meet the high throughput requirement. This invention patent was filed in light of this. Summary of the Invention
[0006] To solve the above problems, the present invention provides a high-throughput unique ID issuance method, device, and storage medium. Specifically, the following technical solutions are adopted:
[0007] A high-throughput unique ID issuance method comprising:
[0008] The unique ID is stored using long type data, including the highest bit for storing 0 or 1, a timestamp bit for storing a timestamp, an identification bit for storing a working machine ID, and a serial number bit for generating an incremental serial number;
[0009] Get the current absolute timestamp of the unique ID service host and the relative timestamp T through the formula 相对 = Current absolute timestamp T绝对 -Base timestamp T0 obtains the relative timestamp of the unique ID service host, and the relative timestamp T 相对 Write the timestamp bit of the long type data to generate a unique ID.
[0010] As an optional embodiment of the present invention, in the high-throughput unique ID issuance method described in the present invention, the number of bits of the timestamp bit is 时间 The number of bits of the identification bit is determined according to the time accuracy benchmark of the relative timestamp. 标识 The number of bits in the serial number is determined according to the maximum machine capacity of the system. 序列 The number of bits in the serial number is Bit 序列 =Total number of bits of long type data - Number of bits of timestamp 时间 -Number of bits for the flag bit 标识 -1 is calculated;
[0011] Optionally, the time accuracy standard is at the second level, and the number of bits of the timestamp bit is less than or equal to 30 bits.
[0012] As an optional embodiment of the present invention, in the high-throughput unique ID issuance method described in the present invention, the number of bits of the timestamp bit is Bit 时间 Control is 30 bits, the number of bits of the identification bit is Bit 标识 Control is 10 bits, the number of bits of the serial number Bit 序列 24 bits;
[0013] Each coroutine (or thread) splits the number segment [1, 16777216] that can be generated by the sequence number position into multiple caches and issues numbers concurrently.
[0014] As an optional embodiment of the present invention, in a high throughput unique ID issuance method of the present invention, when the unique ID service host is provided with the current absolute timestamp T 绝对 Calculate the current relative timestamp T 相对 When the remaining number N of the corresponding unique ID number segment is 0, determine whether there are still working machines that need to be issued unique IDs;
[0015] If the result is yes, the incremental unique ID issuance process is executed:
[0016] The current absolute timestamp T of the unique ID service host 绝对 After the self-increment of n*T0, continue to issue unique IDs to the remaining working machines that need to be issued with the absolute timestamp T 绝对 +n*T0 is the unique ID in the unique ID segment corresponding to the relative timestamp;
[0017] Wherein n*T0 is incremented sequentially according to the minimum time accuracy benchmark, n is the number of increments, and n*T0 is less than or equal to the system allowable timestamp error η.
[0018] As an optional embodiment of the present invention, in a high-throughput unique ID issuance method according to the present invention, when the current absolute timestamp T of the unique ID service host is 绝对2 Updated to T 绝对1 +n*T0, the absolute timestamp T 绝对1 To occupy the current absolute timestamp T 绝对2 The unique ID of the service host is the current absolute timestamp of the unique ID. 绝对2 When the unique ID is issued, the actual number of the unique ID issued is equal to the current absolute timestamp T 绝对2 The theoretical number of issued numbers minus the absolute timestamp T 绝对1 The number of occupied numbers.
[0019] As an optional embodiment of the present invention, in the high-throughput unique ID issuance method described in the present invention, the current absolute timestamp T is preset. 绝对 The threshold N of the unique ID number that can occupy the future absolute timestamp during the incremental unique ID issuance process max , if the current absolute timestamp T 绝对 The number of unique IDs issued during the incremental unique ID issuance process reaches the number threshold N max Afterwards, if there are still working machines that need to be issued unique IDs, the working machines will be sorted and waited.
[0020] As an optional embodiment of the present invention, in the high-throughput unique ID issuance method described in the present invention, if the current absolute timestamp T 绝对 It is necessary to execute the unique ID numbering process t times, and the current absolute timestamp T 绝对 Occupancy absolute timestamp T 绝对 +n1*T0 unique ID number N1, occupies absolute timestamp T 绝对 +n2*T0 unique ID number N2, ..., occupying absolute timestamp T 绝对 +n t *T0 unique ID number N t , the N1, N2, ..., N t The value of gradually decreases,
[0021] As an optional embodiment of the present invention, in a high-throughput unique ID issuance method described in the present invention, the total number of issuances N increments in the incremental unique ID issuance process is monitored. Within a preset time period, when the N increment reaches a preset incremental number issuance amount, the incremental unique ID issuance process is prohibited.
[0022] The present invention also provides a high-throughput unique ID issuance device, comprising:
[0023] A data storage module, using long type data to store a unique ID, wherein the long type data includes a highest bit for storing 0 or 1, a timestamp bit for storing a timestamp, an identification bit for storing a working machine ID, and a serial number bit for generating an incremental serial number;
[0024] And the unique ID generation module obtains the current absolute timestamp of the unique ID service host and the relative timestamp T through the formula 相对 = Current absolute timestamp T 绝对 -Base timestamp T0 obtains the relative timestamp of the unique ID service host, and the relative timestamp T 相对 Write the timestamp bit of the long type data to generate a unique ID.
[0025] The present invention also provides a storage medium storing a computer executable program. When the computer executable program is executed, the high-throughput unique ID issuance method is implemented.
[0026] Compared with the prior art, the present invention has the following beneficial effects:
[0027] The timestamp bit in the long type data of the present invention is written with the relative timestamp T 相对 , relative to the absolute timestamp T written 绝对 , saving more timestamp space. These saved spaces can be used to increase the number of sequence number bits, thereby increasing the number of unique IDs generated and improving the throughput of the unique ID generation system. Therefore, the high-throughput unique ID issuance method of the present invention is designed to improve the throughput of a single-machine snowflake algorithm while ensuring timing and performance.
[0028] The present invention uses the current absolute time stamp T 绝对 When issuing a unique ID according to the unique ID issuing method of this embodiment, the current absolute timestamp T 绝对 Once the unique IDs produced by calculation are issued, the next one or more absolute timestamps T 绝对 The corresponding unique ID produced to meet the current absolute timestamp T 绝对This solves the problem of unavailability of the numbering system due to the need to "wait for time to pass." However, it should be noted that the absolute timestamp after the auto-increment is no longer a timestamp in the ordinary sense. We have modified the time, violating the law of the natural passage of time. Therefore, the incremental unique ID issuance process of the present invention must meet the system's allowable timestamp error η. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] Figure 1 Process of a high-throughput unique ID issuance method according to an embodiment of the present invention Figure 1 ;
[0030] Figure 2 An example diagram of a long type data storage unique ID in a high-throughput unique ID issuance method according to an embodiment of the present invention;
[0031] Figure 3 Flow of a high-throughput unique ID issuance method according to an embodiment of the present invention Figure 2 . DETAILED DESCRIPTION
[0032] To make the purpose, technical solutions and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them.
[0033] Therefore, the following detailed description of the embodiments of the present invention is not intended to limit the scope of the claimed invention, but merely represents some embodiments of the present invention. All other embodiments derived by persons of ordinary skill in the art based on the embodiments of the present invention without creative effort shall fall within the scope of protection of the present invention.
[0034] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features and technical solutions therein may be combined with each other.
[0035] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, it does not need to be further defined or explained in subsequent drawings.
[0036] In the description of the present invention, it should be noted that the terms "upper" and "lower" and the like indicate orientations or positional relationships based on the orientations or positional relationships shown in the accompanying drawings, or the orientations or positional relationships in which the inventive product is typically placed when in use, or the orientations or positional relationships commonly understood by those skilled in the art. Such terms are intended solely to facilitate the description of the present invention and simplify the description, and are not intended to indicate or imply that the device or element referred to must have a specific orientation, be constructed, or operate in a specific orientation. Therefore, they should not be construed as limitations on the present invention. Furthermore, the terms "first" and "second" and the like are used solely for distinction and should not be construed as indicating or implying relative importance.
[0037] See also Figure 1 As shown, a high-throughput unique ID issuance method of this embodiment includes:
[0038] The unique ID is stored using long type data, including the highest bit for storing 0 or 1, a timestamp bit for storing a timestamp, an identification bit for storing a working machine ID, and a serial number bit for generating an incremental serial number;
[0039] Get the current absolute timestamp of the unique ID service host and the relative timestamp T through the formula 相对 = Current absolute timestamp T 绝对 -Base timestamp T0 obtains the relative timestamp of the unique ID service host, and the relative timestamp T 相对 Write the timestamp bit of the long type data to generate a unique ID.
[0040] In this embodiment, the timestamp bit of the long type data is written with the relative timestamp T 相对 , relative to the absolute timestamp T written 绝对 , saving more timestamp space. These saved spaces can be used to increase the number of sequence number bits, thereby increasing the number of unique IDs generated and improving the throughput of the unique ID generation system. Therefore, the high-throughput unique ID issuance method of this embodiment is designed to improve the throughput of a single-machine snowflake algorithm while ensuring timing and performance.
[0041] Since the timestamp bit of this embodiment is written as the relative timestamp T 相对 For relative timestamps, accuracy is less important than immediacy. Therefore, the high-throughput unique ID issuance method of this embodiment is suitable for distributed systems that require less stringent time accuracy than absolute timestamps. For example, when users want to know how long ago a post was published, they prefer to see a relative timestamp. This way, they don't have to mentally count down how long it has been since the event occurred.
[0042] The relative timestamp T in this embodiment相对 The calculation example is as follows:
[0043] Current absolute timestamp: 1641882286;
[0044] Base timestamp: 1641882200;
[0045] Current relative timestamp: 1641882286-1641882200=86.
[0046] The reference timestamp: 1641882200 is a system preset. As can be seen from the example, the relative timestamp 86 occupies significantly fewer bits in long type data storage than the absolute timestamp: 1641882286.
[0047] However, it's important to note that the first problem with using relative timestamps is that the time unit doesn't automatically change over time; only the leading digits change. For example, a website might display relative timestamps in minutes, hours, and days. However, after n days, the time unit doesn't change, while the leading digits increase to hundreds or thousands, significantly increasing the storage space required for absolute timestamps. Therefore, relative timestamps should adapt to different time lengths and choose the appropriate time unit accordingly. For example, after 30 days, months should be displayed, and after 12 months, years should be displayed. Sometimes, displaying relative timestamps can take up more space than you'd like. If you need to display them in a limited area—such as in content cards or mobile pages—use abbreviations for the time units: Seconds (s), Minutes (min), Hours (h), Days (d), Weeks (wk), Months (mo), Years (y).
[0048] As an optional implementation of this embodiment, in the high-throughput unique ID issuance method described in this embodiment, the number of bits of the timestamp bit is 时间 The number of bits of the identification bit is determined according to the time accuracy benchmark of the relative timestamp. 标识 The number of bits in the serial number is determined according to the maximum machine capacity of the system. 序列 The number of bits in the serial number is Bit 序列 =Total number of bits of long type data - Number of bits of timestamp 时间 -Number of bits for the flag bit 标识 -1 is calculated.
[0049] For absolute timestamps using millisecond-level time accuracy, to reduce timestamp bit usage, relative timestamps in this embodiment can use a lower time accuracy benchmark, optionally to the second level, while still ensuring that the distributed system's timestamp accuracy is met. Accordingly, the number of timestamp bits (bits) is less than or equal to 30.
[0050] As an optional implementation of this embodiment, see Figure 2 As shown, in the high-throughput unique ID issuance method described in this embodiment, the number of bits of the timestamp bit is Bit 时间 Control is 30 bits, the number of bits of the identification bit is Bit 标识 Control is 10 bits, the number of bits of the serial number Bit 序列 24 bits;
[0051] Each coroutine (or thread) splits the number segment [1, 16777216] that can be generated by the sequence number position into multiple caches and issues numbers concurrently.
[0052] Furthermore, the high-throughput unique ID issuance method of this embodiment can also solve the following technical problems:
[0053] For example, the current absolute timestamp is 1641882286, and the base timestamp is 1641882200. Because the request is too large, the number corresponding to the current absolute timestamp 1641882286 has been issued. The traditional approach is to "wait time to reach the next timestamp" before issuing a number. However, while "waiting time to pass", the system is equivalent to being unavailable.
[0054] In order to solve the above technical problems, see Figure 3 As shown, the high throughput unique ID issuance method described in this embodiment, when the unique ID service host is based on the current absolute timestamp T 绝对 Calculate the current relative timestamp T 相对 When the remaining number N of the corresponding unique ID number segment is 0, determine whether there are still working machines that need to be issued unique IDs;
[0055] If the result is yes, the incremental unique ID issuance process is executed:
[0056] The current absolute timestamp T of the unique ID service host 绝对 After the self-increment of n*T0, continue to issue unique IDs to the remaining working machines that need to be issued with the absolute timestamp T 绝对 +n*T0 is the unique ID in the unique ID segment corresponding to the relative timestamp;
[0057] Wherein n*T0 is incremented sequentially according to the minimum time accuracy benchmark, n is the number of increments, and n*T0 is less than or equal to the system allowable timestamp error η.
[0058] In this embodiment, the current absolute timestamp T 绝对 When issuing a unique ID according to the unique ID issuing method of this embodiment, the current absolute timestamp T 绝对 Once the unique IDs produced by calculation are issued, the next one or more absolute timestamps T 绝对 The corresponding unique ID produced to meet the current absolute timestamp T 绝对 The unique ID number issuance requirement is met, which solves the problem of the number issuance system being unavailable due to the need to "wait for time to pass".
[0059] However, it should be noted that since the absolute timestamp after self-increment is no longer a timestamp in the ordinary sense, we have modified the time, which violates the law of natural passage of time. Therefore, the incremental unique ID issuance process of this embodiment must meet the system's allowable timestamp error η.
[0060] Furthermore, in the high-throughput unique ID issuance method described in this embodiment, when the current absolute timestamp T of the unique ID service host is 绝对2 Updated to T 绝对1 +n*T0, the absolute timestamp T 绝对1 To occupy the current absolute timestamp T 绝对2 The unique ID of the service host is the current absolute timestamp of the unique ID. 绝对2 When the unique ID is issued, the actual number of the unique ID issued is equal to the current absolute timestamp T 绝对2 The theoretical number of issued numbers minus the absolute timestamp T 绝对1 Therefore, this embodiment assumes that the current absolute timestamp T 绝对2 , the traffic peak has passed, and the current absolute timestamp T occupied 绝对2 The calculated unique ID number has not been issued yet, the current absolute timestamp T 绝对2 You can continue to follow the current absolute timestamp T 绝对2 The calculated unique ID is used to issue the remaining numbers.
[0061] Because the high-throughput unique ID issuance method of this embodiment can generate unique IDs in the range [1, 16777, 216], covering nearly 99% of unique ID issuance requirements, the incremental unique ID issuance process of this embodiment is triggered only when the system faces an emergency, to address issuance bottlenecks in extreme situations. Although the timestamp of the unique ID issuance system may experience errors of seconds in extreme cases, it still ensures absolute high availability.
[0062] At the same time, in order to avoid the incremental unique ID numbering process affecting the subsequent absolute timestamp T 绝对 As an optional implementation of this embodiment, the current absolute timestamp T is preset. 绝对 The threshold N of the unique ID number that can occupy the future absolute timestamp during the incremental unique ID issuance process max , if the current absolute timestamp T 绝对 The number of unique IDs issued during the incremental unique ID issuance process reaches the number threshold N max Afterwards, if there are still working machines that need to be issued unique IDs, the working machines will be sorted and waited.
[0063] As an optional implementation of this embodiment, in the high-throughput unique ID issuance method described in this embodiment, if the current absolute timestamp T 绝对 It is necessary to execute the unique ID numbering process t times, and the current absolute timestamp T 绝对 Occupancy absolute timestamp T 绝对 +n1*T0 unique ID number N1, occupies absolute timestamp T 绝对 +n2*T0 unique ID number N2, ..., occupying absolute timestamp T 绝对 +n t *T0 unique ID number N t , the N1, N2, ..., N t The value of gradually decreases,
[0064] The current absolute timestamp T in this embodiment 绝对 If it is necessary to occupy the unique ID numbers calculated by the next multiple absolute timestamps, the number of occupied unique ID numbers should be gradually reduced, which matches the trend of the request peak parabola. 绝对 While meeting the number issuance requirements, avoid a subsequent absolute timestamp T 绝对 The number of unique IDs occupied is too large, resulting in the subsequent absolute timestamp T 绝对 The problem of not being able to meet the number issuance needs will be avoided, thus ensuring the efficiency and stability of the unique ID number issuance system.
[0065] At the same time, in order to avoid the frequent triggering of the incremental unique ID number issuance process, which may cause serious system timing errors, the high-throughput unique ID issuance method described in this embodiment monitors the total issuance quantity N increments in the incremental unique ID number issuance process. Within a preset time period, when the N increment reaches the preset incremental issuance quantity, the execution of the incremental unique ID number issuance process is prohibited.
[0066] Specifically, using the above embodiment as an example, the current absolute timestamp is 1641882286, and the reference timestamp is 1641882200. Because the request is too large, the number corresponding to the current absolute timestamp 1641882286 has been issued. The current absolute timestamp 1641882286 is incremented by +1s, and 1641882286 is incremented by +1s to become 1641882287. 1641882287 is used as the new absolute timestamp for unique ID issuance. When the time point 1641882287 is reached, it is found that the timestamp 1641882287 has been issued, so the timestamp is incremented by +1s to 1641882288. Assume that by the time point 1641882288, the traffic peak has passed, and the borrowed number 1641882288 has not been issued, the current number 1641882288 can continue to issue numbers according to the current time point 1641882288.
[0067] This embodiment also provides a high-throughput unique ID issuance device, including:
[0068] A data storage module, using long type data to store a unique ID, wherein the long type data includes a highest bit for storing 0 or 1, a timestamp bit for storing a timestamp, an identification bit for storing a working machine ID, and a serial number bit for generating an incremental serial number;
[0069] And the unique ID generation module obtains the current absolute timestamp of the unique ID service host and the relative timestamp T through the formula 相对 = Current absolute timestamp T 绝对 -Base timestamp T0 obtains the relative timestamp of the unique ID service host, and the relative timestamp T 相对 Write the timestamp bit of the long type data to generate a unique ID.
[0070] In this embodiment, the timestamp bit of the long type data stored in the data storage module is written with the relative timestamp T 相对 , relative to the absolute timestamp T written 绝对, saving more timestamp space. These saved spaces can be used to increase the number of sequence number bits, thereby increasing the number of unique IDs generated and improving the throughput of the unique ID generation system. Therefore, the high-throughput unique ID issuance device of this embodiment is designed to improve the throughput of a single-machine snowflake algorithm while ensuring timing and performance.
[0071] Since the timestamp of the data storage module in this embodiment is written into the relative timestamp T 相对 For relative timestamps, accuracy is less important than immediacy. Therefore, the high-throughput unique ID issuance device of this embodiment is suitable for distributed systems that require less stringent time accuracy than absolute timestamps. For example, when users want to know how long ago a post was published, they prefer to see a relative timestamp. This way, they don't have to mentally count down how long it has been since the event occurred.
[0072] The data storage module of this embodiment stores the relative timestamp T 相对 The calculation example is as follows:
[0073] Current absolute timestamp: 1641882286;
[0074] Base timestamp: 1641882200;
[0075] Current relative timestamp: 1641882286-1641882200=86.
[0076] The reference timestamp: 1641882200 is a system preset. As can be seen from the example, the relative timestamp 86 occupies significantly fewer bits in long type data storage than the absolute timestamp: 1641882286.
[0077] However, it's important to note that the first problem with data storage modules storing relative timestamps is that the time unit doesn't automatically change over time; only the leading digits change. For example, a website might display relative timestamps in minutes, hours, and days. However, after n days, the time unit doesn't change, while the leading digits increase to hundreds or thousands, significantly increasing the storage space required for absolute timestamps. Therefore, data storage modules should adapt relative timestamps to different time lengths and choose the appropriate time unit accordingly. For example, after 30 days, months should be displayed, and after 12 months, years should be displayed. Sometimes, displaying relative timestamps can take up more space than you'd like. If you need to display them in a limited area—such as in content cards or mobile pages—use abbreviations for the time units: Seconds (s), Minutes (min), Hours (h), Days (d), Weeks (wk), Months (mo), Years (y).
[0078] As an optional implementation of this embodiment, in the high-throughput unique ID issuing device described in this embodiment, the number of bits of the timestamp bits stored in the data storage module is 时间 The number of bits of the identification bit stored in the data storage module is determined according to the time accuracy benchmark of the relative timestamp. 标识 The number of bits of the serial number stored in the data storage module is determined according to the maximum machine capacity of the system. 序列 The number of bits in the serial number is Bit 序列 =Total number of bits of long type data - Number of bits of timestamp 时间 -Number of bits for the flag bit 标识 -1 is calculated.
[0079] For absolute timestamps using millisecond-level time accuracy, to reduce timestamp bit usage, while ensuring that the distributed system's timestamp accuracy is met, the data storage module in this embodiment can store relative timestamps at a lower time accuracy. Optionally, the time accuracy is at the second level. Accordingly, the number of timestamp bits is less than or equal to 30.
[0080] As an optional implementation of this embodiment, in the high-throughput unique ID issuing device described in this embodiment, the data storage module stores the number of bits of the timestamp bit Bit 时间 Control is 30 bits, the number of bits of the identification bit is Bit 标识 Control is 10 bits, the number of bits of the serial number Bit 序列 24 bits;
[0081] Each coroutine (or thread) splits the number segment [1, 16777216] that can be generated by the sequence number position into multiple caches and issues numbers concurrently.
[0082] Furthermore, the high-throughput unique ID issuance device of this embodiment can also solve the following technical problems:
[0083] For example, the current absolute timestamp is 1641882286, and the base timestamp is 1641882200. Because the request is too large, the number corresponding to the current absolute timestamp 1641882286 has been issued. The traditional approach is to "wait time to reach the next timestamp" before issuing a number. However, while "waiting time to pass", the system is equivalent to being unavailable.
[0084] In order to solve the above technical problems, a high-throughput unique ID issuance device described in this embodiment includes an incremental unique ID issuance module and a judgment and control module:
[0085] When the unique ID service host is determined by the current absolute timestamp T 绝对 Calculate the current relative timestamp T 相对 When the remaining issuance quantity N of the corresponding unique ID number segment is 0, the control module determines whether there are still working machines that need to be issued unique IDs;
[0086] If the result of the judgment is yes, the incremental unique ID issuing module executes the incremental unique ID issuing process:
[0087] The current absolute timestamp T of the unique ID service host 绝对 After the self-increment of n*T0, continue to issue unique IDs to the remaining working machines that need to be issued with the absolute timestamp T 绝对 +n*T0 is the unique ID in the unique ID segment corresponding to the relative timestamp;
[0088] Wherein n*T0 is incremented sequentially according to the minimum time accuracy benchmark, n is the number of increments, and n*T0 is less than or equal to the system allowable timestamp error η.
[0089] In this embodiment, the current absolute timestamp T 绝对 When issuing a unique ID, the current absolute timestamp T 绝对 Once the unique IDs generated by calculation are issued, the incremental unique ID issuing module will occupy the next one or more absolute timestamps T 绝对 The corresponding unique ID produced to meet the current absolute timestamp T 绝对 The unique ID number issuance requirement is met, which solves the problem of the number issuance system being unavailable due to the need to "wait for time to pass".
[0090] However, it should be noted that since the absolute timestamp after self-increment is no longer a timestamp in the ordinary sense, we have modified the time, which violates the law of natural passage of time. Therefore, the incremental unique ID issuance process of this embodiment must meet the system's allowable timestamp error η.
[0091] Furthermore, the incremental unique ID issuing module of this embodiment, when the current absolute timestamp T of the unique ID service host 绝对2 Updated to T 绝对1 +n*T0, the absolute timestamp T 绝对1 To occupy the current absolute timestamp T 绝对2 The unique ID of the service host is the current absolute timestamp of the unique ID. 绝对2 When the unique ID is issued, the actual number of the unique ID issued is equal to the current absolute timestamp T 绝对2 The theoretical number of issued numbers minus the absolute timestamp T 绝对1 Therefore, this embodiment assumes that the current absolute timestamp T 绝对2 , the traffic peak has passed, and the current absolute timestamp T occupied 绝对2 The calculated unique ID number has not been issued yet, the current absolute timestamp T 绝对2 You can continue to follow the current absolute timestamp T 绝对2 The calculated unique ID is used to issue the remaining numbers.
[0092] Because this embodiment can generate unique IDs in the range [1, 16777, 216], it covers nearly 99% of unique ID issuance requirements. To address bottlenecks in extreme situations, the incremental unique ID issuance module in this embodiment triggers the incremental unique ID issuance process only when the system faces an emergency. Although the timestamp of the unique ID issuance system may experience errors of seconds in extreme cases, it still ensures absolute high availability.
[0093] At the same time, in order to avoid the incremental unique ID issuing module executing the incremental unique ID issuing process to the subsequent absolute timestamp T 绝对 As an optional implementation of this embodiment, the current absolute timestamp T is preset. 绝对 The threshold N of the unique ID number that can occupy the future absolute timestamp during the incremental unique ID issuance process max , if the current absolute timestamp T 绝对 The number of unique IDs issued during the incremental unique ID issuance process reaches the number threshold N max Afterwards, if there are still working machines that need to be issued unique IDs, the working machines will be sorted and waited.
[0094] As an optional implementation of this embodiment, the incremental unique ID issuing module of this embodiment executes the incremental unique ID issuing process. If the current absolute timestamp T 绝对 It is necessary to execute the unique ID numbering process t times, and the current absolute timestamp T 绝对 Occupancy absolute timestamp T 绝对 +n1*T0 unique ID number N1, occupies absolute timestamp T 绝对 +n2*T0 unique ID number N2, ..., occupying absolute timestamp T 绝对 +n t *T0 unique ID number N t , the N1, N2, ..., N t The value of gradually decreases,
[0095] The current absolute timestamp T in this embodiment 绝对 If it is necessary to occupy the unique ID numbers calculated by the next multiple absolute timestamps, the number of occupied unique ID numbers should be gradually reduced, which matches the trend of the request peak parabola. 绝对 While meeting the number issuance requirements, avoid a subsequent absolute timestamp T 绝对 The number of unique IDs occupied is too large, resulting in the subsequent absolute timestamp T 绝对 The problem of not being able to meet the number issuance needs will be avoided, thus ensuring the efficiency and stability of the unique ID number issuance system.
[0096] At the same time, to prevent the incremental unique ID issuance process from being frequently triggered and causing serious system timing errors, the incremental unique ID issuance module of this embodiment monitors the total number of issued IDs, N increments, during the incremental unique ID issuance process. When N increments reach the preset incremental number within a preset time period, the incremental unique ID issuance process is prohibited. This embodiment also provides a storage medium storing a computer executable program, characterized in that when the computer executable program is executed, it implements the high-throughput unique ID issuance method described above.
[0097] The storage medium described in this embodiment may include a data signal propagated in baseband or as part of a carrier wave, which carries a readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. The readable storage medium may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, device, or component. The program code contained on the readable storage medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination thereof.
[0098] This embodiment further provides an electronic device, including a processor and a memory, wherein the memory is used to store a computer executable program. When the computer program is executed by the processor, the processor executes the high-throughput unique ID issuance method.
[0099] The electronic device is implemented as a general-purpose computing device. The processor may be one or multiple processors operating in concert. The present invention also does not exclude distributed processing, meaning the processors may be dispersed across different physical devices. The electronic device of the present invention is not limited to a single entity but may also be the sum of multiple physical devices.
[0100] The memory stores a computer executable program, typically a machine-readable code, which can be executed by the processor to enable the electronic device to perform the method of the present invention, or at least some of the steps in the method.
[0101] The memory includes a volatile memory, such as a random access memory unit (RAM) and / or a cache memory unit, and may also be a non-volatile memory, such as a read-only memory unit (ROM).
[0102] It should be understood that the electronic devices of the present invention may also include elements or components not shown in the above examples. For example, some electronic devices also include display units such as screens, and some electronic devices also include human-computer interaction elements such as buttons and keyboards. As long as the electronic device can execute a computer-readable program stored in its memory to implement the method of the present invention or at least some of the steps of the method, it is considered an electronic device covered by the present invention.
[0103] Through the above description of the implementation mode, it is easy for those skilled in the art to understand that the present invention can be implemented by hardware capable of executing a specific computer program, such as the system of the present invention, and the electronic processing unit, server, client, mobile phone, control unit, processor, etc. contained in the system. The present invention can also be implemented by computer software that executes the method of the present invention, such as control software executed by a microprocessor, an electronic control unit, a client, a server, etc. However, it should be noted that the computer software that executes the method of the present invention is not limited to being executed by one or a specific hardware entity, and it can also be implemented in a distributed manner by unspecified specific hardware. For computer software, the software product can be stored in a computer-readable storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.), or it can be distributed and stored on a network, as long as it enables an electronic device to execute the method according to the present invention.
[0104] The above embodiments are only used to illustrate the present invention and are not intended to limit the technical solutions described in the present invention. Although this specification has described the present invention in detail with reference to the above embodiments, the present invention is not limited to the above specific implementation methods. Therefore, any modification or equivalent replacement of the present invention; and all technical solutions and improvements thereof that do not depart from the spirit and scope of the invention are included in the scope of the claims of the present invention.
Claims
1. A high-throughput unique ID issuance method, characterized in that: include: The unique ID is stored using long type data, including the highest bit for storing 0 or 1, a timestamp bit for storing a timestamp, an identification bit for storing a working machine ID, and a serial number bit for generating an incremental serial number; Get the current absolute timestamp of the unique ID service host and the relative timestamp T through the formula 相对 = Current absolute timestamp T 绝对 - The reference timestamp T0 obtains the relative timestamp of the unique ID service host, and writes the relative timestamp T into the timestamp bit of the long type data to generate a unique ID; When the unique ID service host is determined by the current absolute timestamp T 绝对 Calculate the current relative timestamp T 相对 When the remaining number N of the corresponding unique ID number segment is 0, determine whether there are still working machines that need to be issued unique IDs; If the result is yes, the incremental unique ID issuance process is executed: The current absolute timestamp T of the unique ID service host 绝对 After the self-increment of n*T0, continue to issue unique IDs to the remaining working machines that need to be issued with the absolute timestamp T 绝对 +n*T0 is the unique ID in the unique ID segment corresponding to the relative timestamp calculated; where n*T0 is incremented sequentially according to the minimum time accuracy benchmark, n is the number of increments, and the n*T0 is less than or equal to the system's allowable timestamp error η.
2. A high-throughput unique ID issuance method according to claim 1, characterized in that: The number of bits of the timestamp bit 时间 The number of bits of the identification bit is determined according to the time accuracy benchmark of the relative timestamp. 标识 The number of digits in the serial number is determined by the formula: the number of digits in the serial number = the total number of digits in the long type data - the number of digits in the timestamp. 时间 -Number of bits for the flag bit 标识 -1 is calculated.
3. A high-throughput unique ID issuance method according to claim 2, characterized in that: The time accuracy standard is at the second level, and the number of bits of the timestamp bit is less than or equal to 30 bits.
4. A high-throughput unique ID issuance method according to claim 2, characterized in that: The number of bits of the timestamp bit 时间 Control is 30 bits, the number of bits of the identification bit is Bit 标识 Control is 10 bits, the number of bits of the serial number Bit 序列 24 bits; Each coroutine splits the number segment [1,16777216] that can be generated by the sequence number position into multiple buffers and issues numbers concurrently.
5. The high-throughput unique ID issuance method according to claim 1, characterized in that: When the unique ID serves the host's current absolute timestamp T 绝对2 Updated to T 绝对1 +n*T0, the absolute timestamp T 绝对1 To occupy the current absolute timestamp T 绝对2 The unique ID of the service host is the current absolute timestamp of the unique ID. 绝对2 When the unique ID is issued, the actual number of the unique ID issued is equal to the current absolute timestamp T 绝对2 The theoretical number of issued numbers minus the absolute timestamp T 绝对1 The number of occupied numbers.
6. A high-throughput unique ID issuance method according to claim 1, characterized in that: Preset current absolute timestamp T 绝对 The threshold N of the unique ID number that can occupy the future absolute timestamp during the incremental unique ID issuance process max , if the current absolute timestamp T 绝对 The number of unique IDs issued during the incremental unique ID issuance process reaches the number threshold N max Afterwards, if there are still working machines that need to be issued unique IDs, the working machines will be sorted and waited.
7. A high-throughput unique ID issuance method according to claim 6, characterized in that: If the current absolute timestamp T 绝对 It is necessary to execute the unique ID numbering process t times, and the current absolute timestamp T 绝对 Occupancy absolute timestamp T 绝对 +n1*T0 unique ID number N1, occupies absolute timestamp T 绝对 +n2*T0 unique ID number N2, ..., occupying absolute timestamp T 绝对 +n t *T0 unique ID number N t , the N1, N2, ..., N t The value of decreases gradually.
8. The high-throughput unique ID issuance method according to claim 1, characterized in that: The total number N increment of the incremental unique ID number issuance process is monitored. Within a preset time period, when the N increment reaches a preset incremental number issuance amount, the incremental unique ID number issuance process is prohibited.
9. A high-throughput unique ID issuance device, characterized in that: include: A data storage module, using long type data to store a unique ID, wherein the long type data includes a highest bit for storing 0 or 1, a timestamp bit for storing a timestamp, an identification bit for storing a working machine ID, and a serial number bit for generating an incremental serial number; And the unique ID generation module obtains the current absolute timestamp of the unique ID service host and the relative timestamp T through the formula 相对 = Current absolute timestamp T 绝对 - The reference timestamp T0 obtains the relative timestamp of the unique ID service host, and writes the relative timestamp T into the timestamp bit of the long type data to generate a unique ID; A high-throughput unique ID issuing device includes an incremental unique ID issuing module and a judgment control module: When the unique ID service host is determined by the current absolute timestamp T 绝 Calculate the current relative timestamp T 相对 When the remaining issuance quantity N of the corresponding unique ID number segment is 0, the control module determines whether there are still working machines that need to be issued unique IDs; If the result of the judgment is yes, the incremental unique ID issuing module executes the incremental unique ID issuing process: The current absolute timestamp T of the unique ID service host 绝对 After the self-increment of n*T0, continue to issue unique IDs to the remaining working machines that need to be issued with the absolute timestamp T 绝对 +n*T0 is the unique ID in the unique ID segment corresponding to the relative timestamp; Wherein n*T0 is incremented sequentially according to the minimum time accuracy benchmark, n is the number of increments, and n*T0 is less than or equal to the system allowable timestamp error η.
10. A storage medium storing a computer executable program, characterized in that: When the computer executable program is executed, a high-throughput unique ID issuance method according to any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Method and apparatus for generating global unique ID
CN109309736A