A message processing method, device and system
By introducing a token mechanism into the distributed cluster, multiple execution nodes are allowed to process different messages, which solves the node waiting problem caused by distributed locks, improves node utilization and message processing efficiency, and enhances the scalability of the cluster.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- JD DIGITS HAIYI INFORMATION TECHNOLOGY CO LTD
- Filing Date
- 2022-04-12
- Publication Date
- 2026-04-14
AI Technical Summary
When using distributed lock mechanisms in a distributed cluster, most nodes are in a waiting state when there are many nodes in the cluster, resulting in low node utilization and low message processing efficiency.
The token mechanism allows multiple execution nodes to extract different target tokens to process different target messages, avoiding the use of distributed locks. By leveraging the correspondence between token identifiers and storage shard identifiers, it ensures that multiple storage shards are processed by cluster nodes.
It improves the utilization rate of data cluster nodes and message processing efficiency, reduces resource conflicts, and enhances the dynamic scalability of the cluster.
Smart Images

Figure CN114741195B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a message processing method, apparatus and system. Background Technology
[0002] Currently, large-scale message processing is achieved through collaborative processing using distributed clusters. Distributed clusters typically employ distributed locks to implement this collaborative processing.
[0003] In the process of realizing this invention, the inventors discovered at least the following problems in the prior art:
[0004] When using a distributed lock mechanism in a distributed cluster, only the node that acquires the distributed lock can execute processing tasks. As a result, when there are many nodes in the cluster, most of the nodes are in a waiting state. For example, in a Redis cluster and a ZooKeeper cluster, only one node can acquire the distributed lock and execute processing tasks at the same time, while other nodes that have not acquired the distributed lock are in a waiting state and cannot execute processing tasks. This leads to low utilization of cluster nodes, resulting in low message processing efficiency. Summary of the Invention
[0005] In view of this, embodiments of the present invention provide a message processing method, apparatus, and system that utilizes an execution node that has extracted a target token to process target messages on a storage shard. Thus, while one execution node is processing a message, other execution nodes can still extract other target tokens to process other target messages corresponding to those extracted tokens. In other words, multiple execution nodes can process different target messages simultaneously by extracting different target tokens, thereby eliminating the need for a distributed lock for message processing. This avoids the situation where only the node that acquires the distributed lock can execute the message processing task, while other cluster nodes are in a waiting state because they have not acquired the distributed lock. This improves the utilization rate of data cluster nodes and also increases message processing efficiency.
[0006] Furthermore, determining the number of tokens generated based on the processing performance of the data cluster nodes can reduce the idle time of the cluster nodes and improve their efficiency. Additionally, cluster nodes can determine the frequency of token extraction based on their own workload and / or execution cycle, reducing resource conflicts within the data cluster and improving the independence of task execution for each cluster node. The mapping between token identifiers and storage shard identifiers ensures that multiple storage shards can be processed by the cluster nodes, thus ensuring that adding or removing nodes in the cluster does not affect the message processing flow and increases the cluster's dynamic scalability.
[0007] To achieve the above objectives, according to a first aspect of the present invention, a message processing method is provided, the method being applied to an execution node in a data cluster, comprising:
[0008] In response to a message processing request, a target token is retrieved from a token queue. The target identifier of the target token corresponds to the identifier of the storage shard containing the message to be processed. The token queue includes multiple tokens generated by the coordinating node in the data cluster.
[0009] Based on the target identifier of the target token, the target message is extracted from the target storage segment corresponding to the target token, and the target message is processed.
[0010] Optionally, the method further includes:
[0011] Retrieve at least two pending messages;
[0012] Based on the message identifier of the message to be processed, at least two of the messages to be processed are stored in at least two storage shards of the data cluster.
[0013] Optionally, the method further includes:
[0014] After processing the current target message, the method further includes: retrieving the target token from the token queue;
[0015] And / or,
[0016] It also includes: extracting the target token from the token queue if the execution cycle is met at the current time.
[0017] Optionally, the number of the at least two storage shards is determined based on the number of nodes in the data cluster and the processing performance of the nodes, and the number of the at least two storage shards is greater than the number of nodes in the data cluster.
[0018] Optionally, the pending message indicates a pending time; at least two pending messages are ordered in the storage shard according to the chronological order of their pending times; the step of extracting the target message from the target storage shard corresponding to the target token includes:
[0019] The target message is extracted from the target storage segment according to the order of at least two messages to be processed stored on the target storage segment; wherein the difference between the processing time of the target message and the current time is less than or equal to a preset time threshold.
[0020] Optionally, storing at least two messages to be processed in at least two storage shards of the data cluster according to the message identifier of the message to be processed includes:
[0021] Perform a hash operation on the message identifier of the message to be processed, and perform a modulo operation on the number of storage fragments based on the hash operation result;
[0022] The storage segment to be stored for the message to be processed is determined based on the result of the modulo operation.
[0023] The message to be processed is stored in the determined storage segment.
[0024] According to a second aspect of the present invention, a message processing method is provided, the method being applied to a data cluster, comprising:
[0025] Tokens are generated using one or more coordinating nodes and stored in a token queue; the identifier of the token corresponds to the identifier of the storage fragment containing the message to be processed.
[0026] The target token is extracted from the token queue using at least two execution nodes;
[0027] For the execution node that has extracted the target token: extract the target message from the target storage shard corresponding to the target token according to the target identifier of the target token, and process the target message.
[0028] Optionally, the method further includes:
[0029] At least two messages to be processed are obtained using the execution nodes in the data cluster.
[0030] Based on the message identifier of the message to be processed, at least two of the messages to be processed are stored in at least two storage shards of the data cluster.
[0031] Optionally, the method further includes:
[0032] At least two messages to be processed are obtained using the execution nodes in the data cluster.
[0033] Based on the message identifier of the message to be processed, at least two of the messages to be processed are stored in at least two storage shards of the data cluster.
[0034] Optionally, the method further includes:
[0035] For each execution node: after processing the current target message, the method further includes: retrieving the target token from the token queue;
[0036] And / or,
[0037] It also includes: for each of the execution nodes: if the execution cycle is met at the current time, extract the target token from the token queue.
[0038] Optionally, the number of the at least two storage shards is determined based on the number of nodes in the data cluster and the processing performance of the nodes, and the number of the at least two storage shards is greater than the number of nodes in the data cluster.
[0039] Optionally, the pending message indicates a pending time; at least two pending messages are ordered in the storage shard according to the order of their pending times.
[0040] Extracting the target message from the target storage shard corresponding to the target token includes:
[0041] The target message is extracted from the target storage segment according to the order of at least two messages to be processed stored on the target storage segment; wherein the difference between the processing time of the target message and the current time is less than or equal to a preset time threshold.
[0042] Optionally, generating tokens using one or more coordinating nodes includes:
[0043] The number of tokens to be generated is determined based on the current number of tokens in the token queue, the token control policy, and the number of storage shards.
[0044] The tokens are generated using one or more coordinating nodes based on the number of tokens to be generated.
[0045] Optionally, the token control policy includes a first preset threshold and / or a second preset threshold, wherein the first preset threshold is less than the second preset threshold; determining the number of tokens to be generated based on the current number of tokens in the token queue, the token control policy, and the number of storage shards includes:
[0046] If the current number of tokens is less than the first preset threshold: determine the base number of tokens to be generated; determine the multiple of the number of tokens to be generated based on the current number of tokens, the first preset threshold, and the number of storage shards; determine the number of tokens to be generated based on the base number and the multiple.
[0047] And / or,
[0048] If the current number of tokens is greater than or equal to the second preset threshold, the number of tokens to be generated is determined to be zero.
[0049] Optionally, generating tokens using one or more coordinating nodes further includes:
[0050] Multiple nodes are identified from the data cluster as the coordinating nodes, and threads for generating tokens are configured for the coordinating nodes;
[0051] The target node is determined from the plurality of coordinating nodes, and the token is generated using the thread on the target node.
[0052] Optionally, the method further includes:
[0053] If the target node fails to generate a token, a new target node is determined from other coordinating nodes besides the target node, and the token is generated using the thread on the newly determined target node.
[0054] Optionally, storing at least two messages to be processed in at least two storage shards of the data cluster according to the message identifier of the message to be processed includes:
[0055] Perform a hash operation on the message identifier of the message to be processed, and perform a modulo operation on the number of storage fragments based on the hash operation result;
[0056] The storage segment to be stored for the message to be processed is determined based on the result of the modulo operation.
[0057] The message to be processed is stored in the determined storage segment.
[0058] According to a third aspect of the present invention, a message processing apparatus is provided, applied to an execution node in a data cluster, comprising: an extraction module and a processing module; wherein,
[0059] The extraction module is used to extract a target token from the token queue in response to a message processing request. The target identifier of the target token corresponds to the identifier of the storage shard storing the message to be processed. The token queue includes multiple tokens generated by the coordinating node in the data cluster.
[0060] The processing module is used to extract target messages from the target storage shard corresponding to the target token based on the target identifier of the target token, and to process the target messages.
[0061] According to a fourth aspect of the present invention, a message processing system is provided, comprising:
[0062] A coordinating node is used to: generate tokens and store them in a token queue; the identifier of the token corresponds to the identifier of the storage shard containing the message;
[0063] An execution node is configured to: extract a target token from the token queue; extract a target message from the target storage shard corresponding to the target token based on the target identifier of the target token; and process the target message.
[0064] Optionally, the system also includes:
[0065] A storage node is configured to: acquire at least two messages to be processed using the execution node in the data cluster; and store the at least two messages to be processed into at least two storage shards of the data cluster according to the message identifier of the messages to be processed.
[0066] According to a fifth aspect of the present invention, a message processing server is provided, comprising:
[0067] One or more processors;
[0068] Storage device for storing one or more programs.
[0069] When the one or more programs are executed by the one or more processors, the one or more processors implement any of the methods described in the message processing method provided in the embodiments of the present invention.
[0070] According to a sixth aspect of the present invention, a computer-readable medium is provided having a computer program stored thereon, which, when executed by a processor, implements any of the methods described in the message processing method provided in the embodiments of the present invention.
[0071] One embodiment of the above invention has the following advantages or beneficial effects: The execution node that has extracted the target token processes the target message on the storage shard. Therefore, while one execution node is processing a message, other execution nodes can still extract other target tokens to process other target messages corresponding to the extracted target tokens. In other words, multiple execution nodes can process different target messages simultaneously by extracting different target tokens, thus eliminating the need for a distributed lock for message processing. This avoids the situation where only the node that acquires the distributed lock can execute the message processing task, while other cluster nodes are in a waiting state because they have not acquired the distributed lock. This improves the utilization rate of the data cluster nodes and also increases message processing efficiency.
[0072] Furthermore, determining the number of tokens generated based on the processing performance of the data cluster nodes can reduce the idle time of the cluster nodes and improve their efficiency. Additionally, cluster nodes can determine the frequency of token extraction based on their own workload and / or execution cycle, reducing resource conflicts within the data cluster and improving the independence of task execution for each cluster node. The mapping between token identifiers and storage shard identifiers ensures that multiple storage shards can be processed by the cluster nodes, thus ensuring that adding or removing nodes in the cluster does not affect the message processing flow and increases the cluster's dynamic scalability.
[0073] The further effects of the aforementioned unconventional alternative methods will be explained below in conjunction with specific implementation methods. Attached Figure Description
[0074] The accompanying drawings are provided to better understand the invention and are not intended to unduly limit the scope of the invention. Wherein:
[0075] Figure 1 This is a schematic diagram of the main steps of a message processing method provided in one embodiment of the present invention;
[0076] Figure 2 This is a schematic diagram of the main steps of a message processing method provided in another embodiment of the present invention;
[0077] Figure 3 This is a schematic diagram of the structure of a data cluster for processing messages provided in one embodiment of the present invention;
[0078] Figure 4 This is a schematic diagram of a message processing flow provided in another embodiment of the present invention;
[0079] Figure 5 This is a schematic diagram of the structure of a message processing device provided in one embodiment of the present invention;
[0080] Figure 6 This is a schematic diagram of the structure of a message processing system provided in one embodiment of the present invention;
[0081] Figure 7 This is an exemplary system architecture diagram in which embodiments of the present invention can be applied;
[0082] Figure 8 This is a schematic diagram of the structure of a computer system suitable for implementing terminal devices or servers of the present invention. Detailed Implementation
[0083] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of the present invention, including various details to aid understanding. These details should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the invention. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.
[0084] It should be noted that, unless otherwise specified, the embodiments of the present invention and the technical features thereof can be combined with each other.
[0085] like Figure 1 As shown in the figure, an embodiment of the present invention provides a message processing method applied to an execution node in a data cluster. The method may include the following steps:
[0086] Step S101: In response to a message processing request, extract a target token from the token queue. The target identifier of the target token corresponds to the identifier of the storage shard storing the message to be processed. The token queue includes multiple tokens generated by the coordinating node in the data cluster.
[0087] Step S102: Extract the target message from the target storage segment corresponding to the target token according to the target identifier of the target token, and process the target message.
[0088] In one embodiment of the present invention, the message processing request may be a request to process the message to be processed stored in the storage shard, may be a message processing request sent by a scheduled task, or may be a message processing request sent by a functional module of the business system.
[0089] The method for storing messages to be processed to storage shards can be as follows, as provided in this embodiment of the invention: obtaining at least two messages to be processed; and storing at least two messages to be processed to at least two storage shards in the data cluster according to the message identifier of the messages to be processed.
[0090] In another embodiment of the present invention, the number of the at least two storage shards is determined based on the number of nodes in the data cluster and the processing performance of the nodes, and the number of the at least two storage shards is greater than the number of nodes in the data cluster.
[0091] Understandably, having more storage shards than the number of nodes in the data cluster ensures that execution nodes do not experience execution conflicts when retrieving target tokens for message processing, thus improving message processing efficiency.
[0092] In another embodiment of the present invention, storing at least two messages to be processed into at least two storage shards of a data cluster according to the message identifier of the message to be processed includes: performing a hash operation on the message identifier of the message to be processed; performing a modulo operation on the number of storage shards according to the hash operation result; determining the storage shard to which the message to be processed should be stored according to the modulo operation result; and storing the message to be processed into the determined storage shard.
[0093] In another embodiment of the present invention, the message to be processed indicates a processing time; at least two messages to be processed are ordered in the storage shard according to the order of the processing time; the target message is extracted from the target storage shard according to the order of the at least two messages to be processed stored on the target storage shard; wherein the difference between the processing time of the target message and the current time is less than or equal to a preset time threshold.
[0094] In another embodiment of the present invention, after processing the current target message, the method further includes: extracting the target token from the token queue.
[0095] In another embodiment of the present invention, the method further includes: extracting a target token from the token queue when the current time satisfies the execution cycle.
[0096] Figure 2 This is a schematic diagram illustrating the main steps of a message processing method according to another embodiment of the present invention. The method is applied to a data cluster and may include the following steps:
[0097] Step S201: Generate tokens using one or more coordinating nodes and store them in a token queue; the identifier of the token corresponds to the identifier of the storage shard containing the message to be processed.
[0098] Step S202: Extract the target token from the token queue using at least two execution nodes.
[0099] Step S203: For the execution node where the target token has been extracted: extract the target message from the target storage shard corresponding to the target token according to the target identifier of the target token, and process the target message.
[0100] Understandably, one application scenario for this invention is the processing of delayed messages. In this scenario, messages to be processed can be obtained through message queues, remote calls, asynchronous files, etc. Typically, messages to be processed contain information such as the sender, receiver, message content, delay time, and processing time. The obtained messages to be processed can be persistently stored first, and then processed through a data cluster.
[0101] For large volumes of messages, in order to utilize multiple data cluster nodes for parallel processing and maximize the cluster's processing capacity, the acquired messages can be stored in shards. This means storing at least two messages to be processed in at least two storage shards within the data cluster.
[0102] In one embodiment of the present invention, at least two messages to be processed can be obtained using storage nodes in the data cluster; based on the message identifier of the messages to be processed, the at least two messages to be processed are stored in at least two storage shards of the data cluster.
[0103] In this context, a storage node can be a node in the data cluster used to store messages, or it can be a node in the data cluster used for message processing, i.e., an execution node. In other words, a storage node can be one or more execution nodes, or it can be a different node from the execution nodes.
[0104] Data cluster storage sharding can utilize databases, MongoDB, Redis (Remote Dictionary Server), and other systems.
[0105] Understandably, in scenarios involving delayed messages, these messages are not sent immediately but are typically processed according to their pending processing times. After receiving a delayed message, its pending processing time can be calculated based on the current time and the delay duration specified in the message. Correspondingly, during storage, messages can be stored in storage shards according to their pending processing times.
[0106] When storing messages using databases or similar methods, additional code is required to sort the messages. However, Redis's sorted set (zset) is an ordered set, making message sorting easier, reducing coding workload, and improving efficiency. Therefore, in one embodiment of this invention, it is preferable to use Redis's zset to implement storage sharding, that is, storing multiple messages in multiple zsets to correspond to multiple storage shards, with each storage shard corresponding to one zset.
[0107] Understandably, the number of storage shards needs to be determined before storing messages to be processed. In one embodiment of the present invention, the number of the at least two storage shards is determined based on the number of nodes in the data cluster and the processing performance of the nodes, and the number of the at least two storage shards is greater than the number of nodes in the data cluster.
[0108] Understandably, when forming a data cluster for message processing, multiple machines with roughly similar processing capabilities are usually selected as multiple nodes of the data cluster.
[0109] For example, the number of storage shards, M, can be calculated from the number of nodes, N, in the data cluster, and the processing performance, k, of each node. This can be expressed as: M = N * k. Here, k is an estimate of the cluster's node processing capacity, which can be obtained from historical processing capacity statistics. k can be an integer of 2 or higher. Taking a data cluster with N = 100 nodes as an example, if k is set to 2 based on processing capacity statistics, then the number of storage shards, M, is 200. The identifiers for the storage shards are integers from 1 to 200.
[0110] In one embodiment of the present invention, the 200 storage shards mentioned above can correspond to 200 zset sets in the Redis system. The key value of the zset set can be used to mark the identifier of the storage shard. In other words, 200 zset sets with key values from 1 to 200 can be created in the Redis system to store messages.
[0111] To ensure that the number of storage shards is available to every node in the data cluster, in one embodiment of the invention, the number of storage shards can be stored in a distributed configuration center. When using nodes in the data cluster for sharded storage, the number of storage shards can be obtained from the configuration center first, and then the storage shards can be determined based on the number of storage shards. For example, the number M of storage shards can be stored in the configuration center. A node in the data cluster can read M from the configuration center, and then create M sets of sorted sets with key values from 1 to M based on M, for subsequent use in storing messages.
[0112] After determining the number and identifier of the storage shards, it is also necessary to determine the storage shard to which each message to be processed should be stored. This can be done in the following way provided by an embodiment of the present invention: perform a hash operation on the message identifier of the message to be processed, perform a modulo operation on the number of storage shards based on the hash operation result; determine the storage shard to which the message to be processed should be stored based on the modulo operation result; and store the message to be processed in the determined storage shard.
[0113] Taking the aforementioned number of storage shards (200) and corresponding to 200 sorted set (zset) collections as an example, hashing the message identifier of one message yields a result of 230. Then, performing a modulo operation on the number of storage shards (200) yields a result of 30. Therefore, the identifier of the storage shard corresponding to this message is determined to be 30, meaning the message can be stored in the storage shard with identifier 30. In the zset collection context, this means storing it in the zset collection with key value 30.
[0114] In practical storage, taking the Redis sorted set (zset) as an example, the message's pending processing time can be used as the zset's score value, and the specific message can be stored in the member corresponding to that score value. Due to the ordered nature of the zset, members can be automatically sorted by score value. Therefore, it is convenient to retrieve the corresponding message from the zset based on a given time, reducing coding workload and improving message processing efficiency.
[0115] The message to be processed can be stored in a storage shard first, and then a token can be generated; alternatively, a token can be generated first, and then the message to be processed can be stored in the storage shard; or the token can be generated at the same time as the message to be processed is stored in the storage shard. In a data cluster, token generation and message storage can be performed by different threads on the same node, or by threads on different nodes.
[0116] Understandably, token generation can be performed by one or more nodes in the cluster. In another embodiment of the invention, the node for generating the token can be determined as follows: multiple nodes are determined from the data cluster as coordinating nodes, and a thread for generating the token is configured for each coordinating node; a target node is determined from the multiple coordinating nodes, and the token is generated using the thread on the target node. If the target node fails to generate the token, a new target node is determined from other coordinating nodes besides the target node, and the token is generated using the thread on the newly determined target node.
[0117] In other words, multiple nodes are selected from the data cluster to form a virtual coordination cluster, and a target node is selected from this virtual coordination cluster each time to generate a token.
[0118] For example, if a data cluster has 100 nodes, at least three nodes are selected from these 100 nodes as coordinating nodes to form a virtual coordinating cluster. These coordinating nodes can be configured with threads for generating tokens or threads for executing message processing. That is, these at least three nodes can function as both token-generating nodes (coordinating nodes) and message-processing nodes (execution nodes). This improves the utilization rate of each node in the data cluster and reduces waste of node resources. Furthermore, both coordinating nodes and execution nodes are nodes in the data cluster, and there is no actual distinction between them. In this embodiment of the invention, for ease of description, they are described according to their functions: coordinating nodes are used to generate tokens, and execution nodes are used to process messages. However, in reality, a node in the data cluster can be both a coordinating node and an execution node; or, a node in the data cluster can function only as a coordinating node or only as an execution node.
[0119] In another embodiment of the invention, a distributed lock can be used to determine a target node from multiple coordinating nodes to generate a token. A token generation cycle can be set for the coordination cluster, for example, every 1 minute or every 5 minutes. At the start of the token generation cycle, the node that acquires the distributed lock is designated as the target node, and the target node is used to generate the token. After completion, the distributed lock is released. At the start of the next cycle, the same method is used to determine the target node to generate the token. If the target node that acquires the distributed lock fails to generate the token, the distributed lock is released, and the remaining coordinating nodes that acquire the distributed lock generate the token. This process will not be described in detail.
[0120] In another embodiment of the present invention, multiple nodes are selected from the data cluster to generate tokens periodically. This avoids the situation where the token generation is interrupted due to the failure of a fixed node when it is selected to generate tokens, thereby reducing the possibility of token generation failure or interruption and improving the efficiency of token generation.
[0121] Understandably, the task of generating tokens is not complex; a small number of nodes can be selected from the data cluster as coordinating nodes. In one embodiment of the present invention, when selecting a target node from multiple coordinating nodes, a distributed lock is preferably used. This allows for the quick determination of a target node from multiple coordinating nodes, with that target node generating the token, ensuring the uniqueness of the generated token. Although a distributed lock is used, because the total number of coordinating nodes is small, and because the distributed lock only applies to the token generation process, other coordinating nodes that have not acquired the distributed lock can still act as execution nodes to process messages. Therefore, this does not result in excessive resource consumption and reduced message processing efficiency.
[0122] After determining a coordinating node for token generation, the number of tokens to be generated in each token generation cycle must also be determined. In another embodiment of the invention, the following method can be used: determine the number of tokens to be generated based on the current number of tokens in the token queue, the token control policy, and the number of storage shards; and use one or more coordinating nodes to generate the tokens based on the number of tokens to be generated.
[0123] The purpose of the token control strategy is to address the mismatch between the number of tokens generated and the number of tokens consumed.
[0124] Specifically, another embodiment of the present invention can be adopted in the following manner: the token control policy includes a first preset threshold and / or a second preset threshold, and the first preset threshold is less than the second preset threshold; the step of determining the number of tokens to be generated based on the current number of tokens in the token queue, the token control policy, and the number of storage shards includes: when the current number of tokens is less than the first preset threshold: determining the base number of tokens to be generated; determining the multiple of the number of tokens to be generated based on the current number of tokens, the first preset threshold, and the number of storage shards; and determining the number of tokens to be generated based on the base number and the multiple of the number.
[0125] The first and second preset thresholds in the token control policy can be estimated by the business system based on statistical data.
[0126] Understandably, when the current number of tokens is less than the first preset threshold, multiple times the number of tokens can be generated, and when the current number of tokens is greater than or equal to the second preset threshold, token generation can be stopped.
[0127] In one embodiment of the present invention, the token identifier corresponds to the storage shard identifier; that is, for M storage shards, the token identifier is an integer number from 1 to M. To ensure that each storage shard is acquired and processed by the cluster nodes, the base number of tokens to be generated can be determined to be the number of storage shards M. That is, for 200 storage shards, the base number of tokens to be generated is determined to be 200.
[0128] The multiple of tokens to be generated is determined by the rate of token consumption and generation. Tokens are consumed by the message processing nodes (execution nodes). To avoid the coordinating node generating tokens too frequently, the token generation cycle can be set to be longer than the message processing cycle, and a sufficient number of tokens can be generated in each generation cycle to ensure the required token consumption is met. This allows more resources from the coordinating node to be allocated to the message processing threads, improving the utilization of cluster resources.
[0129] For example, consider a data cluster with 200 storage shards (M) and 100 nodes (N). Three coordinating nodes are configured with token-generating threads. These threads generate tokens every minute, while the execution nodes generate tokens every 10 seconds. All 100 nodes in the cluster can act as execution nodes. Assuming each node consumes one token per generation, each node consumes 100 tokens every 10 seconds. Therefore, each node consumes 600 tokens per minute. This means the coordinating nodes must generate at least 600 tokens per minute to meet the token consumption requirements of the execution nodes. Since 600 tokens is three times the number of storage shards (200), the minimum number of tokens to be generated must be at least three.
[0130] For the aforementioned 600 tokens, their identifiers are integers from 1 to 200 repeated 3 times. That is, the token identifier sequence is (1, 2, 3…200, 1, 2, 3…200, 1, 2, 3…200).
[0131] As can be seen, in the above example, the multiple of the number of tokens to be generated is 3, ensuring a minimum number of tokens generated per minute. Alternatively, the multiple can be set to 4 or a higher number to ensure a sufficient number of tokens in the token queue. To make the number of generated tokens more reasonable and accurate, in one embodiment of the present invention, the following method is preferred to determine the number of tokens to be generated: calculating the multiple of the number of tokens to be generated based on the current number of tokens, the first preset threshold, and the number of storage shards; and determining the number of tokens to be generated based on the base number and the multiple.
[0132] Understandably, tokens are stored in a token queue, and at the start of each token generation cycle, the token queue typically contains a certain number of tokens, thus allowing us to determine the current token count. The number of storage shards can be obtained from a distributed configuration center by the coordinating node that generates the tokens.
[0133] For example, if the number of storage shards is M, the first preset threshold is X1, the current number of tokens is Y, and the quantity multiplier is S, it can be calculated using the formula: S = (X1 - Y) / M + 1. That is, (X1 - Y) is divided by M and rounded up. The base quantity is the number of storage shards M, and the number of tokens to be generated is Z, which can be expressed as: Z = M * S. The quantity multiplier uses rounding up to ensure that there are enough tokens in the token queue.
[0134] For example, with 200 storage shards, a first preset threshold of 600, and a current token count of 300, the multiple can be calculated as 2. The number of tokens to be generated is then 400. After storing the generated tokens in the token queue, the total number of tokens in the queue will be the current token count plus the generated token count, i.e., 400 + 300 = 700, ensuring that the total number of tokens in the queue is greater than the first preset threshold of 600. However, while the generated tokens are being stored in the token queue, the execution nodes are also continuously consuming tokens, so the total number of tokens in the queue may be close to 700 but not exactly equal to 700.
[0135] In one embodiment of the present invention, if the current number of tokens is greater than or equal to the second preset threshold, the number of tokens to be generated is determined to be zero. That is, the coordinating node does not generate tokens in this round of token generation.
[0136] For example, if the second preset threshold X2 is set to 1200, no tokens will be generated in this round if the current number of tokens is greater than or equal to 1200.
[0137] In one embodiment of the present invention, only a first preset threshold may be set, or the first preset threshold and the second preset threshold may be set to the same value. The first preset threshold is used as a safety threshold for the number of tokens. When the current number of tokens is less than the safety threshold, the same method is used to calculate the multiple to determine the number of tokens to be generated. When the current number of tokens is greater than or equal to the safety threshold, the number of tokens to be generated is zero, that is, no tokens are generated.
[0138] For example, in the above example, the first preset threshold is set to 1200, which is used as a security threshold. At the start of the token generation cycle, the current token quantity is 300, which is less than 1200. The base number of tokens is the number of storage shards, 200. The token multiplier S is (1200-300) divided by 200 and rounded up, which equals 5. Then the number of tokens to be generated is 5*200=1000. Adding the current token quantity of 300, the total number of tokens in the token queue is 1300, which exceeds the security threshold of 1200.
[0139] At the start of the next token generation cycle, if the current number of tokens is greater than or equal to the security threshold, no tokens will be generated in this round of token generation.
[0140] An early warning threshold can also be set. When the number of tokens is found to be less than the early warning threshold, an early warning message is sent through the coordinating node to facilitate subsequent analysis and troubleshooting.
[0141] In addition to setting the token generation cycle, the coordinating node can also use a round-robin approach to check the number of tokens in the token queue, and then determine whether to initiate the token generation operation based on the current number of tokens. Its token control strategy and the method of determining the number of tokens to be generated can be the same as those provided in step S201, and will not be repeated here.
[0142] After determining the number of tokens to be generated, one of the multiple coordinating nodes, the target node, generates the corresponding number of tokens and stores them in a token queue. The token's identifier corresponds to the identifier of the storage shard.
[0143] For example, if the number of storage shards is 200, the 600 tokens generated are a set of numbers from 1 to 200 repeated 3 times. These 600 tokens are then inserted into the token queue sequentially from the tail of the token queue in the order of (1, 2, 3…200, 1, 2, 3…200, 1, 2, 3…200).
[0144] In another embodiment of the present invention, during message processing, each execution node needs to extract a token from the token queue before performing message processing, and then execute subsequent message processing tasks based on the token's identifier. The execution node can extract the token using the following method provided in another embodiment of the present invention: using at least two execution nodes to extract the target token from the token queue; for each execution node: after processing the current target message, further including: extracting the target token from the token queue; and / or, further including: for each execution node: if the execution cycle is satisfied at the current time, extracting the target token from the token queue.
[0145] Understandably, since the token identifier corresponds to the storage shard identifier, each execution node, after retrieving the target token, can determine the identifier of the storage shard containing the message to be processed based on the token's identifier, and then extract the target message from the corresponding storage shard. For example, if the token identifier retrieved by the execution node is 50, then the execution node will extract the message from the storage shard with identifier 50 for processing.
[0146] The execution nodes of the data cluster can be configured with either a fixed or variable execution cycle. In another embodiment of the invention, a variable execution cycle is preferred, meaning that the execution cycle of the execution node is determined by the node's processing speed and the number of messages. After processing the messages retrieved in this iteration, the execution node can rest for a period of time before entering the next execution cycle. For multiple execution nodes in the data cluster, each node has its own cycle. Although the duration of these execution cycles is not significantly different, the start time of each node's execution cycle is sequential. This ensures that multiple execution nodes retrieve tokens from the token queue in a specific order within the same time period, thereby avoiding conflicts caused by multiple nodes accessing the token queue simultaneously.
[0147] Understandably, the identifiers of storage shards correspond to the identifiers of tokens. Tokens in the token queue are stored repeatedly according to the order of their storage shard identifiers. That is, if the number of tokens is twice the number of storage shards, the tokens in the token queue are stored in the order of their storage shard identifiers, repeated twice. Typically, the processing capabilities of multiple execution nodes are roughly the same, while the number of storage shards is k times the number of execution nodes. This ensures that multiple execution nodes retrieve different token identifiers within the same time period, thus corresponding to different storage shards. This avoids multiple execution nodes processing the same storage shard simultaneously, thereby preventing the use of distributed locks for collaborative processing and avoiding a situation where most cluster nodes are waiting. This improves the utilization of cluster nodes and ultimately increases message processing efficiency.
[0148] To ensure that retrieving a token from the token queue is an atomic operation, the token queue can use a Redis list structure or a message queue. In one embodiment of the present invention, a Redis list structure is preferred. Each token is removed from the token queue after being retrieved by an execution node, ensuring that multiple execution nodes retrieve different tokens sequentially according to the storage order of the token queue.
[0149] After the target token is extracted at each node, the target message can be extracted from the target storage shard corresponding to the target token using the following method provided in another embodiment of the present invention: the target message is extracted from the target storage shard according to the order of at least two messages to be processed stored on the target storage shard; wherein the difference between the processing time of the target message and the current time is less than or equal to a preset time threshold.
[0150] Understandably, the number of nodes in a data cluster is typically set based on the magnitude of the messages to be processed to ensure message handling. Therefore, under normal operating conditions, the difference between the message's pending processing time and the current time is usually greater than or equal to 0. This means the message's pending processing time is greater than or equal to the current time, and the message needs to be processed at or after the current time. In this case, a preset time threshold is set, and messages whose pending processing time is less than or equal to this threshold are extracted. These messages are then used as target messages and processed by the execution nodes. For example, setting the preset time threshold to 1 minute, target messages whose pending processing time is less than or equal to 1 minute are extracted from the target storage shard and processed sequentially according to the order in which they are extracted.
[0151] For example, in a message push system, each message has a push timeframe, which can be preset to a 1-minute threshold. When using a sorted set (zset) to store messages, retrieving these target messages is relatively simple. The zset sorting command can return multiple members (i.e., multiple messages) whose score is less than or equal to a preset processing time. The preset processing time is the current time plus one minute. For example, if the current time is 12:00, the preset processing time is the current time plus one minute, which is 12:01. Therefore, members with a score less than 12:01 and / or members with a score equal to 12:01 are all target messages.
[0152] In one embodiment of the present invention, message processing typically allows for a certain error processing time. Messages only need to be processed within a certain time range. Therefore, a preset time threshold can be set to zero, so the processing time of the target message can be less than or equal to the current time. Even if there are messages at or before the current time, these messages will be processed quickly due to the frequent execution by cluster nodes (multiple times per minute). It is acceptable for messages to be processed within a certain error range before or after the processing time. For example, when using a zset collection, if the current time is 12:00, then members with a score value less than 12:00 and / or members with a score value equal to 12:00 are considered target messages.
[0153] After extracting the target message, the execution node processes it according to the order of its pending time and the specific content of the message. For example, if it is a delayed push message, the message is pushed to the recipient's device sequentially according to the push time and the recipient information in the message.
[0154] Of course, in rare cases, the difference between the pending time of a message and the current time may be negative and have a large absolute value. In other words, there may be messages that have been overdue for a long time without being processed. A monitoring thread can be set up so that when the difference is negative and the absolute value exceeds a certain set threshold, the monitoring thread can issue an abnormal prompt message to remind humans to analyze and deal with it in a timely manner.
[0155] In one embodiment of the present invention, when obtaining a message, it can also be determined whether the message's processing time is within one day or one day later. Messages to be processed within one day are stored in storage shards, while messages to be processed one day later are stored in other storage media. After a certain period of time, these messages to be processed one day later are stored from the storage media to the storage shards. This can avoid storing too many messages in the storage shards.
[0156] After the execution node retrieves the target message, it can copy the target message from the storage shard to the execution node's memory. After the execution node has processed all the target messages in memory, it deletes the processed target messages from the storage shard. This method of processing before deleting can avoid message loss due to failures in the execution node during message processing.
[0157] When there are many target messages, to reduce frequent interactions between the execution node and the storage shards, the execution node can copy a certain number of target messages to its memory for processing. After the target messages in memory are processed, another certain number of target messages are copied for processing, that is, processing is performed in multiple stages. For example, in a message push system, when there are many target messages, the execution node can copy only the first 50 target messages to memory for push at a time, and then copy the next 50 messages after that, until all target messages have been processed.
[0158] Of course, there may be situations where an execution node suddenly fails during processing. For example, if 20 out of 50 target messages have been processed, and 30 remain unprocessed, the intermediate file saved before the failure can be used. This intermediate file records the information of the processed target messages and the identifier of the storage shard they belong to. The 20 processed target messages can be deleted from the corresponding storage shard, while the 30 unprocessed messages will remain unprocessed and continue to be stored in the storage shard, waiting for other execution nodes to retrieve and process them.
[0159] Alternatively, a fixed execution cycle can be adopted, such as each execution node executing once every 20 seconds, and each time a token is extracted according to the fixed execution cycle. That is, the execution node extracts a token from the token queue once at the beginning of the fixed execution cycle, and then extracts a token from the token queue again at the beginning of the next fixed cycle.
[0160] Understandably, when there are too many target messages, at the start of a new execution cycle, the execution node may be processing the target messages extracted in the previous execution cycle. To ensure the continuity of message processing, the execution node may not extract tokens at the start of the current cycle, and will extract new tokens only after all the target messages in the previous cycle have been processed.
[0161] In one embodiment of the present invention, a non-fixed execution cycle is preferably adopted. A maximum processing count can be set for each execution node in each execution cycle. When the number of target messages is less than or equal to the maximum processing count, the execution node can process all target messages, rest for a certain period after processing, and then enter the next execution cycle. When the number of target messages exceeds the maximum processing count, the execution node only extracts a portion of the target messages equal to the maximum processing count for processing, rests for a certain period after processing, and then enters the next execution cycle. The maximum processing count can be estimated based on business statistics and historical processing data of the cluster nodes.
[0162] The duration of the variable execution period depends on the number of target messages and the processing capacity of the execution nodes. Using a variable execution period avoids situations where execution nodes are idle and waiting when there are few target messages and the period is long, and also avoids situations where messages cannot be processed when there are many target messages and the period is insufficient. Setting a maximum processing number prevents execution nodes from processing a single storage shard for an extended period, thus ensuring that messages on each storage shard have roughly equal opportunities to be processed.
[0163] For example, in a message processing system, a maximum processing limit of 100 can be set, with each execution node processing a maximum of 100 messages per cycle. When the target number of messages to be extracted is 60, the execution node processes all 60 messages, then waits for 1 or 2 seconds before entering the next execution cycle. When the target number of messages to be extracted is 200, the execution node only processes the first 100 messages, waits for 1 or 2 seconds after processing, and then enters the next execution cycle to extract new tokens.
[0164] When the number of target messages is small, the execution cycle may be completed in 10 seconds, while when the number of target messages is large, it may take 20 seconds to complete an execution cycle.
[0165] It is understandable that since different execution nodes have different processing capabilities and the number of target messages extracted is also not exactly the same, the execution cycles of different execution nodes are also different. By setting the maximum processing number, the time of the execution cycle can be estimated. Although the duration of the execution cycle is not fixed, the number of tokens consumed by the execution node and the number of tokens to be generated can still be estimated based on the average value or the maximum value of the execution cycles of multiple execution nodes.
[0166] It is understandable that after an execution node extracts a token, it can determine the storage shard according to the token identifier, and then process the messages in the storage shard. It does not need to cooperate with other nodes in the cluster, reducing the situation of resource conflicts and also reducing the waiting or idle time of the execution node. Moreover, the execution node only needs to decide when to extract tokens according to the progress of its own message processing or its own cycle, improving the independence of the nodes in the data cluster and thus improving the processing ability of the cluster nodes.
[0167] When the number of messages obtained in a certain period is relatively large, if the current processing capacity of the cluster cannot meet the messages of the current order of magnitude, the nodes of the data cluster can be dynamically increased to expand the number of cluster nodes. The newly added cluster nodes can directly obtain tokens from the token queue and process messages, without affecting the message processing process of the existing cluster nodes, improving the dynamic expansion ability of the cluster.
[0168] The following combines Figure 3 and Figure 4 , and a message processing method provided by an embodiment of the present invention will be described in detail by taking the process of processing delayed messages in a Redis-based data cluster as an example.
[0169] Figure 3 FIG. is a schematic structural diagram of a data cluster for processing messages provided by an embodiment of the present invention. In this data cluster, the number of nodes is N. Among these N nodes, all N nodes can be used as execution nodes, and N1 nodes can be used as coordination nodes (N1 < N). The process of processing delayed messages in this data cluster can be as shown in the steps of Figure 4 as follows:
[0170] Step S401: Calculate the number of storage shards M according to the number of nodes N in the data cluster and the processing performance k of the cluster.
[0171] Where M = N * k, and k is an integer greater than or equal to 2. Store M in the configuration center for subsequent acquisition by nodes.
[0172] S402: Store multiple delayed messages in the message queue into M storage shards.
[0173] For M storage shards, Redis's sorted sets (zsets) are used for storage. M zset collections are created, with each zset's key corresponding to a storage shard identifier. The identifier of the delayed message is hashed and modulo M to determine the corresponding storage shard identifier, which also determines the zset's key. Based on the delayed message's pending processing time, this time is used as the zset's score, and the message's content is stored in the member corresponding to that score.
[0174] S403: Determine a target node from N1 coordinating nodes to generate the token.
[0175] A distributed lock mechanism is used to determine one node from N1 coordinating nodes that has acquired the distributed lock, and this node is used as the target node for generating tokens.
[0176] S404: Generate the corresponding number of tokens based on the token control policy, the number of storage shards M, and the current number of tokens in the token queue.
[0177] The number of tokens Z to be generated is usually a multiple of the storage shard M. The identifiers of these Z tokens are the result of repeating the identifiers from 1 to M multiple times. Z is (1, 2, 3…M, 1, 2, 3…M, 1, 2, 3…M, 1, 2, 3…M, 1, 2, 3…M…).
[0178] S405: Store the generated token in the token queue.
[0179] The token queue is preferably implemented using Redis's list structure. In a Redis list structure, both enqueueing and dequeueing are atomic operations, ensuring that each token is acquired by only one execution node. This eliminates distributed coordination issues and avoids the resource consumption problems associated with using distributed locks.
[0180] S406: N execution nodes sequentially retrieve tokens from the token queue according to their own cycles.
[0181] The token's identifier corresponds to the identifier of the storage shard.
[0182] S407: The execution nodes extract the target delay message from the corresponding storage shard based on the token identifier they extracted.
[0183] like Figure 3As shown, if the token identifier extracted by execution node 1 is 1, then the identifier of the corresponding storage shard is 1, and the key value of the zset set is 1. Execution node 1 then extracts the target delayed message from the zset set with key value 1. If the token identifier extracted by execution node N is 2, then the identifier of the corresponding storage shard is 2, and the key value of the zset set is 2. Execution node N then extracts the target delayed message from the zset set with key value 2.
[0184] A preset time threshold can be set, and delayed messages whose difference between the pending time and the current time is less than or equal to the preset time threshold can be used as target delayed messages.
[0185] S408: The execution node processes the extracted target delayed messages according to the order of their pending times.
[0186] To ensure reasonable execution cycle times and efficient cluster node processing, a maximum processing capacity is set for the execution nodes of the data cluster, and the number of delayed messages processed in each execution cycle does not exceed the maximum processing capacity.
[0187] The execution cycle of each execution node is not fixed. Once each execution node has completed processing no more than the maximum number of delayed messages, it immediately rests for a period of time before entering the next execution cycle. Each execution node has its own execution cycle, which can efficiently utilize the processing capacity of the execution nodes, reduce the idle time of the execution nodes, and improve the processing efficiency of the data cluster.
[0188] After all target delayed messages are completed, the execution node sends a batch deletion request to the corresponding zset set to remove the target delayed messages from the zset set, and waits for the next execution cycle to start before retrieving the token and processing the delayed messages.
[0189] According to an embodiment of the present invention, a message processing method utilizes an execution node that has extracted a target token to process target messages on a storage shard. Thus, while one execution node is processing a message, other execution nodes can still extract other target tokens to process other target messages corresponding to those extracted tokens. In other words, multiple execution nodes can process different target messages simultaneously by extracting different target tokens, thereby eliminating the need for a distributed lock for message processing. This avoids the situation where only the node that acquires the distributed lock can execute the message processing task, while other cluster nodes are in a waiting state because they have not acquired the distributed lock. This improves the utilization rate of the data cluster nodes and also increases message processing efficiency.
[0190] Furthermore, determining the number of tokens generated based on the processing performance of the data cluster nodes can reduce the idle time of the cluster nodes and improve their efficiency. Additionally, cluster nodes can determine the frequency of token extraction based on their own workload and / or execution cycle, reducing resource conflicts within the data cluster and improving the independence of task execution for each cluster node. The mapping between token identifiers and storage shard identifiers ensures that multiple storage shards can be processed by the cluster nodes, thus ensuring that adding or removing nodes in the cluster does not affect the message processing flow and increases the cluster's dynamic scalability.
[0191] like Figure 5 As shown, this embodiment of the invention provides a message processing device 500, applied to an execution node in a data cluster, including: an extraction module 501 and a processing module 502; wherein,
[0192] The extraction module 501 is used to extract a target token from the token queue in response to a message processing request. The target identifier of the target token corresponds to the identifier of the storage shard storing the message to be processed. The token queue includes multiple tokens generated by the coordinating node in the data cluster.
[0193] The processing module 502 is used to extract target messages from the target storage shard corresponding to the target token according to the target identifier of the target token, and to process the target messages.
[0194] In one embodiment of the present invention, the extraction module 501 is used to extract the target token from the token queue after processing the current target message.
[0195] In one embodiment of the present invention, the extraction module 501 is used to extract a target token from the token queue when the execution cycle is met at the current time.
[0196] In one embodiment of the present invention, the processing module 502 is used to determine that the message to be processed indicates a processing time; at least two messages to be processed are ordered in the storage shard according to the order of the processing time.
[0197] In one embodiment of the present invention, the processing module 502 is used to extract the target message from the target storage segment according to the order of at least two messages to be processed stored on the target storage segment; wherein the difference between the processing time of the target message and the current time is less than or equal to a preset time threshold.
[0198] In one embodiment of the present invention, the processing module 502 is configured to acquire at least two messages to be processed; and store the at least two messages to be processed in at least two storage shards of the data cluster according to the message identifier of the messages to be processed.
[0199] In one embodiment of the present invention, the processing module 502 is used to determine the number of the at least two storage shards based on the number of nodes in the data cluster and the processing performance of the nodes, and the number of the at least two storage shards is greater than the number of nodes in the data cluster.
[0200] In one embodiment of the present invention, the processing module 502 is configured to perform a hash operation on the message identifier of the message to be processed, perform a modulo operation on the number of storage shards based on the hash operation result, determine the storage shard to which the message to be processed is to be stored based on the modulo operation result, and store the message to be processed in the determined storage shard.
[0201] like Figure 6 As shown, this embodiment of the invention provides a message processing system, including a coordinating node 601 and an execution node 602; wherein,
[0202] The coordinating node 601 is used to generate tokens using one or more coordinating nodes and store them in a token queue; the identifier of the token corresponds to the identifier of the storage shard containing the message to be processed.
[0203] The execution node 602 is used to extract a target token from the token queue using at least two execution nodes; for the execution node that has extracted the target token: according to the target identifier of the target token, extract the target message from the target storage segment corresponding to the target token, and process the target message.
[0204] In one embodiment of the present invention, reference continues to be made to... Figure 6 This invention provides a message processing system 600, which may further include a storage node 603; the storage node 603 is used to obtain at least two messages to be processed using the storage nodes in the data cluster; and to store the at least two messages to be processed in at least two storage shards of the data cluster according to the message identifiers of the messages to be processed.
[0205] In one embodiment of the present invention, the storage node 603 is used to determine the number of the at least two storage shards based on the number of nodes in the data cluster and the processing performance of the nodes, and the number of the at least two storage shards is greater than the number of nodes in the data cluster.
[0206] In one embodiment of the present invention, the storage node 603 is used to determine that the message to be processed indicates a processing time; at least two messages to be processed are ordered in the storage shard according to the order of their processing times.
[0207] In one embodiment of the present invention, the storage node 603 is configured to perform a hash operation on the message identifier of the message to be processed, perform a modulo operation on the number of storage shards based on the hash operation result, determine the storage shard to which the message to be processed is to be stored based on the modulo operation result, and store the message to be processed in the determined storage shard.
[0208] In one embodiment of the present invention, the coordinating node 601 is used to determine the number of tokens to be generated based on the current number of tokens in the token queue, the token control policy, and the number of storage shards; and to generate the tokens using one or more coordinating nodes based on the number of tokens to be generated.
[0209] In one embodiment of the present invention, the coordination node 601 is configured to: define a token control policy including a first preset threshold and / or a second preset threshold, wherein the first preset threshold is less than the second preset threshold; and determine the number of tokens to be generated based on the current number of tokens in the token queue, the token control policy, and the number of storage shards, comprising: when the current number of tokens is less than the first preset threshold: determining a base number of tokens to be generated; determining a multiple of the number of tokens to be generated based on the current number of tokens, the first preset threshold, and the number of storage shards; and determining the total number of tokens to be generated based on the base number and the multiple of the number.
[0210] In one embodiment of the present invention, the coordinating node 601 is used to determine that the number of tokens to be generated is zero when the current number of tokens is greater than or equal to the second preset threshold.
[0211] In one embodiment of the present invention, the coordinating node 601 is configured to determine multiple nodes from the data cluster as the coordinating nodes and configure a thread for generating tokens for the coordinating nodes; determine a target node from the multiple coordinating nodes and generate the token using the thread on the target node.
[0212] In one embodiment of the present invention, the coordinating node 601 is configured to, in the event that the target node fails to generate a token, re-determine the target node from other coordinating nodes besides the target node, and generate the token using the thread on the re-determined target node.
[0213] In one embodiment of the present invention, the execution node 602 is configured to, for each execution node, after processing the current target message, further include: extracting the target token from the token queue.
[0214] In one embodiment of the present invention, the execution node 602 is configured to, for each execution node, extract a target token from the token queue if the execution cycle is satisfied at the current time.
[0215] In one embodiment of the present invention, the execution node 602 is used to extract the target message from the target storage segment according to the order of at least two messages to be processed stored on the target storage segment; wherein the difference between the processing time of the target message and the current time is less than or equal to a preset time threshold.
[0216] According to an embodiment of the present invention, a message processing system generates tokens through a coordinating node in a data cluster, and uses the execution node that extracts the target token to process target messages on a storage shard. Thus, while one execution node is processing a message, other execution nodes can still extract other target tokens to process other target messages corresponding to the extracted target tokens. In other words, multiple execution nodes can process different target messages simultaneously by extracting different target tokens, thereby eliminating the need for a distributed lock for message processing. This avoids the situation where only the node that acquires the distributed lock can execute the message processing task, while other cluster nodes are in a waiting state because they have not acquired the distributed lock. This improves the utilization rate of data cluster nodes and also increases message processing efficiency.
[0217] Furthermore, determining the number of tokens generated based on the processing performance of the data cluster nodes can reduce the idle time of the cluster nodes and improve their efficiency. Additionally, cluster nodes can determine the frequency of token extraction based on their own workload and / or execution cycle, reducing resource conflicts within the data cluster and improving the independence of task execution for each cluster node. The mapping between token identifiers and storage shard identifiers ensures that multiple storage shards can be processed by the cluster nodes, thus ensuring that adding or removing nodes in the cluster does not affect the message processing flow and increases the cluster's dynamic scalability.
[0218] Figure 7 An exemplary system architecture 700 is shown, in which an embodiment of the present invention can be applied to a message processing method or a message processing apparatus.
[0219] like Figure 7As shown, system architecture 700 may include terminal devices 701, 702, and 703, a network 704, and a server 705. Network 704 serves as the medium for providing communication links between terminal devices 701, 702, and 703 and server 705. Network 704 may include various connection types, such as wired or wireless communication links, or fiber optic cables, etc.
[0220] Users can use terminal devices 701, 702, and 703 to interact with server 705 via network 704 to receive or send messages, etc.
[0221] Terminal devices 701, 702, and 703 can be various electronic devices with displays that support information browsing, including but not limited to smartphones, tablets, laptops, and desktop computers.
[0222] Server 705 can be a server that provides various services, such as a background management server that supports message processing requests made by users using terminal devices 701, 702, and 703. The background management server can analyze and process received messages and other data, and send the messages back to the terminal devices according to their pending processing time.
[0223] It should be noted that the message processing method provided in the embodiments of the present invention is generally executed by server 705, and correspondingly, the message processing device is generally set in server 705.
[0224] It should be understood that Figure 7 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.
[0225] The following is for reference. Figure 8 It shows a schematic diagram of the structure of a computer system 800 suitable for implementing a terminal device of the present invention. Figure 8 The terminal device shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of the present invention.
[0226] like Figure 8 As shown, the computer system 800 includes a central processing unit (CPU) 801, which can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) 802 or programs loaded from storage section 808 into random access memory (RAM) 803. The RAM 803 also stores various programs and data required for the operation of the system 800. The CPU 801, ROM 802, and RAM 803 are interconnected via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0227] The following components are connected to I / O interface 805: an input section 806 including a keyboard, mouse, etc.; an output section 807 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 808 including a hard disk, etc.; and a communication section 809 including a network interface card such as a LAN card, modem, etc. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to I / O interface 805 as needed. A removable medium 811, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on drive 810 as needed so that computer programs read from it can be installed into storage section 808 as needed.
[0228] In particular, according to the embodiments disclosed in this invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 809, and / or installed from removable medium 811. When the computer program is executed by central processing unit (CPU) 801, it performs the functions defined above in the system of this invention.
[0229] It should be noted that the computer-readable medium shown in this invention can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this invention, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.
[0230] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0231] The modules described in the embodiments of the present invention can be implemented in software or hardware. The described modules can also be housed in a processor; for example, a processor may be described as including an extraction module and a processing module. The names of these modules do not necessarily limit the module itself; for example, an extraction module may also be described as a "token extraction module."
[0232] In another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiments; or it may exist independently and not assembled into the device. The computer-readable medium carries one or more programs that, when executed by the device, cause the device to include: in response to a message processing request, retrieving a target token from a token queue, wherein the target token's target identifier corresponds to an identifier of a storage shard storing a message to be processed; the token queue includes multiple tokens generated by a coordinating node in a data cluster; retrieving a target message from the target storage shard corresponding to the target token based on the target identifier of the target token, and processing the target message.
[0233] According to the technical solution of this invention, the execution node that has extracted the target token processes the target message on the storage shard. Therefore, while one execution node is processing a message, other execution nodes can still extract other target tokens to process other target messages corresponding to those extracted tokens. In other words, multiple execution nodes can process different target messages simultaneously by extracting different target tokens, thus eliminating the need for a distributed lock for message processing. This avoids the situation where only the node that acquires the distributed lock can execute the message processing task, while other cluster nodes are in a waiting state because they have not acquired the distributed lock. This improves the utilization rate of the data cluster nodes and also increases message processing efficiency.
[0234] Furthermore, determining the number of tokens generated based on the processing performance of the data cluster nodes can reduce the idle time of the cluster nodes and improve their efficiency. Additionally, cluster nodes can determine the frequency of token extraction based on their own workload and / or execution cycle, reducing resource conflicts within the data cluster and improving the independence of task execution for each cluster node. The mapping between token identifiers and storage shard identifiers ensures that multiple storage shards can be processed by the cluster nodes, thus ensuring that adding or removing nodes in the cluster does not affect the message processing flow and increases the cluster's dynamic scalability.
[0235] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A message processing method, characterized in that, Execution nodes used in data clusters include: In response to a message processing request, a target token is extracted from the token queue. The target identifier of the target token corresponds to the identifier of the storage shard storing the message to be processed. The token queue includes multiple tokens generated by the coordinating node in the data cluster. The number of execution nodes is greater than the number of coordinating nodes. The coordinating node generates multiple tokens according to the number of tokens required to be generated in each token generation cycle. Based on the target identifier of the target token, the target message is extracted from the target storage segment corresponding to the target token, and the target message is processed; the target message is a delayed message. It also includes: extracting the target token from the token queue when the execution cycle is met at the current time; wherein the token generation cycle is longer than the message processing cycle.
2. The method according to claim 1, characterized in that, Also includes: Retrieve at least two pending messages; Based on the message identifier of the message to be processed, at least two of the messages to be processed are stored in at least two storage shards of the data cluster.
3. The method according to claim 1, characterized in that, After processing the current target message, the process also includes: retrieving the target token from the token queue.
4. The method according to claim 2, characterized in that, The number of at least two storage shards is determined based on the number of nodes in the data cluster and the processing performance of the nodes, and the number of at least two storage shards is greater than the number of nodes in the data cluster.
5. The method according to claim 2, characterized in that, The pending message indicates the pending time; at least two of the pending messages are ordered in the storage segment according to the order of the pending time. Extracting the target message from the target storage shard corresponding to the target token includes: The target message is extracted from the target storage segment according to the order of at least two messages to be processed stored on the target storage segment; wherein the difference between the processing time of the target message and the current time is less than or equal to a preset time threshold.
6. The method according to claim 2, characterized in that, The step of storing at least two messages to be processed into at least two storage shards of the data cluster according to the message identifier of the message to be processed includes: Perform a hash operation on the message identifier of the message to be processed, and perform a modulo operation on the number of storage fragments based on the hash operation result; The storage segment to be stored for the message to be processed is determined based on the result of the modulo operation. The message to be processed is stored in the determined storage segment.
7. A message processing method, characterized in that, Applied to data clusters, including: One or more coordinating nodes are used to generate tokens and store them in a token queue; the identifier of the token corresponds to the identifier of the storage shard containing messages to be processed; wherein the number of execution nodes is greater than the number of coordinating nodes; the coordinating nodes generate multiple tokens according to the number of tokens to be generated in each token generation cycle; The target token is extracted from the token queue using at least two execution nodes; For the execution node where the target token has been extracted: based on the target identifier of the target token, extract the target message from the target storage shard corresponding to the target token, and process the target message; the target message is a delayed message; It also includes: extracting the target token from the token queue when the execution cycle is met at the current time; wherein the token generation cycle is longer than the message processing cycle.
8. The method according to claim 7, characterized in that, Also includes: Retrieve at least two pending messages; Based on the message identifier of the message to be processed, at least two of the messages to be processed are stored in at least two storage shards of the data cluster.
9. The method according to claim 7, characterized in that, For each execution node: after processing the current target message, the method further includes: retrieving the target token from the token queue; And / or, It also includes: for each of the execution nodes: if the execution cycle is met at the current time, extract the target token from the token queue.
10. The method according to claim 8, characterized in that, The number of at least two storage shards is determined based on the number of nodes in the data cluster and the processing performance of the nodes, and the number of at least two storage shards is greater than the number of nodes in the data cluster.
11. The method according to claim 8, characterized in that, The pending message indicates the pending time; at least two of the pending messages are ordered in the storage segment according to the order of the pending time. Extracting the target message from the target storage shard corresponding to the target token includes: The execution node extracts the target message from the target storage segment according to the order of at least two messages to be processed stored on the target storage segment; wherein the difference between the processing time of the target message and the current time is less than or equal to a preset time threshold.
12. The method according to claim 7, characterized in that, The generation of tokens using one or more coordinating nodes includes: The number of tokens to be generated is determined based on the current number of tokens in the token queue, the token control policy, and the number of storage shards. The tokens are generated using one or more coordinating nodes based on the number of tokens to be generated.
13. The method according to claim 12, characterized in that, The token control policy includes a first preset threshold and / or a second preset threshold, wherein the first preset threshold is less than the second preset threshold; The step of determining the number of tokens to be generated based on the current number of tokens in the token queue, the token control policy, and the number of storage shards includes: If the current number of tokens is less than the first preset threshold: determine the base number of tokens to be generated; determine the multiple of the number of tokens to be generated based on the current number of tokens, the first preset threshold, and the number of storage shards; determine the number of tokens to be generated based on the base number and the multiple. And / or, If the current number of tokens is greater than or equal to the second preset threshold, the number of tokens to be generated is determined to be zero.
14. The method according to claim 12, characterized in that, The method of generating tokens using one or more coordinating nodes also includes: Multiple nodes are identified from the data cluster as the coordinating nodes, and threads for generating tokens are configured for the coordinating nodes; The target node is determined from the plurality of coordinating nodes, and the token is generated using the thread on the target node.
15. The method according to claim 14, characterized in that, Also includes: If the target node fails to generate a token, a new target node is determined from other coordinating nodes besides the target node, and the token is generated using the thread on the newly determined target node.
16. The method according to claim 8, characterized in that, The step of storing at least two messages to be processed into at least two storage shards of the data cluster according to the message identifier of the message to be processed includes: Perform a hash operation on the message identifier of the message to be processed, and perform a modulo operation on the number of storage fragments based on the hash operation result; The storage segment to be stored for the message to be processed is determined based on the result of the modulo operation. The message to be processed is stored in the determined storage segment.
17. A message processing device, characterized in that, The execution nodes used in the data cluster include: an extraction module and a processing module; among which, The extraction module is used to extract a target token from the token queue in response to a message processing request. The target identifier of the target token corresponds to the identifier of the storage shard storing the message to be processed. The token queue includes multiple tokens generated by the coordinating nodes in the data cluster. The number of execution nodes is greater than the number of coordinating nodes. The coordinating nodes generate multiple tokens according to the number of tokens to be generated in each token generation cycle. The message to be processed is a delayed message. The processing module is used to extract target messages from the target storage shard corresponding to the target token according to the target identifier of the target token, and to process the target messages; The extraction module is further configured to: extract a target token from the token queue when the execution cycle is met at the current time; wherein the token generation cycle is longer than the message processing cycle.
18. A message processing system, characterized in that, include: The coordinating node is used to: generate tokens and store them in a token queue; The token identifier corresponds to the identifier of the storage shard containing the message; wherein, the number of execution nodes is greater than the number of coordination nodes; the coordination node generates multiple tokens according to the number of tokens required for each token generation cycle; An execution node is configured to: extract a target token from the token queue when the execution cycle is met at the current time; extract a target message from the target storage shard corresponding to the target token according to the target identifier of the target token, and process the target message; the target message is a delayed message; wherein the token generation cycle is longer than the message processing cycle.
19. The system according to claim 18, characterized in that, Also includes: Storage nodes are used to: retrieve at least two messages to be processed using execution nodes in the data cluster; Based on the message identifier of the message to be processed, at least two of the messages to be processed are stored in at least two storage shards of the data cluster.
20. A message processing server, characterized in that, include: One or more processors; Storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any one of claims 1-16.
21. A computer-readable medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1-16.
Citation Information
Patent Citations
Memory cluster storage balancing method and device
CN106909556A
Delay message processing method and device, computer equipment and storage medium
CN110636130A
Method, system and device for limiting bandwidth in distributed storage and medium
CN111708482A
Message processing method and device
CN112948138A