Message storage method, device, equipment and computer readable medium
By calculating the expiration time difference and target circle number of messages in the ring message queue, determining the insertion position and delaying message consumption, the problem of expiration message discarding in the message queue is solved, and the secure storage and timely consumption of messages are realized.
Patent Information
- Application Number
- CN202011349702.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-26
- Publication Date
- 2025-01-14
- Estimated Expiration
- 2040-11-26
AI Technical Summary
Expired messages in the message queue may be discarded, resulting in data loss, and the prior art is difficult to effectively solve this problem.
By calculating the time difference between the message to be stored and the current time, determining its corresponding target turn and insertion position, and saving the message into the ring message queue, so that the number of turns that the pointer points to the insertion position and the number of turns that has been turned matches the target turn. This delays its consumption.
It effectively avoids the discarding of expired messages in the message queue, ensures that messages are consumed at the right time, and reduces the risk of data loss.
Smart Images

Figure CN112346891B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present disclosure relate to the field of computer technology, and in particular to a message storage method, apparatus, device, and computer-readable medium. Background Art
[0002] Message queues can decouple large implementation systems and have advantages such as improving system scalability, flexibility, and peak processing capabilities. Therefore, they are widely used in various business scenarios. However, related message queues often have the following technical problems:
[0003] Expired consumption problem. That is, if a message in the message queue has passed the expiration time but has not been consumed, then the message will be discarded, which may cause data loss. Summary of the invention
[0004] The content of this disclosure is used to introduce concepts in a brief form, and these concepts will be described in detail in the specific implementation section below. The content of this disclosure is not intended to identify the key features or essential features of the technical solution for which protection is sought, nor is it intended to limit the scope of the technical solution for which protection is sought. Some embodiments of the present disclosure propose a message storage method, device, electronic device, and computer-readable medium to solve the technical problems mentioned in the above background technology section.
[0005] In a first aspect, some embodiments of the present disclosure provide a message storage method, the method comprising: in response to receiving a message to be stored, determining the time difference between an expiration time of the message to be stored and a current time; determining a target number of revolutions corresponding to the message to be stored based on the time difference and the total number of grooves of a circular message queue that is intended to store the message to be stored; determining an insertion position of the message to be stored in the circular message queue based on the time difference, the total number of grooves and the position currently pointed to by a pointer of the circular message queue; according to the target number of revolutions and the insertion position, storing the message to be stored in the circular message queue, so that the message to be stored is consumed in response to the pointer pointing to the insertion position and the number of revolutions that have been turned matching the target number of revolutions.
[0006] Optionally, each groove of the circular message queue corresponds to a message linked list; and according to the target number of turns and the insertion position, the message to be stored is stored in the circular message queue, including: determining the target groove corresponding to the insertion position; determining the storage position of the message to be stored in the message linked list corresponding to the target groove according to the target number of turns; and storing the message to be stored in the storage position.
[0007] Optionally, each message in the message linked list corresponding to the target groove is arranged according to the size of the corresponding number of turns; and according to the target number of turns, the storage position of the message to be stored in the message linked list corresponding to the target groove is determined, including: comparing the target number of turns with the number of turns corresponding to each message in the message linked list corresponding to the target groove, determining the sorting position of the target number of turns in the sequence of each message according to the corresponding number of turns and determining the sorting position as the storage position.
[0008] Optionally, based on the time difference, the total number of grooves and the position currently pointed to by the pointer of the circular message queue, the insertion position of the message to be stored in the circular message queue is determined, including: determining the remainder of the time difference divided by the total number of grooves; determining the sum of the numbered grooves corresponding to the remainder and the position currently pointed to by the pointer; and determining the groove corresponding to the sum as the insertion position.
[0009] In a second aspect, some embodiments of the present disclosure provide a message storage device, the device comprising: a time difference determination unit, configured to determine the time difference between the expiration time of the message to be stored and the current time in response to receiving the message to be stored; a number of revolutions determination unit, configured to determine the target number of revolutions corresponding to the message to be stored based on the time difference and the total number of grooves of the circular message queue in which the message to be stored is to be stored; an insertion position determination unit, configured to determine the insertion position of the message to be stored in the circular message queue based on the time difference, the total number of grooves and the position currently pointed to by the pointer of the circular message queue; a storage unit, configured to store the message to be stored in the circular message queue according to the target number of revolutions and the insertion position, so that the message to be stored is consumed in response to the pointer pointing to the insertion position and the number of revolutions that have been turned matching the target number of revolutions.
[0010] Optionally, each groove of the circular message queue corresponds to a message linked list; and the storage unit is further configured to: determine the target groove corresponding to the insertion position; determine the storage position of the message to be stored in the message linked list corresponding to the target groove according to the target number of circles; and store the message to be stored in the storage position.
[0011] Optionally, each message in the message linked list corresponding to the target groove is arranged according to the size of the corresponding number of turns; and the storage unit is further configured to: compare the target number of turns with the number of turns corresponding to each message in the message linked list corresponding to the target groove, determine the sorting position of the target number of turns in the sequence of each message according to the corresponding number of turns, and determine the sorting position as the storage position.
[0012] Optionally, the insertion position determination unit is further configured to: determine the remainder of the time difference divided by the total number of grooves; determine the sum of the number of grooves corresponding to the remainder and the position currently pointed to by the pointer; and determine the groove corresponding to the sum as the insertion position.
[0013] In a third aspect, some embodiments of the present disclosure provide an electronic device comprising: one or more processors; a storage device on which one or more programs are stored, and when the one or more programs are executed by the one or more processors, the one or more processors implement the method described in any implementation manner in the first aspect.
[0014] In a fourth aspect, some embodiments of the present disclosure provide a computer-readable medium having a computer program stored thereon, wherein when the program is executed by a processor, the method described in any implementation manner in the first aspect is implemented.
[0015] The above-mentioned embodiments of the present disclosure have the following beneficial effects: the problem of overdue consumption is solved. Specifically, the greater the time difference between the expiration time and the current time, the greater the corresponding target number of laps. In other words, the more laps the message needs to go through to consume it, the later it can be consumed. For messages with a smaller time difference between the expiration time and the current time, they can be consumed first, avoiding a large number of messages being discarded in the queue due to expiration. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the accompanying drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and that components and elements are not necessarily drawn to scale.
[0017] Figure 1 is a schematic diagram of an application scenario of a message storage method according to some embodiments of the present disclosure;
[0018] Figure 2 is a flow chart of some embodiments of the message storage method according to the present disclosure;
[0019] Figure 3 is a flowchart of other embodiments of the message storage method according to the present disclosure;
[0020] Figure 4 is an exemplary schematic diagram of a message linked list in a message storage method according to the present disclosure;
[0021] Figure 5 is a schematic diagram of the structure of some embodiments of the message storage device according to the present disclosure;
[0022] Figure 6 It is a schematic diagram of the structure of an electronic device suitable for implementing some embodiments of the present disclosure. DETAILED DESCRIPTION
[0023] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments set forth herein. On the contrary, these embodiments are provided to provide a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.
[0024] It should also be noted that, for ease of description, only the parts related to the invention are shown in the drawings. In the absence of conflict, the embodiments and features in the embodiments of the present disclosure can be combined with each other.
[0025] It should be noted that the concepts such as "first" and "second" mentioned in the present disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0026] It should be noted that the modifications of "one" and "plurality" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0027] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only used for illustrative purposes and are not used to limit the scope of these messages or information.
[0028] The present disclosure will be described in detail below with reference to the accompanying drawings and in conjunction with embodiments.
[0029] Figure 1 This is an application scenario 100 of the message storage method according to some embodiments of the present disclosure.
[0030] like Figure 1 As shown, a circular message queue 101 is shown as an example for storing the message to be stored. The circular message queue is a data structure connected end to end. The circular message queue may include multiple slots for storing messages. For example, Figure 160 grooves are shown, numbered as groove 0-groove 59. Assume that the pointer moves to the next groove every 1s. Then, it takes 1 minute to make one turn. On this basis, in response to receiving the message 102 to be stored, the execution subject of the message storage method can first determine the time difference between the expiration time (e.g., T) of the message 102 to be stored and the current time. Then, the target number of laps corresponding to the message to be stored can be determined based on the time difference and the total number of grooves of the circular message queue to be stored. For example, assuming that the time difference is 120s, the target number of laps corresponding to the message to be stored is 2. Then, the above execution subject can also determine the insertion position of the message to be stored in the circular message queue based on the time difference, the total number of grooves and the position currently pointed to by the pointer of the circular message queue. Optionally, the remainder obtained by dividing the time difference by the total number of grooves and the number of the position currently pointed to can be summed to obtain the number of the insertion position. In this application scenario, the time difference is 120s, the total number of grooves is 60, and it can be seen that the remainder is 0. As shown by the mark 103 in the figure, the position currently pointed to by the pointer is groove 2. Then, the number of the insertion position is 2. That is, the message 102 to be stored can be stored in groove 2, which is the position currently pointed to by the pointer. When the pointer points to groove 2 and the number of turns it has made is 2, the message 102 to be stored can be consumed.
[0031] It is understandable that the execution subject of the message storage method can be various software, a terminal device, or a server. The execution subject of the above method can also include a device formed by integrating the above terminal device and the above server through a network. Among them, the terminal device can be various electronic devices with information processing capabilities, including but not limited to smart phones, tablet computers, e-book readers, laptop computers and desktop computers, etc. When the execution subject of the message storage method is software, it can be installed in the electronic devices listed above. It can be implemented as multiple software or software modules for providing distributed services, for example, or it can be implemented as a single software or software module. No specific limitation is made here.
[0032] It should be understood that Figure 1 The number of the grooves is only for illustration purposes. Any number of grooves may be provided as required.
[0033] Continue to refer Figure 2 , shows a process 200 of some embodiments of the message storage method according to the present disclosure. The message storage method comprises the following steps:
[0034] Step 201: In response to receiving a message to be stored, determining a time difference between an expiration time of the message to be stored and a current time.
[0035] In some embodiments, a message generating end (such as a user terminal, etc.) will continuously generate various messages. The executing subject of the message storage method can respond to receiving a message to be stored, and can first determine the time difference between the expiration time of the message to be stored and the current time. Among them, the expiration time of the message to be stored can be specified, or it can be determined according to certain conditions. The expiration time (TTL) indicates the maximum time a message can survive in a queue. In other words, when a message is set with a TTL or when a message enters a queue with a TTL set, the message will "die" after a certain period of time and become a dead letter.
[0036] Step 202 : determining a target number of laps corresponding to the message to be stored based on the time difference and the total number of grooves of the circular message queue that is intended to store the message to be stored.
[0037] In some embodiments, the execution subject may determine the target number of laps corresponding to the message to be stored based on the time difference and the total number of grooves of the circular message queue to be stored. As an example, the time difference may be divided by the total number of grooves, and the quotient obtained may be used as the target number of laps. As an example, the time difference may be divided by the total number of grooves, the quotient obtained may be summed with a given constant, and the sum obtained may be used as the target number of laps.
[0038] Step 203: Determine the insertion position of the message to be stored in the circular message queue based on the time difference, the total number of grooves and the position currently pointed to by the pointer of the circular message queue.
[0039] In some embodiments, the insertion position of the message to be stored in the circular message queue is used to indicate which groove the message to be stored is stored in. As an example, when the total number of grooves meets the preset conditions, the sum of the last several digits of the time difference and the currently pointed position can be determined, and the obtained sum is determined as the insertion position. For example, when the total number of grooves is 20 (numbered 0-19). The sum of the last two digits of the time difference and the currently pointed position (for example, 12) can be determined. And the message to be stored is stored in the groove whose number is consistent with the sum (for example, the groove numbered 12).
[0040] In some optional implementations of some embodiments, the remainder of the time difference divided by the total number of grooves can be first determined; the sum of the number of grooves corresponding to the remainder and the position currently pointed to by the pointer is determined; and the groove corresponding to the sum of the number is determined as the insertion position.
[0041] Step 204, according to the target number of revolutions and the insertion position, the message to be stored is stored in the circular message queue, so that the message to be stored is consumed in response to the pointer pointing to the insertion position and the number of revolutions that have been turned matches the target number of revolutions.
[0042] The methods provided by some embodiments of the present disclosure solve the problem of overdue consumption. Specifically, the greater the time difference between the expiration time and the current time, the greater the corresponding target number of circles. In other words, the more circles the message needs to go through to consume it, the later it can be consumed. For messages with a smaller time difference between the expiration time and the current time, they can be consumed first to avoid a large number of messages being discarded in the queue due to expiration.
[0043] Further references Figure 3 , which shows a process 300 of another embodiment of a message storage method. The process 300 of the message storage method includes the following steps:
[0044] Step 301: In response to receiving a message to be stored, determining a time difference between an expiration time of the message to be stored and a current time.
[0045] Step 302: Determine the target number of laps corresponding to the message to be stored based on the time difference and the total number of grooves of the circular message queue that is intended to store the message to be stored.
[0046] In some embodiments, each groove of the circular message queue corresponds to a message linked list.
[0047] Step 303: Determine the insertion position of the message to be stored in the circular message queue based on the time difference, the total number of grooves and the position currently pointed to by the pointer of the circular message queue.
[0048] In some embodiments, the specific implementation of steps 301-303 and the technical effects thereof can be referred to in Figure 2 The corresponding steps 201-203 in the embodiments are not described in detail here.
[0049] Step 304: determine the target groove corresponding to the insertion position.
[0050] In some embodiments, the groove having the same number as the insertion position may be determined as the target groove.
[0051] Step 305: Determine the storage position of the message to be stored in the message linked list corresponding to the target groove according to the target number of laps.
[0052] In an optional implementation of some embodiments, each message in the message chain list corresponding to the target groove is arranged according to the size of the corresponding number of turns. Therefore, by comparing the target number of turns with the number of turns corresponding to each message in the message chain list corresponding to the target groove, the sorting position of the target number of turns in the sequence of the corresponding number of turns of each message can be determined and the sorting position can be determined as the storage position.
[0053] You can refer to Figure 4, which exemplarily shows a message chain list 400. There are 5 nodes in the message chain list 400, and each node stores a message with a number of turns. Each node is arranged according to the size of the corresponding number of turns. As shown in the figure, the larger the number of turns, the closer it is to the head of the chain list, and the smaller the number of turns, the closer it is to the tail of the chain list. The messages in the chain list are generally consumed from the head. Therefore, the closer to the head, the earlier it is consumed. On this basis, by comparing the target number of turns with the number of turns corresponding to each message in the message chain list corresponding to the target groove, the sorting position of the target number of turns in each message according to the corresponding number of turns sequence can be determined, and the sorting position can be determined as the storage position. As an example, the target number of turns of the message to be stored is 6. By comparing with the number of turns corresponding to each message, it can be seen that it is located between the number of turns corresponding to the message stored in node 401 and the message stored in node 402. Therefore, the storage position can be determined to be between node 401 and node 402.
[0054] Step 306: Store the message to be stored in a storage location.
[0055] In the process 400 of the message storage method in these embodiments, a message linked list is set for each groove, and according to the target number of circles, the storage position of the message to be stored in the message linked list corresponding to the target groove is determined. The above scheme, as an inventive point of the present disclosure, further solves the "overdue consumption problem" in the background technology. Specifically, since the storage position is determined according to the number of circles, the larger the number of circles, the closer to the head of the linked list, and the smaller the number of circles, the closer to the tail of the linked list. The messages in the linked list are generally consumed from the head. Therefore, the closer to the head, the earlier it can be consumed, thereby reducing the phenomenon that the message has expired but has not been consumed.
[0056] Further references Figure 5 As an implementation of the methods shown in the above figures, the present disclosure provides some embodiments of a message storage device. These device embodiments are similar to Figure 2 Corresponding to the method embodiments shown, the device can be specifically applied to various electronic devices.
[0057] like Figure 5As shown, the message storage device 500 of some embodiments includes a time difference determination unit 501, a number of turns determination unit 502, an insertion position determination unit 503 and a storage unit 504. Among them, the time difference determination unit 501 is configured to determine the time difference between the expiration time of the message to be stored and the current time in response to receiving the message to be stored. The number of turns determination unit 502 is configured to determine the target number of turns corresponding to the message to be stored based on the time difference and the total number of grooves of the circular message queue to be stored. The insertion position determination unit 503 is configured to determine the insertion position of the message to be stored in the circular message queue based on the time difference, the total number of grooves and the position currently pointed to by the pointer of the circular message queue. The storage unit 504 is configured to store the message to be stored in the circular message queue according to the target number of turns and the insertion position, so that the message to be stored is consumed in response to the pointer pointing to the insertion position and the number of turns that have been turned matches the target number of turns.
[0058] In an optional implementation of some embodiments, each groove of the circular message queue corresponds to a message linked list; and the storage unit is further configured to: determine the target groove corresponding to the insertion position; determine the storage position of the message to be stored in the message linked list corresponding to the target groove according to the target number of circles; and store the message to be stored in the storage position.
[0059] In an optional implementation of some embodiments, each message in the message chain list corresponding to the target groove is arranged according to the size of the corresponding number of circles; and the storage unit is further configured to:
[0060] The target number of revolutions is compared with the number of revolutions corresponding to each message in the message chain list corresponding to the target groove, the sorting position of the target number of revolutions in each message according to the corresponding number of revolutions sequence is determined, and the sorting position is determined as the storage position.
[0061] In an optional implementation of some embodiments, the insertion position determination unit is further configured to: determine the remainder of the time difference divided by the total number of grooves; determine the sum of the number of grooves corresponding to the remainder and the position currently pointed to by the pointer; and determine the groove corresponding to the sum as the insertion position.
[0062] It is understood that the units described in the device 500 are similar to those described in the reference Figure 2 Therefore, the operations, features and beneficial effects described above for the method are also applicable to the device 500 and the units included therein, and will not be described in detail here.
[0063] Reference below Figure 6 , which shows a structural schematic diagram of an electronic device 600 suitable for implementing some embodiments of the present disclosure. Figure 6The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0064] like Figure 6 As shown, the electronic device 600 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage device 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the electronic device 600 are also stored. The processing device 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0065] Typically, the following devices may be connected to the I / O interface 605: an input device 606 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 607 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 608 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 609. The communication device 609 may allow the electronic device 600 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 6 The electronic device 600 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead. Figure 6 Each block shown in the figure may represent one device, or may represent multiple devices as required.
[0066] In particular, according to some embodiments of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, some embodiments of the present disclosure include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In some such embodiments, the computer program can be downloaded and installed from the network through the communication device 609, or installed from the storage device 608, or installed from the ROM 602. When the computer program is executed by the processing device 601, the above-mentioned functions defined in the method of some embodiments of the present disclosure are executed.
[0067] It should be noted that the computer-readable medium recorded in some embodiments of the present disclosure may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In some embodiments of the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In some embodiments of the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-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 of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0068] In some embodiments, the client and the server may communicate using any currently known or future developed network protocol such as HTTP (HyperText Transfer Protocol), and may be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or future developed network.
[0069] The computer-readable medium may be included in the electronic device; or it may exist independently without being assembled into the electronic device. The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device: in response to receiving a message to be stored, determines the time difference between the expiration time of the message to be stored and the current time; based on the time difference and the total number of grooves of the circular message queue to be stored, determines the target number of laps corresponding to the message to be stored; based on the time difference, the total number of grooves and the position currently pointed to by the pointer of the circular message queue, determines the insertion position of the message to be stored in the circular message queue; based on the target number of laps and the insertion position, stores the message to be stored in the circular message queue, so that the message to be stored is consumed in response to the pointer pointing to the insertion position and the number of laps that have been turned matches the target number of laps.
[0070] Computer program code for performing the operations of some embodiments of the present disclosure may be written in one or more programming languages or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on a user's computer, partially on a user's computer, as a separate software package, partially on a user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0071] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0072] The units described in some embodiments of the present disclosure may be implemented by software or hardware. The units described may also be set in a processor, for example, it may be described as: a processor includes a time difference determination unit, a lap number determination unit, an insertion position determination unit, and a storage unit. The names of these units do not constitute limitations on the units themselves in some cases, for example, the time difference determination unit may also be described as "a unit for determining the time difference between the expiration time of the message to be stored and the current time".
[0073] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0074] The above descriptions are only some preferred embodiments of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the embodiments of the present disclosure is not limited to the technical solutions formed by a specific combination of the above-mentioned technical features, but should also cover other technical solutions formed by any combination of the above-mentioned technical features or their equivalent features without departing from the above-mentioned inventive concept. For example, the above-mentioned features are replaced with the technical features with similar functions disclosed in the embodiments of the present disclosure (but not limited to) and the technical solutions formed.
Claims
1. A message storage method, comprising: In response to receiving a message to be stored, determining a time difference between an expiration time of the message to be stored and a current time; Determining a target number of laps corresponding to the message to be stored based on the time difference and the total number of grooves of the circular message queue that is intended to store the message to be stored, comprising: dividing the time difference by the total number of grooves, and using the quotient as the target number of laps; Based on the time difference, the total number of the grooves and the position currently pointed to by the pointer of the circular message queue, determining the insertion position of the message to be stored in the circular message queue, comprising: determining the remainder of the time difference divided by the total number of the grooves; determining the sum of the number of grooves corresponding to the remainder and the position currently pointed to by the pointer; determining the groove corresponding to the sum as the insertion position, wherein each groove of the circular message queue corresponds to a message linked list; According to the target number of revolutions and the insertion position, the message to be stored is stored in the message linked list corresponding to the groove in the circular message queue, so that the message to be stored is consumed in response to the pointer pointing to the insertion position and the number of revolutions that have been turned matches the target number of revolutions, thereby avoiding a large number of messages from being discarded in the queue due to expiration, wherein each message in the message linked list corresponding to the groove is arranged according to the size of the corresponding number of revolutions.
2. The method according to claim 1, wherein: The step of storing the message to be stored in the annular message queue according to the target number of turns and the insertion position includes: Determine a target groove corresponding to the insertion position; Determine, according to the target number of laps, a storage position of the message to be stored in a message linked list corresponding to the target groove; The message to be stored is stored in the storage location.
3. The method according to claim 2, wherein: The messages in the message chain list corresponding to the target groove are arranged according to the corresponding number of circles; as well as Determining the storage position of the message to be stored in the message linked list corresponding to the target groove according to the target number of laps includes: The target number of revolutions is compared with the number of revolutions corresponding to each message in the message linked list corresponding to the target groove, the sorting position of the target number of revolutions in the corresponding number of revolutions sequence of each message is determined, and the sorting position is determined as the storage position.
4. A message storage device, comprising: a time difference determining unit, configured to determine, in response to receiving a message to be stored, a time difference between an expiration time of the message to be stored and a current time; A lap number determination unit is configured to determine a target lap number corresponding to the message to be stored based on the time difference and the total number of grooves of the circular message queue that is intended to store the message to be stored, including: dividing the time difference by the total number of grooves, and using the quotient as the target lap number; The insertion position determination unit is configured to determine the insertion position of the message to be stored in the annular message queue based on the time difference, the total number of the grooves and the position currently pointed to by the pointer of the annular message queue, including: determining the remainder of the time difference divided by the total number of the grooves; determining the sum of the number of grooves corresponding to the remainder and the position currently pointed to by the pointer; determining the groove corresponding to the sum as the insertion position, wherein each groove of the annular message queue corresponds to a message linked list; The storage unit is configured to store the message to be stored into the message linked list corresponding to the groove in the circular message queue according to the target number of revolutions and the insertion position, so that the message to be stored is consumed in response to the pointer pointing to the insertion position and the number of revolutions that have been turned matches the target number of revolutions, thereby avoiding a large number of messages from being discarded in the queue due to expiration, wherein the messages in the message linked list corresponding to the groove are arranged according to the size of the corresponding number of revolutions.
5. The device according to claim 4, wherein: The storage unit is further configured to: Determine a target groove corresponding to the insertion position; Determine, according to the target number of laps, a storage position of the message to be stored in a message linked list corresponding to the target groove; The message to be stored is stored in the storage location.
6. The device according to claim 5, wherein: The messages in the message chain list corresponding to the target groove are arranged according to the corresponding number of circles; and The storage unit is further configured to: The target number of revolutions is compared with the number of revolutions corresponding to each message in the message linked list corresponding to the target groove, the sorting position of the target number of revolutions in the corresponding number of revolutions sequence of each message is determined, and the sorting position is determined as the storage position.
7. An electronic device comprising: one or more processors; a storage device having one or more programs stored thereon, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 3.
8. A computer readable medium having a computer program stored thereon, wherein: When the program is executed by a processor, the method according to any one of claims 1 to 3 is implemented.
Citation Information
Patent Citations
Delayed task execution method and device
CN107220030A