Distributed ID generation method, device and electronic device for dealing with burst traffic
By caching the distributed ID generation factors within the preset time period and selecting them in sequence, the large resource consumption problem caused by burst traffic in the existing technology is solved, efficient distributed ID generation is achieved, and server resources are saved.
Patent Information
- Application Number
- CN202211491245.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-25
- Publication Date
- 2025-02-07
- Estimated Expiration
- 2042-11-25
AI Technical Summary
When processing burst traffic, the prior art distributes traffic by expanding distributed ID service instances in advance, resulting in high resource consumption and it is difficult to accurately predict burst traffic time.
By obtaining multiple distributed ID generation factors generated within the preset time period and cache them in an ordered queue, when receiving burst traffic requests, selecting the corresponding number of ID generation factors corresponding to the sequence number from the queue in sequence , generate a distributed ID.
This method can effectively deal with burst traffic, save server deployment resources, and avoid resource waste caused by capacity expansion.
Smart Images

Figure CN115865818B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of network communication technology, and in particular to a distributed ID generation method, device and electronic equipment for dealing with burst traffic. Background Art
[0002] In distributed systems, in order to identify a large amount of data and messages (user, product, and other IDs), distributed ID generation services have emerged. Currently, one of the solutions is a distributed ID generation method based on the snowflake algorithm. When the service receives an ID generation request, it obtains a distributed ID based on the current system timestamp, current machine number, and serial number. Under normal circumstances, 4096 IDs can be generated in one millisecond. When there are product promotions, distributed ID clients are restarted in batches, etc., a distributed ID service may receive more than 4096 distributed ID requests in the same millisecond. In the prior art, by estimating the distributed ID burst traffic time in advance, the distributed ID service instance is expanded in advance, and more service instances are used to spread the burst traffic, resulting in large resource consumption. Summary of the invention
[0003] The purpose of the present invention is to provide a distributed ID generation method, device and electronic device for dealing with burst traffic, so as to save server deployment resources.
[0004] The present invention provides a distributed ID generation method for dealing with burst traffic, which is applied to a server; the method comprises:
[0005] Obtain multiple distributed ID generation factors generated within a preset time period; wherein each distributed ID generation factor includes: a timestamp, a machine number corresponding to the server, a start sequence number, and an end sequence number;
[0006] Cache multiple distributed ID generation factors into an ordered queue;
[0007] Receive multiple distributed ID generation requests corresponding to burst traffic;
[0008] According to the number of multiple distributed ID generation requests, ID generation factors corresponding to the same number of serial numbers are selected in sequence from the ordered queue to generate a distributed ID corresponding to each distributed ID generation request.
[0009] Furthermore, the preset time period includes multiple timestamps corresponding to multiple time points respectively, and the step of obtaining multiple distributed ID generation factors generated within the preset time period includes:
[0010] Based on each timestamp, the machine number corresponding to the server, the starting sequence number and the ending sequence number, multiple distributed ID generation factors are generated; wherein the number of distributed ID generation factors is the same as the number of time points.
[0011] Furthermore, the step of caching multiple distributed ID generation factors into an ordered queue includes:
[0012] According to the chronological order of the time points corresponding to the multiple timestamps, the multiple distributed ID generation factors are sequentially cached into an ordered queue.
[0013] Furthermore, the method also includes:
[0014] Get the total number of distributed IDs currently cached in the ordered queue;
[0015] Based on the preset server processing peak rate and the preset time period, the target number of distributed IDs is obtained; and whether the total number of distributed IDs is greater than the target number of distributed IDs is determined;
[0016] If the total number of distributed IDs is greater than the target number of distributed IDs, remove the first distributed ID generation factor in the ordered queue and update the total number of distributed IDs;
[0017] The updated total number of distributed IDs is used as the new total number of distributed IDs currently cached, and the step of determining whether the total number of distributed IDs is greater than the target number of distributed IDs is repeated until the total number of distributed IDs is less than or equal to the target number of distributed IDs.
[0018] Further, according to the number of the plurality of distributed ID generation requests, the step of selecting the ID generation factors corresponding to the same number of serial numbers from the ordered queue in order to generate a distributed ID corresponding to each distributed ID generation request includes:
[0019] Based on the starting sequence number and the ending sequence number of each distributed ID generation factor, the number of sequence numbers of each distributed ID generation factor is obtained;
[0020] According to the number of the multiple distributed ID generation requests, sequentially select the same number of sequence numbers as the number of the distributed ID generation requests from the ordered queue to obtain multiple first sequence numbers;
[0021] Based on the multiple first serial numbers, a distributed ID corresponding to each distributed ID generation request is generated.
[0022] Further, according to the number of the multiple distributed ID generation requests, the step of selecting the same number of sequence numbers as the number of the distributed ID generation requests from the ordered queue in order to obtain the multiple first sequence numbers includes:
[0023] According to the number of multiple distributed ID generation requests, select the same number of sequence numbers as the number of distributed ID generation requests from the number of sequence numbers of the first distributed ID generation factor in the ordered queue;
[0024] If the number of serial numbers of the first distributed ID generation factor is less than the number of distributed ID generation requests, continue to select the number of serial numbers of the second distributed ID generation factor from the ordered queue to obtain multiple first serial numbers that are the same as the number of distributed ID generation requests.
[0025] The present invention provides a distributed ID generation device for dealing with burst traffic, the device is arranged on a server; the device comprises:
[0026] An acquisition module is used to acquire multiple distributed ID generation factors generated within a preset time period; wherein each distributed ID generation factor includes: a timestamp, a machine number corresponding to the server, a start sequence number, and an end sequence number;
[0027] A cache module, used to cache multiple distributed ID generation factors into an ordered queue;
[0028] A receiving module, used for receiving multiple distributed ID generation requests corresponding to burst traffic;
[0029] The generation module is used to select ID generation factors corresponding to the same number of serial numbers from the ordered queue in order according to the number of multiple distributed ID generation requests, so as to generate a distributed ID corresponding to each distributed ID generation request.
[0030] Furthermore, the preset time period includes multiple timestamps corresponding to multiple time points respectively, and the acquisition module is further used to:
[0031] Based on each timestamp, the machine number corresponding to the server, the starting sequence number and the ending sequence number, multiple distributed ID generation factors are generated; wherein the number of distributed ID generation factors is the same as the number of time points.
[0032] An electronic device provided by the present invention includes a processor and a memory, wherein the memory stores machine executable instructions that can be executed by the processor, and the processor executes the machine executable instructions to implement the above method.
[0033] The present invention provides a computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the above method.
[0034] The present invention provides a distributed ID generation method, device and electronic device for dealing with burst traffic, the method is applied to a server; it includes: obtaining multiple distributed ID generation factors generated within a preset time period; caching the multiple distributed ID generation factors into an ordered queue; receiving multiple distributed ID generation requests corresponding to the burst traffic; according to the number of multiple distributed ID generation requests, sequentially selecting ID generation factors corresponding to the same number of serial numbers from the ordered queue to generate a distributed ID corresponding to each distributed ID generation request. In this way, by caching multiple distributed ID generation factors generated within a preset time period into an ordered queue; according to the number of multiple distributed ID generation requests, sequentially selecting ID generation factors corresponding to the same number of serial numbers from the ordered queue to generate a distributed ID corresponding to each distributed ID generation request, server deployment resources can be saved. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0036] Figure 1 A schematic diagram of distributed ID generation provided by an embodiment of the present invention;
[0037] Figure 2 A flow chart of a distributed ID generation method for dealing with burst traffic provided by an embodiment of the present invention;
[0038] Figure 3 A schematic diagram of generating a distributed ID generation factor provided by an embodiment of the present invention;
[0039] Figure 4 A flowchart of another distributed ID generation method for dealing with burst traffic provided by an embodiment of the present invention;
[0040] Figure 5 A schematic diagram of the structure of a distributed ID generation device for dealing with burst traffic provided by an embodiment of the present invention;
[0041] Figure 6 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0042] The technical solution of the present invention will be clearly and completely described below in conjunction with the embodiments. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0043] In order to identify a large amount of data and messages (user, product, etc. ID) in a distributed system, a distributed ID generation service has emerged. Currently, one of the solutions is a distributed ID generation method based on the snowflake algorithm. For details, please refer to Figure 1 The diagram of distributed ID generation shown in the figure shows that when the service receives an ID generation request, it converts the three values of the current system timestamp, the current machine number, and the serial number into corresponding binary strings, concatenates them front and back, and then concatenates 0 at the front to obtain a 64-bit binary string, which is then converted into decimal to obtain a 19-digit decimal number, i.e., a distributed ID.
[0044] Generally speaking, 4096 IDs can be generated in one millisecond through this method. When there are product promotions, distributed ID clients are restarted in batches, etc., a distributed ID service may receive more than 4096 distributed ID requests in the same millisecond, and we will not be able to continue to generate corresponding IDs. However, this situation where a large number of distributed IDs are required is small and short-lived, so we urgently need a way to handle distributed ID burst traffic to deal with similar situations.
[0045] In the prior art, when dealing with similar situations, the distributed ID burst traffic time is usually estimated in advance, the distributed ID service instance is expanded in advance, and more service instances are used to spread the burst traffic. This method is difficult to accurately predict the burst traffic time and expand the capacity accordingly; it consumes a lot of resources; because the maximum number of machine numbers can be 2 to the power of 10, that is, 1024, there is an upper limit to the expansion.
[0046] To facilitate understanding of this embodiment, firstly, a distributed ID generation method for dealing with burst traffic disclosed in an embodiment of the present invention is described in detail. The method is applied to a server, such as Figure 2 As shown, the method comprises the following steps:
[0047] Step S102, obtaining multiple distributed ID generation factors generated within a preset time period; wherein each distributed ID generation factor includes: a timestamp, a machine number corresponding to the server, a start sequence number, and an end sequence number.
[0048] The above server is usually a computer software that manages resources and provides services to users. It has the ability to undertake and guarantee services. Generally speaking, the server needs to respond to service requests and process them. Many important data are stored on the server, and many network services are run on the server. The above distributed ID can be understood as a unique identifier that distinguishes a large amount of data and messages in a distributed system.
[0049] It is generally believed that a distributed system is a collection of independent computers. The distributed system can select the most suitable computer in the system according to the needs, submit the user's job to the server corresponding to the computer, and pass the result to the user after the job is completed. In this process, the user does not realize the existence of multiple computers. The system is like a single computer.
[0050] In the specific implementation process, each computer in the distributed system has a corresponding number to distinguish different computers. In addition, each computer also has a corresponding server to process corresponding user services. Therefore, the machine number corresponding to the above server is equivalent to the number of the computer corresponding to the server.
[0051] The above-mentioned preset time period can be understood as a period of time in the past, and the time unit is usually milliseconds; for convenience, the above-mentioned distributed ID generation factor can be expressed as: ID_DIVISOR (t: timestamp, w: machine number, s: start sequence number, e: end sequence number); wherein ID_DIVISOR represents the distributed ID generation factor; t (TIMESTAMP_NOW) represents the timestamp, corresponding to the current system time; w (WORK_ID) represents the machine number, and usually the WORK_ID of the same distributed ID server is fixed; s (START_ID) represents the start sequence number, and the value range can be [0~4095]; e (END_ID) represents the end sequence number, and the value range can be [START_ID~4095]. For details, please refer to the following. Figure 3 A schematic diagram of generating a distributed ID generation factor is shown; a distributed ID generation factor can be generated based on the three values of the current system timestamp, the current machine number, and the serial number, and then concatenating 0 at the front.
[0052] In actual implementation, each timestamp can be regarded as one millisecond, and one distributed ID generation factor can be generated every millisecond. Each distributed ID generation factor can have a maximum of 4096 serial numbers and can generate 4096 distributed IDs. Therefore, the number of distributed ID generation factors can be obtained according to the preset time period in milliseconds. For example, if the preset time period is 5 milliseconds, 5 distributed ID generation factors generated within 5 milliseconds can be obtained.
[0053] Step S104, cache multiple distributed ID generation factors into an ordered queue.
[0054] For the convenience of representation, the above-mentioned ordered queue is generally referred to as QUEUE_DIVISOR. In the specific implementation process, multiple distributed ID generation factors in the past time period can be obtained periodically. Specifically, when the distributed ID service is started, a scheduled task can be set to perform ID generation factor caching and cleaning every X milliseconds (such as: 5 milliseconds). Therefore, the 5 distributed ID generation factors obtained within these 5 milliseconds can be cached in an ordered queue in chronological order every 5 milliseconds.
[0055] Step S106: receiving multiple distributed ID generation requests corresponding to burst traffic.
[0056] In actual implementation, burst traffic is usually short-lived and does not occur often, while normal traffic is more common in life and work. In addition to receiving multiple distributed ID generation requests corresponding to burst traffic, this application can also receive multiple distributed ID generation requests corresponding to normal traffic when normal traffic is generated, and then select ID generation factors corresponding to the same sequence number as the number of normal traffic distributed ID generation requests from the ordered queue in the order of cache, and generate the same number of distributed IDs. Therefore, the technical features of this application can not only cope with burst traffic but also cope with normal traffic.
[0057] Step S108, according to the number of multiple distributed ID generation requests, select ID generation factors corresponding to the same number of serial numbers from the ordered queue in order to generate a distributed ID corresponding to each distributed ID generation request.
[0058] In the specific implementation process, facing sudden traffic in situations such as product promotions and holiday activities, a large number of distributed ID generation requests are generally generated. When the server receives a large number of ID generation requests, it can select ID generation factors corresponding to the same serial numbers as the number of distributed ID generation requests from the ordered queue in the order of cache to generate the same number of distributed IDs.
[0059] Specifically, assuming that the number of distributed ID generation requests corresponding to the burst traffic is 5000, the distributed ID generation factor corresponding to the earliest timestamp can be selected from all the distributed ID generation factors in the ordered queue. Since the number of sequence numbers in each distributed ID generation factor can be at most 4096 (it should be noted that the number of sequence numbers in each distributed ID generation factor is not fixed to 4096, because it is possible that before the burst traffic arrives, some of the sequence numbers have been occupied by multiple distributed ID generation requests corresponding to other traffic, to generate the distributed IDs corresponding to the multiple distributed ID generation requests corresponding to these other traffic. D. For example, if the number of multiple distributed ID generation requests corresponding to other traffic is 5, the number of serial numbers in the distributed ID generation factor is 4091. Therefore, the maximum number of serial numbers in each distributed ID generation factor can be 4096, that is, the corresponding part of the serial numbers is not occupied by other traffic. Therefore, it is necessary to continue to select the distributed ID generation factor corresponding to the second earliest timestamp until the total number of serial numbers in all selected distributed ID generation factors is greater than or equal to 5000. Then, 5000 distributed IDs are generated based on these 5000 serial numbers and the timestamps and machine numbers corresponding to these 5000 serial numbers.
[0060] The above-mentioned distributed ID generation method for dealing with burst traffic is applied to a server; it includes: obtaining multiple distributed ID generation factors generated within a preset time period; caching the multiple distributed ID generation factors into an ordered queue; receiving multiple distributed ID generation requests corresponding to burst traffic; and selecting the ID generation factors corresponding to the same number of serial numbers from the ordered queue in order according to the number of multiple distributed ID generation requests to generate a distributed ID corresponding to each distributed ID generation request. This method can save server deployment resources by caching the multiple distributed ID generation factors generated within a preset time period into an ordered queue; and selecting the ID generation factors corresponding to the same number of serial numbers from the ordered queue in order according to the number of multiple distributed ID generation requests to generate a distributed ID corresponding to each distributed ID generation request.
[0061] The embodiment of the present invention also provides another distributed ID generation method for dealing with burst traffic, which is implemented on the basis of the above embodiment method; the preset time period includes multiple timestamps corresponding to multiple time points, such as Figure 4 As shown, the method comprises the following steps:
[0062] Step S202, based on each timestamp, the machine number corresponding to the server, the starting sequence number and the ending sequence number, generate multiple distributed ID generation factors; wherein the number of distributed ID generation factors is the same as the number of time points.
[0063] In a specific implementation process, the preset time period includes multiple time stamps corresponding to multiple time points, wherein a time point represents a specific time, and a difference of one millisecond between every two time points, and therefore a difference of one millisecond between every two time stamps.
[0064] Usually the system time (in milliseconds) is expressed as TIMESTAMP. The current system time corresponds to the current timestamp (TIMESTAMP_NOW). In addition, there is a timestamp in the system that records the last (preset time period) ID factor generation (the system time corresponding to the last ID factor generation), called LAST_TIMESTAMP, the first being the server startup time. Then in the same timestamp, there will be a variable that records the sequence number, called SEQUENCE_ID. SEQUENCE_ID increases in the same millisecond and resets to 0 in the next millisecond.
[0065] Step S204, caching the multiple distributed ID generation factors in sequence into an ordered queue according to the chronological order of the time points corresponding to the multiple timestamps.
[0066] In the specific implementation process, if TIMESTAMP_NOW<=LAST_TIMESTAMP, no processing is performed; if TIMESTAMP_NOW>LAST_TIMESTAMP, the difference between TIMESTAMP_NOW and LAST_TIMESTAMP (equivalent to the above preset time period) is calculated. Assuming that the difference is Y, then Y distributed ID generation factors will be generated this time (current preset time period), which are as follows:
[0067] ID_DIVISOR(t:LAST_TIMESTAMP+1,w:WORK_ID,s:SEQUENCE_ID,e:4095);
[0068] ID_DIVISOR(t:LAST_TIMESTAMP+2,w:WORK_ID,s:0,e:4095); ...
[0069] ID_DIVISOR(t:LAST_TIMESTAMP+Y,w:WORK_ID,s:0,e:4095)
[0070] The above Y ID generation factors are added to the QUEUE_DIVISOR queue in ascending order according to their corresponding timestamps. The queue has a variable ID_TOTAL_NUM (starting at 0) that records the total number of IDs in the QUEUE_DIVISOR queue. After the above Y ID generation factors are added to the queue, ID_TOTAL_NUM is updated to ID_TOTAL_NUM+4096-SEQUENCE_ID+4096*(Y-1) at the same time, and the LAST_TIMESTAMP value is updated to MESTAMP_NOW (equal to LAST_TIMESTAMP+Y).
[0071] Step S206: receiving multiple distributed ID generation requests corresponding to burst traffic.
[0072] Step S208, based on the starting sequence number and the ending sequence number of each distributed ID generation factor, obtain the number of sequence numbers of each distributed ID generation factor.
[0073] In the specific implementation process, the number of serial numbers of each distributed ID generation factor can be obtained by calculating the difference between the end serial number and the start serial number of the distributed ID generation factor and then adding 1. For example, a distributed ID generation factor is: ID_DIVISOR(t:LAST_TIMESTAMP+2,w:WORK_ID,s:0,e:4095); then the number of serial numbers of the distributed ID generation factor is 4096 (4095-0+1=4096).
[0074] Step S210: According to the number of multiple distributed ID generation requests, a number of sequence numbers that is the same as the number of distributed ID generation requests is selected from the ordered queue in order to obtain multiple first sequence numbers.
[0075] When QUEUE_DIVISOR is not empty, you can get the head element of the QUEUE_DIVISOR queue (the first distributed ID generation factor), generate an ID, and update the ID_TOTAL_NUM value. If there are still serial numbers in the factor after the ID generation, continue to keep the factor in the queue. If all the serial numbers in the factor are used up, remove the factor from the queue, continue to get the head element of the QUEUE_DIVISOR queue (the second distributed ID generation factor), generate an ID, and update the ID_TOTAL_NUM value.
[0076] Specifically, the above step S210 can be implemented by following the steps 1 to 2:
[0077] Step 1: According to the number of multiple distributed ID generation requests, select the same number of sequence numbers as the number of distributed ID generation requests from the number of sequence numbers of the first distributed ID generation factor in the ordered queue.
[0078] In the specific implementation process, if the number of distributed ID generation requests is less than the number of serial numbers of the first distributed ID generation factor, specifically assuming that the number of distributed ID generation requests is 1000, and the first distributed ID generation factor is: ID_DIVISOR(t:LAST_TIMESTAMP+1,w:WORK_ID,s:100,e:4095 (it can be seen that the starting serial number of the distributed ID generation factor is 100 instead of 0. This is because serial numbers 0-99 have been used and the corresponding 100 distributed IDs have been generated), then the number of serial numbers of the distributed ID generation factor is 3996. At this time, the number of distributed ID generation requests (1000) is less than the number of serial numbers of the first distributed ID generation factor (3996). The first 1000 serial numbers (corresponding to serial numbers 100-1099) can be directly selected from these 3996 serial numbers to obtain 1000 first serial numbers.
[0079] Step 2: If the number of serial numbers of the first distributed ID generation factor is less than the number of distributed ID generation requests, continue to select the number of serial numbers of the second distributed ID generation factor from the ordered queue to obtain multiple first serial numbers that are the same as the number of distributed ID generation requests.
[0080] In the specific implementation process, if the number of distributed ID generation requests is greater than the number of serial numbers of the first distributed ID generation factor, specifically assuming that the number of distributed ID generation requests is 5000, and the first distributed ID generation factor is still: ID_DIVISOR(t:LAST_TIMESTAMP+1,w:WORK_ID,s:100,e:4095, at this time, the number of distributed ID generation requests (5000) is greater than the number of serial numbers of the first distributed ID generation factor (3996), and it is necessary to continue to select the number of serial numbers of the second distributed ID generation factor from the ordered queue. Assuming that the second distributed ID generation factor is: ID_DIVISOR(t:LAST_TIMESTAMP+2,w:WORK_ID,s:0,e:4095); then the number of serial numbers of the second distributed ID generation factor is 4096, and the first 1004 (5000-3996=1004) serial numbers (corresponding to serial numbers 0-1033) can be selected therefrom, and a total of 5000 first serial numbers are obtained.
[0081] Step S212: Generate a distributed ID corresponding to each distributed ID generation request based on multiple first serial numbers.
[0082] In the specific implementation process, each first serial number has a corresponding timestamp and machine number, wherein the timestamp and machine number corresponding to the first serial number in the same distributed ID generation factor are the same, while the timestamps corresponding to the first serial numbers in different distributed ID generation factors are different, and the machine numbers are the same. The above 5000 first serial numbers can generate 5000 distributed IDs corresponding to 5000 distributed ID generation requests according to the serial numbers, timestamps and machine numbers in their respective distributed ID generation factors.
[0083] In actual implementation, when burst traffic arrives, there may be a situation where there is no cached distributed ID generation factor in the ordered queue, that is, QUEUE_DIVISOR is empty. In this case, you still need to follow the steps below: Figure 1 The normal logic of the snowflake algorithm shown generates multiple distributed IDs.
[0084] Step S214, obtaining the total number of distributed IDs currently cached in the ordered queue.
[0085] Step S216, based on the preset server processing peak rate and preset time period, obtain the target number of distributed IDs; and determine whether the total number of distributed IDs is greater than the target number of distributed IDs.
[0086] In the specific implementation process, first, the variable ID_TOTAL_NUM (corresponding to the total number of distributed IDs currently cached) used to record the total number of IDs in the QUEUE_DIVISOR queue can be obtained; then the target number of distributed IDs can be determined. Specifically, assuming that the server processing peak rate is preset to ID_RATE_PEAK (TPMS, such as 500,000 per millisecond, the server can process 500,000 IDs per millisecond), the ID generation factor cache and cleanup are performed every X milliseconds (such as: 5 milliseconds), then the target number of distributed IDs is the product of ID_RATE_PEAK and X; finally, the total number of distributed IDs and the target number of distributed IDs can be compared.
[0087] Step S218: If the total number of distributed IDs is greater than the target number of distributed IDs, remove the first distributed ID generation factor in the ordered queue and update the total number of distributed IDs.
[0088] Specifically, when ID_TOTAL_NUM>ID_RATE_PEAK*X, it means that the number of cached IDs is sufficient, and the first element (distributed ID generation factor) in QUEUE_DIVISOR can be removed and discarded, and the ID_TOTAL_NUM value is updated to ID_TOTAL_NUM-(END_ID-START_ID+1).
[0089] Step S220, taking the updated total number of distributed IDs as the new total number of distributed IDs currently cached, and repeating the step of determining whether the total number of distributed IDs is greater than the target number of distributed IDs until the total number of distributed IDs is less than or equal to the target number of distributed IDs.
[0090] In the specific implementation process, after updating the ID_TOTAL_NUM value to ID_TOTAL_NUM-(END_ID-START_ID), continue to determine whether the updated ID_TOTAL_NUM is still greater than the calculation result of ID_RATE_PEAK*X until the total number of distributed IDs is less than or equal to the target number of distributed IDs.
[0091] The above-mentioned distributed ID generation method for dealing with burst traffic, the preset time period includes multiple timestamps corresponding to multiple time points respectively, and the distributed ID generation factors equal to the number of time points are generated based on each timestamp, the machine number corresponding to the server, the starting sequence number and the ending sequence number; the multiple distributed ID generation factors are cached in sequence in an ordered queue according to the chronological order of the time points corresponding to the multiple timestamps; multiple distributed ID generation requests corresponding to the burst traffic are received; based on the starting sequence number and the ending sequence number of each distributed ID generation factor, the number of sequence numbers of each distributed ID generation factor is obtained; according to the number of multiple distributed ID generation requests, the number of sequence numbers equal to the number of distributed ID generation requests is selected from the number of sequence numbers of the first distributed ID generation factor in the ordered queue; if the number of sequence numbers of the first distributed ID generation factor is less than the number of distributed ID generation requests, the number of sequence numbers of the second distributed ID generation factor is continued to be selected from the ordered queue to obtain multiple first sequence numbers equal to the number of distributed ID generation requests; based on the multiple first sequence numbers, a distributed ID corresponding to each distributed ID generation request is generated. This method avoids the problem of high resource consumption caused by expanding the capacity of distributed ID service instances to spread burst traffic by caching recently unused distributed IDs, thereby saving server deployment resources.
[0092] The embodiment of the present invention also provides a distributed ID generation device for dealing with burst traffic, such as Figure 5As shown, the device is arranged on a server; the device comprises: an acquisition module 50, for acquiring a plurality of distributed ID generation factors generated within a preset time period; wherein each distributed ID generation factor comprises: a timestamp, a machine number corresponding to the server, a starting sequence number and an ending sequence number; a cache module 51, for caching a plurality of distributed ID generation factors into an ordered queue; a receiving module 52, for receiving a plurality of distributed ID generation requests corresponding to burst traffic; a generating module 53, for selecting ID generation factors corresponding to the same number of sequence numbers from the ordered queue in order according to the number of the plurality of distributed ID generation requests, so as to generate a distributed ID corresponding to each distributed ID generation request.
[0093] The above-mentioned distributed ID generation device for dealing with burst traffic is arranged on a server; it includes: obtaining multiple distributed ID generation factors generated within a preset time period; caching the multiple distributed ID generation factors into an ordered queue; receiving multiple distributed ID generation requests corresponding to burst traffic; and selecting the ID generation factors corresponding to the same number of serial numbers from the ordered queue in order according to the number of multiple distributed ID generation requests to generate a distributed ID corresponding to each distributed ID generation request. The device can save server deployment resources by caching the multiple distributed ID generation factors generated within a preset time period into an ordered queue; and selecting the ID generation factors corresponding to the same number of serial numbers from the ordered queue in order according to the number of multiple distributed ID generation requests to generate a distributed ID corresponding to each distributed ID generation request.
[0094] Furthermore, the preset time period includes multiple timestamps corresponding to multiple time points respectively, and the acquisition module is also used to: generate multiple distributed ID generation factors based on each timestamp, the machine number corresponding to the server, the starting serial number and the ending serial number; wherein the number of distributed ID generation factors is the same as the number of time points.
[0095] Furthermore, the cache module is also used to: cache multiple distributed ID generation factors in sequence into an ordered queue according to the chronological order of the time points corresponding to the multiple timestamps.
[0096] Furthermore, the device is also used to: obtain the total number of distributed IDs currently cached in the ordered queue; obtain the target number of distributed IDs based on a preset server processing peak rate and a preset time period; determine whether the total number of distributed IDs is greater than the target number of distributed IDs; if the total number of distributed IDs is greater than the target number of distributed IDs, remove the first distributed ID generation factor in the ordered queue and update the total number of distributed IDs; use the updated total number of distributed IDs as the new total number of distributed IDs currently cached, and repeat the step of determining whether the total number of distributed IDs is greater than the target number of distributed IDs until the total number of distributed IDs is less than or equal to the target number of distributed IDs.
[0097] Furthermore, the generation module is also used to: obtain the number of serial numbers of each distributed ID generation factor based on the starting serial number and the ending serial number of each distributed ID generation factor; according to the number of multiple distributed ID generation requests, select the same number of serial numbers as the number of distributed ID generation requests from the ordered queue in sequence to obtain multiple first serial numbers; based on the multiple first serial numbers, generate a distributed ID corresponding to each distributed ID generation request.
[0098] Furthermore, the generation module is also used to: according to the number of multiple distributed ID generation requests, select the same number of serial numbers as the number of distributed ID generation requests from the number of serial numbers of the first distributed ID generation factor in the ordered queue; if the number of serial numbers of the first distributed ID generation factor is less than the number of distributed ID generation requests, continue to select the number of serial numbers of the second distributed ID generation factor from the ordered queue to obtain multiple first serial numbers that are the same as the number of distributed ID generation requests.
[0099] The distributed ID generation device for dealing with burst traffic provided in the embodiment of the present invention has the same implementation principle and technical effects as those of the aforementioned distributed ID generation method embodiment for dealing with burst traffic. For the embodiment of the distributed ID generation device for dealing with burst traffic, reference can be made to the corresponding contents in the aforementioned distributed ID generation method embodiment for dealing with burst traffic.
[0100] The embodiment of the present invention further provides an electronic device, see Figure 6 As shown, the electronic device includes a processor 130 and a memory 131, wherein the memory 131 stores machine executable instructions that can be executed by the processor 130, and the processor 130 executes the machine executable instructions to implement the above-mentioned distributed ID generation method for dealing with burst traffic.
[0101] Further, Figure 6 The electronic device shown further includes a bus 132 and a communication interface 133 , and the processor 130 , the communication interface 133 and the memory 131 are connected via the bus 132 .
[0102] The memory 131 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk storage. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 133 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used. The bus 132 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0103] The processor 130 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 130. The above processor 130 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present invention can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in conjunction with the embodiments of the present invention can be directly embodied as a hardware decoding processor for execution, or a combination of hardware and software modules in the decoding processor for execution. The software module may be located in a storage medium mature in the art, such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 131, and the processor 130 reads the information in the memory 131 and completes the steps of the method of the above embodiment in combination with its hardware.
[0104] An embodiment of the present invention also provides a computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the above-mentioned distributed ID generation method for dealing with burst traffic. The specific implementation can be found in the method embodiment, which will not be repeated here.
[0105] The distributed ID generation method, device and electronic device for dealing with burst traffic provided in the embodiments of the present invention include a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the method described in the previous method embodiments. The specific implementation can be found in the method embodiments, which will not be repeated here.
[0106] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc., which can store program codes.
[0107] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A distributed ID generation method for dealing with burst traffic, characterized in that: The method is applied to a server; the method comprises: Acquire multiple distributed ID generation factors generated within a preset time period; wherein each of the distributed ID generation factors includes: a timestamp, a machine number corresponding to the server, a start sequence number, and an end sequence number; caching the multiple distributed ID generation factors into an ordered queue; Receiving multiple distributed ID generation requests corresponding to the burst traffic; According to the number of the plurality of distributed ID generation requests, sequentially selecting ID generation factors corresponding to the same number of sequence numbers from the ordered queue to generate a distributed ID corresponding to each of the distributed ID generation requests; The method further comprises: Obtain the total number of distributed IDs currently cached in the ordered queue; Based on the preset server processing peak rate and the preset time period, a target distributed ID number is obtained; and it is determined whether the total number of distributed IDs is greater than the target distributed ID number; If the total number of distributed IDs is greater than the target number of distributed IDs, removing the first distributed ID generation factor in the ordered queue and updating the total number of distributed IDs; The updated total number of distributed IDs is used as the new total number of distributed IDs currently cached, and the step of determining whether the total number of distributed IDs is greater than the target number of distributed IDs is repeated until the total number of distributed IDs is less than or equal to the target number of distributed IDs.
2. The method according to claim 1, characterized in that The preset time period includes multiple timestamps corresponding to multiple time points respectively, and the step of obtaining multiple distributed ID generation factors generated within the preset time period includes: Based on each of the timestamps, the machine number corresponding to the server, the starting sequence number and the ending sequence number, multiple distributed ID generation factors are generated; wherein the number of the distributed ID generation factors is the same as the number of the time points.
3. The method according to claim 2, characterized in that The step of caching the multiple distributed ID generation factors into an ordered queue comprises: According to the chronological order of the time points corresponding to the multiple timestamps, the multiple distributed ID generation factors are sequentially cached in an ordered queue.
4. The method according to claim 2, characterized in that: The step of selecting, in order according to the number of the plurality of distributed ID generation requests, ID generation factors corresponding to the same number of serial numbers from the ordered queue to generate a distributed ID corresponding to each of the distributed ID generation requests comprises: Based on the starting sequence number and the ending sequence number of each of the distributed ID generation factors, obtaining the number of sequence numbers of each of the distributed ID generation factors; According to the number of the plurality of distributed ID generation requests, sequentially selecting the same number of sequence numbers as the number of the distributed ID generation requests from the ordered queue to obtain a plurality of first sequence numbers; Based on the multiple first serial numbers, a distributed ID corresponding to each of the distributed ID generation requests is generated.
5. The method according to claim 4, characterized in that The step of selecting, in order according to the number of the plurality of distributed ID generation requests, the same number of sequence numbers as the number of the distributed ID generation requests from the ordered queue to obtain the plurality of first sequence numbers comprises: According to the number of the plurality of distributed ID generation requests, selecting the same number of sequence numbers as the number of the distributed ID generation requests from the number of sequence numbers of the first distributed ID generation factor in the ordered queue; If the number of serial numbers of the first distributed ID generation factor is less than the number of distributed ID generation requests, continue to select the number of serial numbers of the second distributed ID generation factor from the ordered queue to obtain multiple first serial numbers that are the same as the number of distributed ID generation requests.
6. A distributed ID generation device for dealing with burst traffic using the distributed ID generation method for dealing with burst traffic as claimed in claim 1, characterized in that: The device is arranged on a server; the device comprises: An acquisition module, used to acquire multiple distributed ID generation factors generated within a preset time period; wherein each of the distributed ID generation factors includes: a timestamp, a machine number corresponding to the server, a start sequence number, and an end sequence number; A cache module, used for caching the multiple distributed ID generation factors into an ordered queue; A receiving module, used for receiving a plurality of distributed ID generation requests corresponding to the burst traffic; A generation module is used to select ID generation factors corresponding to the same number of serial numbers from the ordered queue in sequence according to the number of the multiple distributed ID generation requests, so as to generate a distributed ID corresponding to each distributed ID generation request.
7. The device according to claim 6, characterized in that: The preset time period includes a plurality of time stamps corresponding to a plurality of time points respectively, and the acquisition module is further used for: Based on each of the timestamps, the machine number corresponding to the server, the starting sequence number and the ending sequence number, multiple distributed ID generation factors are generated; wherein the number of the distributed ID generation factors is the same as the number of the time points.
8. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores machine executable instructions that can be executed by the processor, and the processor executes the machine executable instructions to implement the method according to any one of claims 1 to 5.
9. A machine-readable storage medium, characterized in that: The machine-readable storage medium stores machine-executable instructions, and when the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Distributed ID acquisition method and device, electronic equipment and storage medium
CN111985187A