Flow scheduling method and device for redis cluster and electronic equipment
By introducing preset proxy middleware and traffic scheduling policies into the redis cluster, request scheduling is performed according to response priority and node load, the problem of degradation in the service quality of the redis cluster in the existing technology is solved, and efficient service quality assurance is achieved.
Patent Information
- Application Number
- CN202410989586.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-23
- Publication Date
- 2024-12-03
AI Technical Summary
The existing redis cluster cannot effectively guarantee the QoS service quality, especially when the data volume increases and the access load increases, the stand-alone redis cannot meet the needs, and the existing cluster cannot effectively schedule user requests of different priority levels, resulting in a decline in service quality. .
Use preset proxy middleware to receive user requests and schedule according to the target response priority (high, medium, and low). The request is scheduled to the corresponding request queue through the traffic scheduling policy, and load balancing is performed between master and slave nodes, according to the node The load condition adjusts the time limit and node selection of requests, creates a detection thread to monitor node load, and adjusts the scheduling time of priority requests.
Timely scheduling of user requests at different response priority levels is realized, the service quality of the entire redis cluster is ensured, and the response efficiency and stability of the cluster are improved through load monitoring and dynamic adjustment strategies.
Smart Images

Figure CN119065830A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of databases, and in particular to a traffic scheduling method, device and electronic device for a redis cluster. Background Art
[0002] In the database field, redis (remote dictionary server) is a distributed database solution that implements data sharing through data sharding and replication. In the application of redis, with the increase of data volume and access load, single-machine redis can no longer meet the demand. Usually, a redis cluster is built to meet the sharp increase in data volume and access requirements. However, the existing redis cluster cannot guarantee the quality of service (QoS). Summary of the invention
[0003] In view of this, an embodiment of the present application provides a traffic scheduling method, device and electronic device for a redis cluster to ensure the service quality QoS of the redis cluster.
[0004] In a first aspect, an embodiment of the present application provides a traffic scheduling method for a redis cluster, wherein the method is applied to a redis cluster, the redis cluster at least comprising: a preset proxy middleware, and a plurality of shards, each of the shards comprising a master node and a plurality of slave nodes, the method comprising:
[0005] Utilizing the preset proxy middleware to receive a user request sent by a target user, and obtaining a target response priority of the target user, wherein the response priority includes: high priority, medium priority, and low priority;
[0006] The preset proxy middleware is used to schedule the user request according to a preset traffic scheduling strategy in combination with the target response priority, wherein the preset traffic scheduling strategy is determined based on the target response priority.
[0007] Optionally, the using the preset proxy middleware to schedule the user request according to a preset traffic scheduling strategy in combination with the target response priority includes:
[0008] If the target response priority is high priority, the user request is scheduled to a high priority request queue, wherein both the read request and the write request in the high priority request queue are scheduled to the target master node;
[0009] Execution time exceeding a preset time quota is allocated to requests in the high priority request queue.
[0010] Optionally, the using the preset proxy middleware to schedule the user request according to a preset traffic scheduling strategy in combination with the target response priority includes:
[0011] If the target response priority is medium priority, the user request is dispatched to the medium priority request queue;
[0012] Obtain the load condition of the target master node and the load condition of each slave node corresponding to the target master node. If the load condition of the target master node is idle, schedule both the write request and the read request in the medium priority request queue to the target master node;
[0013] If the load condition of the target master node is non-idle, the write requests in the medium priority request queue are scheduled to the target master node, and the read requests in the medium priority request queue are scheduled to the target slave node, wherein the target slave node is the slave node with the lowest load of the target master node;
[0014] An execution time less than a preset time quota is allocated to the requests in the medium priority request queue.
[0015] Optionally, the using the preset proxy middleware to schedule the user request according to a preset traffic scheduling strategy in combination with the target response priority includes:
[0016] After a preset delay time, the write request in the user request is scheduled to the target master node, and the read request in the user request is scheduled to the slave node corresponding to the target master node.
[0017] Optionally, the method further includes:
[0018] Using the preset proxy middleware to create a detection thread, the detection thread detects the processes and CPU core usage of each master node and the slave nodes corresponding to each master node according to a preset detection cycle;
[0019] Based on the detection results output by the detection thread, the load condition of each node is determined.
[0020] Optionally, the method further includes:
[0021] The load condition of the preset proxy middleware is obtained. If the load of the preset proxy middleware exceeds a preset load threshold, the scheduling time of the high priority and medium priority requests is increased, and the scheduling time of the low priority request is decreased.
[0022] Optionally, after increasing the scheduling time of the high-priority and medium-priority requests and decreasing the scheduling time of the low-priority requests, the method further includes:
[0023] If the load of the preset proxy middleware still exceeds the preset load threshold, the scheduling time of the high priority request is increased again, and the scheduling time of the medium priority and the low priority request is decreased.
[0024] In a second aspect, an embodiment of the present application provides a traffic scheduling device for a redis cluster, wherein the device is applied to a redis cluster, the redis cluster at least includes: a preset proxy middleware, a plurality of shards, each of the shards is composed of a master node and a plurality of slave nodes, and the device includes:
[0025] A traffic scheduling module, wherein the traffic scheduling module includes the preset proxy middleware, which is used to receive a user request sent by a target user and obtain a target response priority of the target user, wherein the response priority includes: high priority, medium priority and low priority, and the user request is scheduled according to a preset traffic scheduling strategy combined with the target response priority, wherein the preset traffic scheduling strategy is determined based on the target response priority.
[0026] Optionally, the using the preset proxy middleware to schedule the user request according to a preset traffic scheduling strategy in combination with the target response priority includes:
[0027] If the target response priority is high priority, the user request is scheduled to a high priority request queue, wherein both the read request and the write request in the high priority request queue are scheduled to the target master node;
[0028] Execution time exceeding a preset time quota is allocated to requests in the high priority request queue.
[0029] Optionally, the using the preset proxy middleware to schedule the user request according to a preset traffic scheduling strategy in combination with the target response priority includes:
[0030] If the target response priority is medium priority, the user request is dispatched to the medium priority request queue;
[0031] Obtain the load condition of the target master node and the load condition of each slave node corresponding to the target master node. If the load condition of the target master node is idle, schedule both the write request and the read request in the medium priority request queue to the target master node;
[0032] If the load condition of the target master node is non-idle, the write requests in the medium priority request queue are scheduled to the target master node, and the read requests in the medium priority request queue are scheduled to the target slave node, wherein the target slave node is the slave node with the lowest load of the target master node;
[0033] An execution time less than a preset time quota is allocated to the requests in the medium priority request queue.
[0034] Optionally, the using the preset proxy middleware to schedule the user request according to a preset traffic scheduling strategy in combination with the target response priority includes:
[0035] After a preset delay time, the write request in the user request is scheduled to the target master node, and the read request in the user request is scheduled to the slave node corresponding to the target master node.
[0036] Optionally, the device further comprises:
[0037] A detection module, used to create a detection thread by using the preset proxy middleware, and detect the processes and CPU core usage of each master node and the slave nodes corresponding to each master node through the detection thread according to a preset detection cycle;
[0038] The load determination module is used to determine the load status of each node based on the detection result output by the detection thread.
[0039] Optionally, the device further comprises:
[0040] The adjustment module is used to obtain the load status of the preset proxy middleware. If the load of the preset proxy middleware exceeds the preset load threshold, the scheduling time of the high priority and medium priority requests is increased, and the scheduling time of the low priority request is decreased.
[0041] Optionally, after increasing the scheduling time of the high-priority and medium-priority requests and decreasing the scheduling time of the low-priority requests, the adjustment module is also used to increase the scheduling time of the high-priority requests again and decrease the scheduling time of the medium-priority and low-priority requests if the load of the preset proxy middleware still exceeds the preset load threshold.
[0042] In a third aspect, an embodiment of the present application provides an electronic device, wherein the electronic device includes:
[0043] Processor; and
[0044] Memory for storing programs,
[0045] The program includes instructions, which, when executed by the processor, enable the processor to execute the traffic scheduling method for the redis cluster described in the first aspect.
[0046] In a fourth aspect, an embodiment of the present application provides a non-transitory computer-readable storage medium storing computer instructions, characterized in that the computer instructions are used to enable a computer to execute the traffic scheduling method for the redis cluster described in the first aspect.
[0047] Beneficial effects of this application:
[0048] The present application provides a traffic scheduling method, device and electronic device for a redis cluster, wherein the method is applied to a redis cluster, wherein the redis cluster includes at least a preset proxy middleware, and the redis cluster includes a plurality of shards, each shard consisting of a master node and a plurality of slave nodes of the master node. Before the user request is scheduled to the corresponding shard, the preset proxy middleware is used to receive the user's user request, and then based on the user's response priority, user requests with different response priorities are differentially scheduled in combination with a preset traffic scheduling strategy. In this way, it can be ensured that user requests with different response priorities can be scheduled in a timely manner, thereby ensuring the service quality QoS of the entire redis cluster. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] Further details, features and advantages of the present application are disclosed in the following description of exemplary embodiments in conjunction with the accompanying drawings, in which:
[0050] Figure 1 A schematic diagram of a system architecture of a redis cluster provided in an embodiment of the present application is shown;
[0051] Figure 2 A flow chart of a traffic scheduling method for a redis cluster provided in an embodiment of the present application is shown;
[0052] Figure 3 Another flow chart of the traffic scheduling method of the redis cluster provided in the embodiment of the present application is shown;
[0053] Figure 4 A schematic diagram of a logical architecture of a traffic scheduling device for a redis cluster provided in an embodiment of the present application is shown;
[0054] Figure 5 A schematic diagram of a logical structure of an electronic device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0055] The embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be construed as being limited to the embodiments described herein. Instead, these embodiments are provided to provide a more thorough and complete understanding of the present application. It should be understood that the drawings and embodiments of the present application are only for exemplary purposes and are not intended to limit the scope of protection of the present application.
[0056] It should be understood that the various steps described in the method implementation of the present application can be performed in different orders and / or performed in parallel. In addition, the method implementation may include additional steps and / or omit the steps shown. The scope of the present application is not limited in this respect.
[0057] The term "including" and its variations used in this document are open inclusions, that is, "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one other embodiment"; the term "some embodiments" means "at least some embodiments". Relevant definitions of other terms will be given in the description below. It should be noted that the concepts of "first", "second", etc. mentioned in this application are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0058] It should be noted that the modifications of "one" and "plurality" mentioned in the present application are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0059] In a first aspect, the present application provides a traffic scheduling method for a redis cluster, which is applied to any electronic device with a traffic scheduling function for a redis cluster, including but not limited to a personal mobile terminal, a computer or a server.
[0060] As an implementation method, the method is applied to a redis cluster, wherein the system architecture of the redis cluster can be as follows: Figure 1 As shown, the redis cluster includes at least a preset proxy middleware and several shards. Each shard is composed of a master node and several slave nodes, wherein one master node corresponds to several slave nodes, and a master-slave relationship is formed between the master node and the slave nodes.
[0061] like Figure 1As shown, in the embodiment of the present application, the preset proxy middleware is a routing logic module located in the "front" of the shard, which is used to receive the user's request before the shard, and then distribute and schedule the user request to the corresponding shard according to the response level of the user who initiated the user request. Among them, the "front" of the shard is determined based on the inflow path of the traffic request, the preset proxy middleware is located at the first process node after the request flows in, and the shard is located at the second process node after the traffic request flows in.
[0062] In the embodiment of the present application, Figure 2 As shown, the method comprises the following steps:
[0063] S21. Utilize a preset proxy middleware to receive a user request sent by a target user, and obtain a target response priority of the target user.
[0064] Among them, in the embodiment of the present application, the response priority of the user is obtained according to the user attributes. Specifically, it can be divided into: high priority, medium priority and low priority. Among them, the user attribute can be the user's authority level, and the specific meaning of the user attribute can be flexibly set according to the actual application scenario, and this application does not strictly limit it. In the embodiment of the present application, the request of a high-priority user needs to be responded to first, the response priority of the request of a medium-priority user is lower than the request of the high-priority user, and the response priority of the request of a low-priority user is lower than the request of the medium-priority user. Among them, responding to user requests is based on computing resources. Accordingly, the request of a high-priority user is given priority to be allocated sufficient computing resources for response, followed by the medium-priority user, and the computing resources corresponding to the low-priority user are the lowest of the three priorities.
[0065] S22. Schedule the user request using a preset proxy middleware according to a preset traffic scheduling strategy combined with the target response priority.
[0066] Among them, the preset traffic scheduling strategy is determined based on the response priority, and the preset traffic scheduling strategies corresponding to different response priorities are different. Exemplarily, the principle of the preset traffic scheduling strategy corresponding to the high priority is: sufficient computing resources and extremely short scheduling time. The principle of the preset traffic scheduling strategy corresponding to the medium priority is: sufficient computing resources and shorter scheduling time. The principle of the preset traffic scheduling strategy corresponding to the low priority is: general computing resources and general scheduling time. Among them, the size of the computing resources and the length of the scheduling time in the preset traffic scheduling strategies corresponding to each priority can be flexibly set according to the actual application scenario, and this application does not make strict restrictions, but it is necessary to give priority to the scheduling of high-priority user requests.
[0067] In an embodiment of the present application, the redis cluster is a distributed storage system and also a Key-Value storage system, which belongs to the category of NoSQL (non-relational database) database. The redis cluster supports string, hash, list and other data structures. Among them, the redis cluster includes multiple redis shards, and each redis shard corresponds to a master-multiple slave architecture, that is, an architecture of one master node (redis-master node) and multiple slave nodes (redis-slave nodes). Among them, the master node is used to undertake the read and write traffic of upstream services, and the slave node device is usually used as a pure cold device (that is, it does not undertake business reads and writes) or only undertakes the read traffic of some users. The slave node can switch roles and switch from a slave node to a master node when an abnormality occurs in the master node. In addition, it can be like Figure 3 As shown, the redis cluster includes the preset proxy middleware (corresponding to Figure 3 router-sever in), sharding (corresponding to Figure 3 Shard1, Shard2, where the redis-master in the shard is the main node, and redis-slave is the slave node of the redis-master master node), the redis cluster can also include sentinel nodes (corresponding to Figure 3 The sentinel node is usually used to detect the health status of the redis cluster, especially the status of the master node. If the master node is abnormal, the sentinel node can initiate a master-slave switch. In the figure, IDC-1 and IDC-2 can be used to indicate the physical location of the node. For example, the master node in shard 1 and the master node in shard 2 are both located in the physical computer room IDC-1.
[0068] As described above, the preset proxy middleware is router-sever, which is actually a routing logic module. Different priorities are pre-defined for each user who registers to use the redis cluster. As an implementation method, it is specifically divided into: high priority, medium priority and low priority. The urgency of each priority is ranked as follows: high priority> medium priority> low priority. As another implementation method, on the basis of the aforementioned high priority, medium priority and low priority, it also includes an emergency priority. The emergency procedures of each priority are ranked as follows: emergency priority> high priority> medium priority> low priority. Among them, as a preferred implementation method, different characters can be used to represent the corresponding priorities. For example, the number 0 can be used to represent the emergency priority, and the English word urgent can also be used to represent the emergency priority. The number 1 can be used to represent the high priority, and the English word high can also be used to represent the high priority. By analogy, the number 2 represents the medium priority, and the number 3 represents the low priority.
[0069] In the embodiment of the present application, the preset proxy middleware router-sever can assign different characters to different users to define different priorities for different users. In addition, in the embodiment of the present application, each priority level can be allowed to correspond to one or more users.
[0070] In some embodiments, the preset proxy middleware can allocate different redis cluster resources for different users, where the redis cluster resources include: number of CPU cores, memory space size, and maximum number of connections, where the maximum number of connections refers to: the limit value of the connections allowed to be established set by the preset proxy middleware for each user. For example, for user A, the preset proxy middleware allows the user to establish a maximum of 500 connections with the preset proxy middleware, then the maximum number of connections is 500.
[0071] As an example, the preset proxy middleware router-server predefines the priority level of user Zhang San as 1, that is, high priority, and then allows the maximum number of CPU cores to be used to be 2, the maximum memory size to be used to be 16G, and the maximum number of allowed connections to be 5000. In the embodiment of the present application, the underlying isolation architecture mode is adopted between the CPU and the memory, so that the two are isolated from each other and do not affect each other. Specifically, the underlying isolation between the CPU and the memory can be achieved through the Linux cgroups underlying isolation technology.
[0072] In some embodiments, the preset proxy middleware records verification information of each user, and the method further includes:
[0073] Parsing each field in the user request to obtain user field information;
[0074] According to the user field information and the verification information of each user recorded in the preset proxy middleware, the target user is subjected to authority verification, and if the verification fails, the user request is rejected.
[0075] In an embodiment of the present application, a user request is usually composed of multiple fields, including the user's ID, the user's mailing address, the destination IP address of the target device that the user requests to access, etc. In the process of the user trying to build a network connection with the preset proxy middleware router-sever, the preset proxy middleware can receive the request message sent by the user. At this time, the preset proxy middleware router-sever will give priority to parsing the request message and obtain the content of each field in the request message, including user field information (such as the user's ID). The preset proxy middleware locally records the user information registered when each user registers to use the redis cluster. The preset proxy middleware can verify the user field information in the user request based on the locally recorded user information to determine whether the user field information has been recorded in advance. If it has been recorded, the verification is passed, allowing the back-end redis cluster to respond to the user request. If it has not been recorded, the verification fails. At this time, the user request can be rejected in advance to continue to access the back-end redis cluster. In this way, it can help reduce the risk of malicious traffic accessing the redis cluster and causing the redis cluster to be attacked.
[0076] In addition, the preset proxy middleware also records the response priority pre-assigned to each user. At this time, when executing the above step S11, the preset proxy middleware can determine the user's response priority based on the locally recorded response priority. As an implementation method, in the embodiment of the present application, different response priorities correspond to different preset traffic scheduling strategies. Therefore, when executing step S11, the preset proxy middleware can also determine the corresponding preset traffic scheduling strategy from the built-in preset traffic scheduling strategies based on the determined user's response priority. In the embodiment of the present application, the target user refers to the initiator corresponding to the user request that the preset proxy middleware is currently receiving and scheduling, and is one of many users. The target response priority is the response priority to which the target user belongs.
[0077] When executing step S12, the user request of the user can be scheduled by the preset proxy middleware according to the preset traffic scheduling strategy corresponding to the user's response priority. Specifically, it can be divided into the following situations:
[0078] Case 1: The user's target response priority is high priority.
[0079] Case 2: The user's target response priority is medium priority.
[0080] Case 3: The user's target response priority is low priority.
[0081] For situation 1: schedule the user request to the high-priority request queue. Among them, each user request in the high-priority request queue will be scheduled to the target master node. Among them, the target master node is the master node in the shard requested by the user request. Correspondingly, the preset proxy middleware allocates execution time exceeding the preset time quota to each user request in the high-priority request queue. Among them, the preset time quota refers to the execution time allocated by the preset proxy middleware to user requests of different response priorities. Among them, the initial time quota allocated by the preset proxy middleware to user requests of each corresponding priority can be the same. For example, the preset proxy middleware runs 24 hours a day. At this time, the preset time quotas of user requests corresponding to high priority, medium priority, and low priority are all 8 hours. When the target response priority is high priority, the preset proxy middleware allocates execution time exceeding 8 hours to the high priority queue.
[0082] As an implementation method, 60% of the 24 hours can be allocated to high-priority user requests, and the preset time quota corresponding to the high priority is 14.4 hours; 30% of the time can be allocated to medium-priority user requests, and the preset time quota corresponding to the medium priority is 7.2 hours; 10% of the time can be allocated to low-priority user requests, and the preset time quota corresponding to the low priority is 2.4 hours. At this time, if the target response priority is high priority, the preset proxy middleware can allocate more than 14.4 hours of execution time to the high priority. This will squeeze the execution time of medium-priority and low-priority user requests, that is, the execution time of medium-priority and low-priority user requests will be adaptively reduced.
[0083] For situation 2: Schedule the user request to the medium priority request queue, obtain the load status of the target master node, and obtain the load status of the slave node corresponding to the target master node. If the load status of the target master node is idle, schedule both the write request and the read request in the medium priority request queue to the target master node. If the load status of the target master node is not idle, schedule the write request in the medium priority request queue to the target master node, and schedule the read request in the medium priority request queue to the target slave node. Among them, the target slave node is the slave node with the lowest load among all the slave nodes of the target master node.
[0084] That is to say, write requests in the medium-priority request queue are directly scheduled to the target master node, but for read requests, a judgment needs to be made based on the load of the target master node:
[0085] If the target master node is idle, the read request is scheduled to the target master node. If the target master node is not idle, the read request is scheduled to a slave node with the lowest load of the target master node.
[0086] In addition, the preset proxy middleware will allocate less than the preset time quota to the requests in the medium priority request queue. If the preset time quota is 30% of the execution time of the preset proxy middleware, the preset proxy middleware will allocate less than 30% execution time to the medium priority request queue.
[0087] As an implementation method, the load status of each node can be obtained in the following manner:
[0088] A detection thread is created using the preset proxy middleware, and the detection thread detects the processes and CPU core usage of each master node and the slave nodes corresponding to each master node according to the preset detection cycle;
[0089] Based on the detection results output by the detection thread, the load condition of each node is determined.
[0090] Specifically, the preset detection cycle can be flexibly set according to actual needs, and the specific cycle length is not strictly limited in this application. Among them, as a preferred implementation method, the process status of each master node and each slave node in each shard of the backend and the number of CPU cores occupied can be obtained every 3 seconds. Among them, a process refers to an execution process of a concurrently executable program or program segment on a given workspace or data set, and a process is an independent unit for resource allocation and scheduling of the operating system. Specifically, the detection thread can send process query and CPU occupancy query commands to each node in the shard, and then obtain the query results fed back by each node of each shard, so as to obtain the process occupancy and CPU occupancy of each node.
[0091] As an implementation method, the average load of each node within 3 minutes can be calculated. If the average load exceeds the preset load threshold, it indicates that the node is in a non-idle state. If it does not exceed the preset load threshold, it indicates that the node is in an idle state. Similarly, the average load of each slave node can be sorted, and the slave node with the lowest average load is taken as the target slave node.
[0092] In addition, in the process of determining the load status of each node, the load status of the node can be determined by combining whether the node device has a slow query, wherein a slow query means that the node's response time for a request exceeds the preset query time threshold. For example, if the response time of a request is greater than 10ms, it can be regarded as a slow query at the node. Among them, the preset query time threshold and the preset load threshold can be flexibly set according to actual application requirements, and this application does not strictly limit it. For example, if each back-end master node has a slow query in the last n seconds, it indicates that the master node is in a non-idle state.
[0093] As an implementation method, the process CPU can also be directly detected through the detection thread. The CPU occupancy of the process is obtained. If the process CPU is less than the preset process CPU threshold for n consecutive cycles, and the average load is less than half of the number of CPU cores of the node, and there has been no slow query in the last n cycles, it can be determined that the load is idle.
[0094] For situation 3: The preset proxy middleware can schedule the write request in the user request to the target master node after the preset delay time, and then schedule the read request in the user request to the slave node corresponding to the target master node. Specifically, the preset delay time can be a fixed time, such as 3ms. The preset delay time can be a random delay time, based on the random time generated by a random function. As a preferred implementation, the random delay time range should be controlled within the time range of [0.5ms, 5ms].
[0095] In addition to the above three cases, it may also include cases where the response priority is urgent. Usually, user requests with this response priority are special requests and are only open to users under special circumstances. Usually, the user request is issued by the administrator. This user request has the highest priority and requires the preset proxy middleware to allocate 80% of the execution time for this urgent user request. The preset proxy middleware allocates the urgent request to the urgent request queue, and then dispatches all requests in the urgent request queue to the corresponding target master node.
[0096] In actual application, there is a situation where traffic surges in response to user requests. In response to this situation, the traffic scheduling method for the redis cluster provided in the embodiment of the present application also includes the following steps:
[0097] The load condition of the preset proxy middleware is obtained. If the load of the preset proxy middleware exceeds a preset load threshold, the scheduling time of the high priority and medium priority requests is increased, and the scheduling time of the low priority request is decreased.
[0098] If the load of the preset proxy middleware still exceeds the preset load threshold, the scheduling time of the high priority request is increased again, and the scheduling time of the medium priority and the low priority request is decreased.
[0099] Specifically, if the load of the preset proxy middleware increases, and the reason for the increase in the load is that the proportion of high-priority user requests and medium-priority user requests in the user requests increases, the response time of high-priority user requests and the response time of medium-priority user requests are continuously monitored. If the response time of high-priority user requests and medium-priority user requests increases, the proportion of the original high-priority, medium-priority, and low-priority request scheduling times is adaptively adjusted, such as adjusting the original scheduling time of the three from: high priority: medium priority: low priority ratio, and gradually adjusting it according to the change in the response time of each request. Specifically, it can be to gradually increase the scheduling time of high priority and medium priority, and reduce the scheduling time of low priority. As an example, the scheduling time can be adjusted every n seconds, such as the high priority is increased by 0.1 each time, the medium priority is increased by 0.05 each time, and the low priority is decreased by 0.1 each time. In this way, the preset proxy middleware is the scheduling time ratio between high priority, medium priority, and low priority. It can be adjusted from 1:1:1 to 1.1:1.05:0.9. After each adjustment of the scheduling time is completed, the response time of user requests of each priority level should be measured twice until the response time of high-priority and medium-priority user requests returns to normal.
[0100] If the response time of high-priority user requests cannot be restored to normal after gradually adjusting the scheduling time of the three priorities, an early warning signal can be output to notify the operation and maintenance personnel, who will intervene manually, such as expanding the capacity of the shard requested by the high-priority user request in the redis cluster and increasing the number of nodes in the shard.
[0101] When the preset proxy middleware is overloaded and needs manual intervention, the operation and maintenance personnel can turn on the preset proxy middleware and limit the queue length of medium-priority and low-priority user requests, for example, allowing a maximum of n requests in the request queues corresponding to the two priorities. This can effectively avoid the blockage of the redis cluster caused by too many requests or prohibit the forwarding of low-priority user requests.
[0102] Among them, as an implementation method, after the load of the preset proxy middleware gradually returns to normal, it can be rolled back step by step from high priority to medium priority to low priority until it rolls back to the initial state.
[0103] In a second aspect, the present application provides a traffic scheduling device for a redis cluster, wherein the device is applied to a redis cluster, and the redis cluster at least includes: a preset proxy middleware, and a plurality of shards, each of which is composed of a master node and a plurality of slave nodes, such as Figure 4 As shown, the device 40 includes:
[0104] The traffic scheduling module 401 includes the preset proxy middleware, which is used to receive the user request sent by the target user and obtain the target response priority of the target user, wherein the response priority includes: high priority, medium priority and low priority, and schedule the user request according to the preset traffic scheduling strategy combined with the target response priority, wherein the preset traffic scheduling strategy is determined based on the target response priority.
[0105] In some possible embodiments, the using the preset proxy middleware to schedule the user request according to a preset traffic scheduling strategy combined with the target response priority includes:
[0106] If the target response priority is high priority, the user request is scheduled to a high priority request queue, wherein both the read request and the write request in the high priority request queue are scheduled to the target master node;
[0107] Execution time exceeding a preset time quota is allocated to requests in the high priority request queue.
[0108] In some possible embodiments, the using the preset proxy middleware to schedule the user request according to a preset traffic scheduling strategy combined with the target response priority includes:
[0109] If the target response priority is medium priority, the user request is dispatched to the medium priority request queue;
[0110] Obtain the load condition of the target master node and the load condition of each slave node corresponding to the target master node. If the load condition of the target master node is idle, schedule both the write request and the read request in the medium priority request queue to the target master node;
[0111] If the load condition of the target master node is non-idle, the write requests in the medium priority request queue are scheduled to the target master node, and the read requests in the medium priority request queue are scheduled to the target slave node, wherein the target slave node is the slave node with the lowest load of the target master node;
[0112] An execution time less than a preset time quota is allocated to the requests in the medium priority request queue.
[0113] In some possible embodiments, the using the preset proxy middleware to schedule the user request according to a preset traffic scheduling strategy combined with the target response priority includes:
[0114] After a preset delay time, the write request in the user request is scheduled to the target master node, and the read request in the user request is scheduled to the slave node corresponding to the target master node.
[0115] In some possible embodiments, the device further includes:
[0116] The detection module 402 is used to create a detection thread by using the preset proxy middleware, and detect the processes and CPU core usage of each master node and the slave nodes corresponding to each master node through the detection thread according to a preset detection cycle;
[0117] The load determination module 403 is used to determine the load status of each node based on the detection result output by the detection thread.
[0118] In some possible embodiments, the device further includes:
[0119] The adjustment module 404 is used to obtain the load status of the preset proxy middleware. If the load of the preset proxy middleware exceeds the preset load threshold, the scheduling time of the high priority and medium priority requests is increased, and the scheduling time of the low priority request is decreased.
[0120] In some possible embodiments, after increasing the scheduling time of the high-priority and medium-priority requests and decreasing the scheduling time of the low-priority requests, the adjustment module 404 is further used to increase the scheduling time of the high-priority requests again and decrease the scheduling time of the medium-priority and low-priority requests if the load of the preset proxy middleware still exceeds the preset load threshold.
[0121] Among them, the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved in this application are in compliance with the relevant laws and regulations and do not violate public order and good morals.
[0122] The names of the messages or information exchanged between multiple devices in the embodiments of the present application are only used for illustrative purposes and are not used to limit the scope of these messages or information.
[0123] In a third aspect, the exemplary embodiments of the present application further provide an electronic device, comprising: at least one processor; and a memory connected to the at least one processor in communication. The memory stores a computer program that can be executed by the at least one processor, and the computer program is used to enable the electronic device to perform a method according to an embodiment of the present application when executed by the at least one processor.
[0124] The exemplary embodiment of the present application further provides a non-transitory computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor of a computer, is used to cause the computer to perform a method according to an embodiment of the present application.
[0125] The exemplary embodiments of the present application further provide a computer program product, including a computer program, wherein when the computer program is executed by a processor of a computer, it is used to enable the computer to execute the method according to the embodiment of the present application.
[0126] refer to Figure 5 , the structural block diagram of the electronic device 500 that can be used as the server or client of the present application will now be described, which is an example of hardware devices that can be applied to various aspects of the present application. The electronic device is intended to represent various forms of digital electronic computer equipment, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices and other similar computing devices. The components shown herein, their connections and relationships, and their functions are only examples, and are not intended to limit the implementation of the present application described and / or required herein.
[0127] like Figure 5 As shown, the electronic device 500 includes a computing unit 501, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 502 or a computer program loaded from a storage unit 508 into a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the electronic device 500 can also be stored. The computing unit 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0128] A plurality of components in the electronic device 500 are connected to the I / O interface 505, including: an input unit 506, an output unit 507, a storage unit 508, and a communication unit 509. The input unit 506 may be any type of device capable of inputting information to the electronic device 500, and the input unit 506 may receive input digital or character information, and generate key signal inputs related to user settings and / or function control of the electronic device. The output unit 507 may be any type of device capable of presenting information, and may include, but is not limited to, a display, a speaker, a video / audio output terminal, a vibrator, and / or a printer. The storage unit 508 may include, but is not limited to, a disk, an optical disk. The communication unit 509 allows the electronic device 500 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks, and may include, but is not limited to, a modem, a network card, an infrared communication device, a wireless communication transceiver, and / or a chipset, such as a Bluetooth™ device, a WiFi device, a WiMax device, a cellular communication device, and / or the like.
[0129] The computing unit 501 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 501 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 501 performs the various methods and processes described above. For example, in some embodiments, the aforementioned traffic scheduling method of the redis cluster may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 508. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 500 via the ROM 502 and / or the communication unit 509. In some embodiments, the computing unit 501 may be configured to perform the aforementioned traffic scheduling method of the redis cluster by any other appropriate means (e.g., by means of firmware).
[0130] The program code for implementing the method of the present application can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, implements the functions / operations specified in the flow chart and / or block diagram. The program code can be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0131] In the context of the present application, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0132] As used herein, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, apparatus, and / or device (e.g., disk, optical disk, memory, programmable logic device (PLD)) for providing machine instructions and / or data to a programmable processor, including a machine-readable medium that receives machine instructions as a machine-readable signal. The term "machine-readable signal" refers to any signal for providing machine instructions and / or data to a programmable processor.
[0133] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0134] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0135] A computer system may include clients and servers. Clients and servers are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship to each other.
Claims
1. A traffic scheduling method for a redis cluster, characterized in that: The method is applied to a redis cluster, the redis cluster at least comprising: a preset proxy middleware, a plurality of shards, each of the shards comprising a master node and a plurality of slave nodes, the method comprising: Utilizing the preset proxy middleware to receive a user request sent by a target user, and obtaining a target response priority of the target user, wherein the response priority includes: high priority, medium priority, and low priority; The preset proxy middleware is used to schedule the user request according to a preset traffic scheduling strategy in combination with the target response priority, wherein the preset traffic scheduling strategy is determined based on the target response priority.
2. The method according to claim 1, characterized in that The using the preset proxy middleware to schedule the user request according to the preset traffic scheduling strategy combined with the target response priority includes: If the target response priority is high priority, the user request is scheduled to a high priority request queue, wherein both the read request and the write request in the high priority request queue are scheduled to the target master node; Requests in the high priority request queue are allocated execution time exceeding a preset time quota.
3. The method according to claim 1, characterized in that: The using the preset proxy middleware to schedule the user request according to the preset traffic scheduling strategy combined with the target response priority includes: If the target response priority is medium priority, the user request is dispatched to the medium priority request queue; Obtain the load condition of the target master node and the load condition of each slave node corresponding to the target master node. If the load condition of the target master node is idle, schedule both the write request and the read request in the medium priority request queue to the target master node; If the load condition of the target master node is non-idle, the write requests in the medium priority request queue are scheduled to the target master node, and the read requests in the medium priority request queue are scheduled to the target slave node, wherein the target slave node is the slave node with the lowest load of the target master node; An execution time less than a preset time quota is allocated to the requests in the medium priority request queue.
4. The method according to claim 1, characterized in that: The using the preset proxy middleware to schedule the user request according to the preset traffic scheduling strategy combined with the target response priority includes: After a preset delay time, the write request in the user request is scheduled to the target master node, and the read request in the user request is scheduled to the slave node corresponding to the target master node.
5. The method according to claim 3, characterized in that: The method further comprises: Using the preset proxy middleware to create a detection thread, the detection thread detects the processes and CPU core usage of each master node and the slave nodes corresponding to each master node according to a preset detection cycle; Based on the detection results output by the detection thread, the load condition of each node is determined.
6. The method according to claim 1, characterized in that The method further comprises: The load condition of the preset proxy middleware is obtained. If the load of the preset proxy middleware exceeds a preset load threshold, the scheduling time of the high priority and medium priority requests is increased, and the scheduling time of the low priority request is decreased.
7. The method according to claim 6, characterized in that After increasing the scheduling time of the high-priority and medium-priority requests and decreasing the scheduling time of the low-priority requests, the method further includes: If the load of the preset proxy middleware still exceeds the preset load threshold, the scheduling time of the high priority request is increased again, and the scheduling time of the medium priority and the low priority request is decreased.
8. A traffic scheduling device for a redis cluster, characterized in that: The device is applied to a redis cluster, the redis cluster at least comprising: a preset proxy middleware, a plurality of shards, each of the shards comprising a master node and a plurality of slave nodes, the device comprising: A traffic scheduling module, wherein the traffic scheduling module includes the preset proxy middleware, which is used to receive a user request sent by a target user and obtain a target response priority of the target user, wherein the response priority includes: high priority, medium priority and low priority, and the user request is scheduled according to a preset traffic scheduling strategy combined with the target response priority, wherein the preset traffic scheduling strategy is determined based on the target response priority.
9. An electronic device, characterized in that: The electronic device comprises: Processor; and Memory for storing programs, The program includes instructions, which, when executed by the processor, cause the processor to perform the method according to any one of claims 1 to 7.
10. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are used to make a computer execute the method according to any one of claims 1-7.
