Redis-based performance tuning methods, devices, electronic equipment, and media
By allocating Redis query requests to a query queue and adjusting the timeout and queue information based on the response time, the performance degradation of Redis under high concurrency is resolved, achieving dynamic performance optimization and improvement.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-14
- Publication Date
- 2026-04-03
AI Technical Summary
When there are many Redis requests, even a small delay can slow down the overall performance, resulting in a decrease in the overall performance of Redis.
Redis query requests are assigned to a predefined query queue. If the query queue receives an expiration notification, the query request is assembled into a communication pipeline and submitted to Redis. The system performance of Redis is determined based on the response time of the query result. If it does not meet the requirements, the timeout time of the expiration notification and/or the queue information of the query queue are adjusted until the performance meets the requirements.
By dynamically adjusting Redis's timeout and queue information, the system performance of Redis is improved, avoiding the need for additional hardware and manual intervention, and increasing query efficiency.
Smart Images

Figure CN117271597B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of logistics technology, specifically to a performance tuning method, apparatus, electronic device, and medium (computer storage medium) based on Redis. Background Technology
[0002] With the popularization of the Internet, more and more users are starting to shop online, send express packages, read news, etc., and the concurrency of system access is increasing exponentially, which also puts forward higher requirements for caching system queries; existing technologies usually use Redis (Remote Dictionary Server, a high-performance key-value database) as a caching system.
[0003] Redis, as a high-performance caching service, offers two query methods: non-piped and piped. Non-piped queries are less efficient under high concurrency. Piped queries improve efficiency under high concurrency, but require waiting for all queries in the pipeline to complete before matching the results back to the pipeline, which also takes time. In other words, while Redis itself is highly performant and the latency of a single request is negligible, when the number of requests is high (tens or hundreds of thousands per second), even small network delays can slow down the overall performance of Redis, leading to a decrease in overall performance. Summary of the Invention
[0004] This application provides a Redis-based performance tuning method, apparatus, device, and computer storage medium, aiming to solve the technical problem that even a small delay can slow down the overall Redis performance when there are many requests, resulting in a decrease in the overall Redis performance.
[0005] On the one hand, this application provides a performance tuning method based on Redis, which includes the following steps:
[0006] Distribute Redis query requests to a predefined query queue;
[0007] If the query queue receives an expiration notification, it assembles each query request in the query queue into a communication pipe and submits it to Redis.
[0008] Receive the query results fed back by Redis based on the communication pipeline, and determine whether the system performance of Redis meets the requirements based on the response time associated with the query results;
[0009] If the Redis system performance does not meet the requirements, the timeout time corresponding to the expiration notification and / or the queue information of the query queue will be adjusted until the Redis system performance meets the requirements.
[0010] In some embodiments of this application, before assembling the query requests in the query queue into a communication pipeline and submitting them to Redis if the query queue receives an expiration notification, the method includes:
[0011] The system controls a preset time wheel to allocate timeout periods to the query queue and controls the query queue to request an expiration notification channel from the time wheel.
[0012] If there are at least two query queue request expiration notification channels, then obtain the queue identifier of the query queue that has exceeded the timeout period;
[0013] The expiration notification is sent to the query queue corresponding to the queue identifier through the expiration notification pipeline.
[0014] In some embodiments of this application, receiving the query results from Redis based on the communication pipeline, and determining whether the system performance of Redis meets the requirements based on the response time associated with the query results, includes:
[0015] Receive the query result fed back by Redis based on the communication pipeline, and obtain the response time associated with the query result;
[0016] Statistically analyze the response times associated with each query result and calculate the average latency of the Redis instance;
[0017] If the average latency exceeds a preset latency threshold, the system performance of Redis is determined to be unsatisfactory.
[0018] In some embodiments of this application, the step of adjusting the timeout time corresponding to the expiration notification and / or the queue information of the query queue if the Redis system performance does not meet the requirements includes:
[0019] If the Redis system performance does not meet the requirements, the timeout period corresponding to the expiration notification, the number of queues in the query queue, or the queue length of the query queue will be adjusted.
[0020] Obtain the new query results corresponding to the adjusted query queue, and determine the new average latency based on the response time associated with the new query results;
[0021] The system performance of Redis is determined to meet the requirements until the new average latency does not exceed the preset latency threshold.
[0022] In some embodiments of this application, determining that the Redis system performance meets the requirements until the new average latency does not exceed a preset latency threshold includes:
[0023] If the new average latency does not exceed the preset latency threshold, then obtain the CPU utilization and memory utilization of Redis;
[0024] If the CPU utilization of Redis exceeds a preset utilization threshold, or the memory utilization of Redis exceeds a preset utilization threshold, then the timeout period corresponding to the expiration notification, the number of queues in the query queue, or the length of the query queue will be adjusted in reverse.
[0025] If the CPU utilization and memory utilization of Redis do not exceed the preset utilization threshold, then the system performance of Redis is determined to meet the requirements.
[0026] In some embodiments of this application, the step of allocating Redis query requests to a preset query queue includes:
[0027] The query service module parses the query request and extracts the query request to Redis.
[0028] Get the number of query requests to Redis, the number of preset query queues, and the length of each query queue.
[0029] Based on the number of queues and the queue length, the number of query requests is allocated to each of the query queues.
[0030] In some embodiments of this application, before allocating the Redis query request to a preset query queue, the method includes:
[0031] The average latency of Redis query requests is retrieved through the preset query service module;
[0032] Receive the expected latency set by the user, and configure the number and length of the corresponding query queue in Redis based on the expected latency and the average latency;
[0033] The average delay is set as the initial timeout for the expiration notification, and the number of queues and the queue length are set as the initial queue information for the query queue.
[0034] On the other hand, this application provides a Redis-based performance tuning device, which includes:
[0035] The allocation module is used to distribute Redis query requests to a preset query queue;
[0036] An assembly module is used to assemble each query request in the query queue into a communication pipe and submit it to Redis if the query queue receives an expiration notification;
[0037] The determination module is used to receive the query results fed back by Redis based on the communication pipeline, and determine whether the system performance of Redis meets the requirements based on the response time associated with the query results;
[0038] The adjustment module is used to adjust the timeout time corresponding to the expiration notification and / or the queue information of the query queue if the system performance of Redis does not meet the requirements, until the system performance of Redis meets the requirements.
[0039] On the other hand, this application also provides an electronic device, the electronic device comprising:
[0040] One or more processors;
[0041] Memory; and
[0042] One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the processor to implement the steps in the Redis-based performance tuning method.
[0043] On the other hand, this application also provides a computer storage medium storing a computer program that is loaded by a processor to execute the steps in the Redis-based performance tuning method.
[0044] This application's technical solution includes a Redis-based performance tuning method, apparatus, electronic device, and medium. The Redis-based performance tuning method includes: allocating Redis query requests to a preset query queue; if the query queue receives an expiration notification, assembling each query request in the query queue into a communication channel and submitting it to Redis; receiving query results fed back by Redis based on the communication channel, and determining whether Redis's system performance meets requirements based on the response time associated with the query results; if Redis's system performance does not meet requirements, adjusting the timeout time corresponding to the expiration notification and / or the queue information of the query queue until Redis's system performance meets requirements. In this embodiment, based on the response time associated with the query request, it is possible to determine whether Redis's system has a response delay, and then determine whether Redis's system performance meets requirements. If Redis's system performance does not meet requirements, the timeout time and / or the queue information of the query queue corresponding to Redis's system are dynamically adjusted to make Redis's system performance meet requirements. This eliminates the need to increase the hardware structure of the Redis system or require manual intervention; the query performance of the Redis system can be improved through simple dynamic parameter adjustments. Attached Figure Description
[0045] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0046] Figure 1 This is a schematic diagram illustrating a scenario of the performance tuning method based on Redis provided in an embodiment of this application.
[0047] Figure 2 This is a flowchart illustrating one embodiment of the performance tuning method based on Redis in this application.
[0048] Figure 3 This is a flowchart illustrating an embodiment of the Redis query expiration notification method provided in the Redis-based performance tuning method of this application.
[0049] Figure 4 This is a schematic diagram of a specific scenario of the Redis performance tuning system in the Redis-based performance tuning method provided in this application embodiment;
[0050] Figure 5This is a flowchart illustrating an embodiment of parameter adjustment in the performance tuning method based on Redis provided in this application.
[0051] Figure 6 This is a flowchart illustrating an embodiment of the query request allocation method based on Redis provided in this application.
[0052] Figure 7 This is a flowchart illustrating an embodiment of the Redis-based performance tuning method provided in this application for initial parameter configuration.
[0053] Figure 8 This is a schematic diagram of an embodiment of the Redis-based performance tuning device provided in this application.
[0054] Figure 9 This is a schematic diagram of an embodiment of the electronic device provided in this application. Detailed Implementation
[0055] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of the present invention.
[0056] In the description of this invention, it should be understood that the terms "center," "longitudinal," "lateral," "length," "width," "thickness," "upper," "lower," "front," "rear," "left," "right," "vertical," "horizontal," "top," "bottom," "inner," and "outer," etc., indicating orientation or positional relationships based on the orientation or positional relationships shown in the accompanying drawings, are only for the convenience of describing the invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of the invention. Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Thus, features defined with "first" and "second" may explicitly or implicitly include one or more of the stated features. In the description of this invention, "a plurality of" means two or more, unless otherwise explicitly specified.
[0057] In this application, the term "exemplary" is used to mean "serving as an example, illustration, or description." Any embodiment described as "exemplary" in this application is not necessarily to be construed as being more preferred or advantageous than other embodiments. The following description is provided to enable any person skilled in the art to make and use the invention. Details are set forth in the following description for purposes of explanation. It should be understood that those skilled in the art will recognize that the invention can be made without using these specific details. In other instances, well-known structures and processes will not be described in detail to avoid obscuring the description of the invention with unnecessary detail. Therefore, the invention is not intended to be limited to the embodiments shown, but is consistent with the broadest scope of the principles and features disclosed in this application.
[0058] This application provides a Redis-based performance tuning method, apparatus, device, and computer storage medium, which will be described in detail below.
[0059] The performance tuning method based on Redis in this embodiment of the invention is applied to a performance tuning device based on Redis. The performance tuning device based on Redis is set in an electronic device. The electronic device is equipped with one or more processors, a memory, and one or more applications. The one or more applications are stored in the memory and configured to be executed by the processor to implement the performance tuning method based on Redis. The electronic device can be a terminal, such as a mobile phone or a tablet computer. The electronic device can also be a server or a service cluster composed of multiple servers.
[0060] like Figure 1 As shown, Figure 1 This is a schematic diagram of a scenario for a Redis-based performance tuning method according to an embodiment of this application. The Redis-based performance tuning scenario in this embodiment includes an electronic device 100 (which integrates a Redis-based performance tuning device). The electronic device 100 runs a computer storage medium corresponding to the Redis-based performance tuning to perform the Redis-based performance tuning steps.
[0061] Understandable Figure 1 The electronic devices in the Redis-based performance adjustment scenario, or the devices contained in the electronic devices, do not constitute a limitation on the embodiments of the present invention. That is, the number or type of devices in the Redis-based performance adjustment scenario, or the number or type of devices contained in each device, do not affect the overall implementation of the technical solution in the embodiments of the present invention, and can all be considered as equivalent substitutions or derivatives of the technical solutions claimed in the embodiments of the present invention.
[0062] In this embodiment of the invention, the electronic device 100 is mainly used for: allocating Redis query requests to a preset query queue; if the query queue receives an expiration notification, assembling each query request in the query queue into a communication channel and submitting it to Redis; receiving the query results fed back by Redis based on the communication channel, and determining whether the system performance of Redis meets the requirements based on the response time associated with the query results; if the system performance of Redis does not meet the requirements, adjusting the timeout time corresponding to the expiration notification and / or the queue information of the query queue until the system performance of Redis meets the requirements.
[0063] In this embodiment of the invention, the electronic device 100 can be an independent electronic device, or it can be a network of electronic devices or a cluster of electronic devices. For example, the electronic device 100 described in this embodiment of the invention includes, but is not limited to, a computer, a network host, a single network electronic device, a set of multiple network electronic devices, or a cloud electronic device composed of multiple electronic devices. Among them, the cloud electronic device is composed of a large number of computers or network electronic devices based on cloud computing.
[0064] Those skilled in the art will understand that Figure 1 The application environment shown is merely one application scenario of the solution in this application and does not constitute a limitation on the application scenario of the solution in this application. Other application environments may include those that are more specific to this application. Figure 1 The number of more or fewer electronic devices shown, or the network connections of electronic devices, for example Figure 1 Only one electronic device is shown in the diagram. It is understood that the Redis-based performance tuning scenario may also include one or more other electronic devices, which are not specified here; the electronic device 100 may also include a memory.
[0065] Furthermore, in the Redis-based performance tuning scenario of this application, the electronic device 100 can be equipped with a display device, or the electronic device 100 can be connected to an external display device 200 without a built-in display device. The display device 200 is used to output the results of the Redis-based performance tuning method executed in the electronic device. The electronic device 100 can access the background database 300 (the background database can be located in the local storage of the electronic device, or it can be located in the cloud), and the background database 300 stores information related to Redis-based performance tuning.
[0066] It should be noted that, Figure 1The schematic diagram of the Redis-based performance tuning method shown is merely an example. The Redis-based performance tuning scenario described in this embodiment is intended to more clearly illustrate the technical solution of this embodiment and does not constitute a limitation on the technical solution provided by this embodiment.
[0067] Based on the above scenarios of Redis-based performance tuning, an embodiment of the Redis-based performance tuning method is proposed.
[0068] like Figure 2 As shown, Figure 2 This is a flowchart illustrating an embodiment of the Redis-based performance tuning method in this application. The Redis-based performance tuning method includes steps 201-204:
[0069] 201. Distribute Redis query requests to a predefined query queue.
[0070] The performance tuning method based on Redis in this embodiment is applied to electronic devices. The type of electronic device is not specifically limited. For example, the electronic device can be a terminal or a server. This embodiment uses a server as an example for explanation.
[0071] The server receives query requests. These requests can be user-initiated, such as when a user clicks the "Data Query" button on a mobile device's interface, sending the request to the server. The server then receives the user-triggered query request. Alternatively, the query request can be automatically triggered by the server. For example, the server may have pre-set conditions for triggering the query request, such as automatically triggering a query request when data is updated, or collecting real-time data update information from the database and automatically triggering a query request when the server detects a database update.
[0072] After receiving a query request, the server parses each request through the query service module, extracting the query requests for Redis. Specifically, the query service module parses the commands in the query request, extracting the key commands for the Redis query. The query service module then decomposes the Redis query into key commands (key1, key2, key3, etc.), and requests result notification pipes (ch1, ch2, ch3, etc.) for each of these key commands. Finally, the query requests for Redis are evenly distributed into pre-defined query queues. These pre-defined query queues have a pre-set number and length that can be flexibly adjusted.
[0073] In this embodiment, the method by which the query service module in the server distributes Redis query requests to the preset query queues is not specifically limited. For example, in the first implementation, the query service module distributes the query requests to the query queues sequentially, making the number of query requests in each query queue more even and improving the execution efficiency of the query requests. In the second implementation, the query service module obtains the queue data and queue length threshold of the query queue, as well as the number of query requests. For example, if the number of query queues is 2 and the queue length threshold of the query queue is 500, the query service module obtains that there are 600 query requests for Redis, and distributes the 600 query requests evenly to the two query queues.
[0074] In this embodiment, the server distributes Redis query requests evenly into the query queue, which can improve the efficiency of Redis queries and accurately record the response time of query requests.
[0075] After the server distributes query requests to preset query queues through the query service module, the query queues apply for result notification channels for each query queue. After the query request is executed, the query result can be fed back through the result notification channel. If the query result is not received from the result notification channel within a preset time, the server generates an expiration notification and sends it to the message queue.
[0076] 202. If the query queue receives an expiration notification, then the query requests in the query queue are assembled into a communication pipe and submitted to Redis.
[0077] If the query queue receives an expiration notification, the server controls the assembly of each query request in the query queue into a communication pipeline (where a pipeline refers to dividing a repetitive task into different stages, each stage being handled by an independent unit; all objects to be executed enter the job queue sequentially, and except for a short period at the beginning and end, all units are served simultaneously at any time) and submits it to Redis; that is, the server associates the various query requests in the query queue. For example, for three queries, query request 1, query request 2, and query request 3, combining the three query requests into a pipeline and submitting it to Redis can improve query efficiency.
[0078] After the server detects that all query requests in the pipeline have returned query results, it will write the final query result to the result notification pipeline corresponding to the query queue. At this time, the server will receive the query result and send a response message to the corresponding query request.
[0079] 203. Receive the query result fed back by Redis based on the communication pipeline, and determine whether the system performance of Redis meets the requirements based on the response time associated with the query result.
[0080] The server receives query results from Redis via a communication pipeline and obtains the response time associated with those results. Based on the response time carried in the query results, the server determines whether Redis's system performance meets the requirements. The specific implementation method is not limited; for example...
[0081] In the first implementation, the server determines whether the Redis system performance meets the requirements based on the average Redis latency, including:
[0082] 1. Receive the query result fed back by Redis based on the communication pipeline, and obtain the response time associated with the query result;
[0083] 2. Statistically analyze the response times associated with each query result and calculate the average latency of the Redis instance;
[0084] 3. If the average latency exceeds the preset latency threshold, the system performance of Redis is deemed to be unacceptable.
[0085] The server receives query results from Redis via communication channels and obtains the response time associated with each query result. Based on the response times associated with each query result, the server calculates the average latency of Redis. Specifically, the query service module in the server calculates the response time of the query result based on the time information carried in the query request and the time information carried in the corresponding query result. The server sums the response times of each query request and calculates the average latency of Redis. The server compares the average latency of Redis with a preset latency threshold, where the preset latency threshold is the latency time set by the user according to expectations, for example, a preset latency threshold set to 0.5 seconds. If the average latency does not exceed the preset latency threshold, the system performance of Redis is deemed to meet the requirements, and no performance optimization is needed. If the average latency exceeds the preset latency threshold, the system performance of Redis is deemed to not meet the requirements.
[0086] Implementation method two: The server determines whether the Redis system performance meets the requirements based on the Redis queries per second rate, including:
[0087] 1. Receive the query result fed back by Redis based on the communication pipeline, and obtain the response time associated with the query result;
[0088] 2. Based on the response time associated with each query result, count the number of requests to Redis to obtain the query rate per second;
[0089] 3. If the query rate per second does not exceed the preset query rate, then the Redis system performance is deemed not to meet the requirements.
[0090] The server receives query results from Redis via the communication channel and obtains the response time associated with each query result. The query service module calculates the response time associated with each query result and the query rate per second (RPS) of Redis. The query service module compares the RPS of Redis with a preset query rate, where the preset query rate is a threshold for the number of requests set by Redis based on actual processing conditions, for example, a preset query rate of 100,000 requests per second. If the RPS exceeds the preset query rate, the system performance of Redis is deemed to meet the requirements and no performance optimization is needed; if the RPS does not exceed the preset query rate, the system performance of Redis is deemed to not meet the requirements.
[0091] In this embodiment, the server determines whether the Redis system performance meets the requirements based on the query results received from Redis via the communication pipeline and the response time associated with the query results. This allows for accurate evaluation of Redis performance and further optimization of Redis system performance. Specifically:
[0092] 204. If the system performance of Redis does not meet the requirements, adjust the timeout time corresponding to the expiration notification and / or the queue information of the query queue until the system performance of Redis meets the requirements.
[0093] If Redis's system performance does not meet the requirements, the server will adjust the timeout time of the expiration notification and / or the queue information of the query queue. The queue information includes the queue length and the number of queues. The server can choose to adjust at least one of the expiration time, queue length, and queue number until Redis's system performance meets the requirements.
[0094] In this embodiment, Redis query requests are allocated to a preset query queue. If the query queue receives an expiration notification, the query requests in the queue are assembled into a communication channel and submitted to Redis. The query results fed back by Redis based on the communication channel are received, and the system performance of Redis is determined based on the response time associated with the query results. If the system performance of Redis is not up to standard, the timeout time corresponding to the expiration notification and / or the queue information of the query queue are adjusted until the system performance of Redis meets the requirements. In this embodiment, the server can determine whether there is a response delay in Redis based on the response time associated with the query request, and then determine whether the system performance of Redis meets the requirements. If the system performance of Redis is not up to standard, the timeout time and / or the queue information of the query queue are dynamically adjusted. In this way, the Redis system feeds back results according to the user's expected time, so that the system performance of Redis meets the requirements. This does not require adding hardware to the Redis system or manual intervention. The system performance of Redis can be improved through simple parameter adjustments.
[0095] Figure 3 This is a flowchart illustrating an embodiment of the Redis query expiration notification in the Redis-based performance tuning method provided in this application.
[0096] In some embodiments of this application, step 202, if the query queue receives an expiration notification, before assembling each query request in the query queue into a communication pipeline and submitting it to Redis, the server pre-builds a Redis front-end performance tuning system and uses the performance tuning system to send expiration notifications, specifically including steps 301-303:
[0097] 301, control the preset time wheel to allocate timeout time to the query queue, and control the query queue to request an expiration notification channel from the time wheel;
[0098] A pre-built performance tuning system for Redis is configured on the server, referencing... Figure 4 , Figure 4 This is a schematic diagram illustrating a specific scenario of the Redis performance tuning system within the Redis-based performance tuning method provided in this application embodiment. Figure 4 As shown, this performance tuning system includes a control service module, a query service module, a time wheel, and a channel pipeline reuse pool, etc.
[0099] The control service module is used to: 1. Receive the expected delay set by the user; 2. Retrieve the average time of query requests through the query service module; 3. Adjust according to the dependency time of query requests, where the adjustment parameters include timeout time, queue length and queue number.
[0100] The query service module is used to: receive query requests, parse the query requests, extract the query requests for Redis from the query requests, and adjust the query requests for Redis into key commands before allocating them to the query queue;
[0101] The time wheel is used to monitor the response time of query requests in each query queue. If the response time of a query request in a query queue exceeds the timeout period, the time wheel will send a timeout notification to the query queue.
[0102] The chan pipeline reuse pool is used to: notify the pipeline of the results of Redis query requests, thereby reducing system memory consumption; and the query queue is used to control the concurrency of Redis requests and the number of query requests packaged in each request.
[0103] It is understood that the structure of the performance tuning system is not limited, and those skilled in the art can set more or fewer processing modules according to the specific use case. In this embodiment, for ease of understanding, the above-mentioned performance tuning system is used as an example for explanation.
[0104] In this embodiment, after the server allocates Redis query requests to a preset query queue through the query service module, the server allocates a timeout period T to the query queue through a preset time wheel, and at the same time controls the query queue to request an expiration notification pipe from the time wheel. The expiration notification pipe notifies the query requests in the query queue whether the execution has exceeded the timeout period T.
[0105] 302. If there are at least two query queue application expiration notification channels, then obtain the queue identifier of the query queue that has exceeded the timeout period.
[0106] In this embodiment, the number of query queues is not specifically limited. For example, there can be at least two query queues. The time wheel monitors the response time of query requests in the query queues in real time. When the time wheel detects that at least two query queues have exceeded the timeout period, it obtains the queue identifier of the query queue that has exceeded the timeout period.
[0107] 303, The expiration notification is sent to the query queue corresponding to the queue identifier through the expiration notification pipeline.
[0108] The time wheel sends an expiration notification to the query queue corresponding to the queue identifier through the expiration notification pipeline. When the query queue receives the expiration notification, the server assembles the query requests in the query queue into a communication pipeline and submits it to Redis.
[0109] For ease of understanding, please refer to Figure 4 The query service module breaks down multiple Redis queries into key1, key2, key3, and so on, and requests result notification pipelines ch1, ch2, ch3, and so on for each key. These pipelines are then evenly distributed across M query queues. Each queue has a maximum length of N. Each queue requests an expiration notification pipeline from the time wheel; if multiple queues have requested expiration notification pipelines, they are reused. The time wheel assigns a timeout T to a query queue at a certain time and notifies the queue of its expiration time via a pipeline. When a queue receives an expiration notification, it assembles all the keys to be queried in the queue into a pipeline, submits a query request to Redis, and simultaneously requests a new expiration notification pipeline from the time wheel, preparing for the next round.
[0110] In this embodiment, a performance tuning system is set up in front of Redis. Expiration notifications are sent through the performance tuning system, which enables effective monitoring of query request times. At the same time, the query method of Redis is determined based on the response time of query requests in the query queue, which can improve the query rate of Redis and further ensure the system performance of Redis.
[0111] Reference Figure 5 , Figure 5 This is a flowchart illustrating an embodiment of parameter adjustment in the performance tuning method based on Redis provided in this application.
[0112] In some embodiments of this application, if the Redis system performance does not meet the requirements in step 204, the timeout time corresponding to the expiration notification and / or the queue information of the query queue are adjusted until the Redis system performance meets the requirements, specifically including steps 401-403:
[0113] 401. If the Redis system performance does not meet the requirements, adjust the timeout period corresponding to the expiration notification, the number of queues in the query queue, or the length of the query queue.
[0114] If Redis's system performance does not meet the requirements, the server obtains the timeout period corresponding to the expiration notification, the number of query queues, and the length of the query queue. The server can keep one value unchanged and adjust the other two. For example, the server can keep the timeout period corresponding to the expiration notification unchanged and adjust the number of query queues and the length of the query queue; or the server can keep the length of the query queue unchanged and adjust the number of query queues and the timeout period corresponding to the expiration notification.
[0115] The server distributes new Redis query requests to the adjusted query queue; if the query queue receives an expiration notification again, the server assembles the query requests in the queue into a communication channel and submits it to Redis.
[0116] 402, obtain the new query results corresponding to the adjusted query queue, and determine the new average latency based on the response time associated with the new query results.
[0117] The server receives new query results from Redis via the communication channel. The server obtains the response time associated with each new query result, sums the response times of all query requests, and calculates the average to obtain a new average latency. The server compares this new average latency with a preset latency threshold, which is a latency time set by the user based on expectations; for example, the preset latency threshold is set to 0.5 seconds. If the new average latency does not exceed the preset latency threshold, the Redis system performance is deemed to meet the requirements, and no performance optimization is needed. If the new average latency exceeds the preset latency threshold, the Redis system performance is deemed to not meet the requirements, and adjustments are made accordingly.
[0118] 403, until the new average latency does not exceed the preset latency threshold, then the system performance of Redis is determined to meet the requirements.
[0119] If the new average latency does not exceed the preset latency threshold, the server further checks other Redis performance parameters to ensure that the Redis system performance meets the requirements; specifically, this includes:
[0120] 1. If the new average latency does not exceed the preset latency threshold, then obtain the CPU utilization and memory utilization of Redis;
[0121] 2. If the CPU utilization rate of Redis exceeds the preset utilization rate threshold, or the memory utilization rate of Redis exceeds the preset utilization rate threshold, then the timeout time corresponding to the expiration notification, the number of queues in the query queue, or the queue length of the query queue will be adjusted in reverse.
[0122] 3. If the CPU utilization and memory utilization of Redis do not exceed the preset utilization threshold, then the system performance of Redis is determined to meet the requirements.
[0123] That is, if the new average latency does not exceed the preset latency threshold, the server obtains the CPU utilization and memory utilization of Redis; the server compares the CPU utilization and memory utilization of Redis with the preset utilization threshold, where the preset utilization threshold refers to the critical value that affects the performance of Redis, for example, the preset utilization threshold is set to 80%.
[0124] If the CPU or memory utilization of Redis exceeds a preset threshold, the timeout period for expiration notifications, the number of queues in the query queue, or the queue length are adjusted in reverse to reduce the CPU and memory utilization of Redis, thus preventing Redis failures. If neither the CPU nor memory utilization exceeds the preset threshold, the system performance of Redis is deemed to meet the requirements. In this case, no additional hardware upgrades to Redis are needed; performance improvements can be achieved by dynamically adjusting Redis parameters.
[0125] For ease of understanding, please continue to refer to... Figure 4 The performance tuning system's control service on the server obtains the user-provided expected latency L and periodically retrieves the average latency information of the query service, as well as Redis CPU and memory usage information. It maintains the average latency of the query service below L by continuously adjusting the values of three parameters: queue size M, queue length N, and timeout T, while keeping Redis CPU and memory usage within a reasonable range. The adjustment rules are as follows: When the query service starts for the first time, these three parameters are assigned empirical values of M=2, N=500, and T=5ms. When the retrieved average latency is higher than L, two of M, N, and T are kept constant, while the value of the third parameter is increased, thus decreasing the value of the fourth parameter. If the average latency decreases, the value of that parameter is adjusted in the same way until the average latency no longer decreases. If the parameter adjustment causes Redis CPU or memory usage to exceed the threshold, the optimization of that parameter is rolled back, and the values of the other two parameters are attempted to be optimized.
[0126] In this embodiment, the server provides a specific implementation method for adjusting Redis parameters. By adjusting the number of queues M, the queue length N, and the timeout T, the performance of Redis can meet the requirements, greatly reducing manual intervention and improving the stability of the system. It is only necessary to specify the expected delay time to the control service.
[0127] Reference Figure 6 , Figure 6 This is a schematic diagram of an embodiment of the query request allocation in the performance tuning method based on Redis provided in this application.
[0128] In some embodiments of this application, step 201 allocates the Redis query request to a preset query queue, specifically including steps 501-503:
[0129] 501 indicates that the query service module parses the query request and extracts the query request to Redis.
[0130] The server parses query requests through the query service module and extracts query requests for Redis. In other words, in this embodiment, the performance tuning system filters query requests and extracts query requests for Redis in order to perform performance tuning on Redis based on the query requests for Redis.
[0131] 502, obtain the number of query requests to Redis, the number of preset query queues, and the length of each query queue.
[0132] The server obtains the number of query requests to Redis, the number of preset query queues, and the length of each query queue. The queue length here includes the real-time length of the queue and the queue length threshold of the query queue. For example, the real-time length of the query queue is 300, and the queue length threshold is 500.
[0133] 503. Based on the number of queues and the queue length, the number of query requests is allocated to each of the query queues.
[0134] The server distributes the number of query requests to each query queue based on the number of queues and the queue length. In other words, in this embodiment, the server distributes the number of query requests based on the number of queues and the queue length, which can make the queue length of each query queue more even and reduce the latency of requests in the queue.
[0135] Reference Figure 7 , Figure 7 This is a flowchart illustrating an embodiment of the Redis-based performance tuning method provided in this application for initial parameter configuration.
[0136] In some embodiments of this application, before step 201 of the embodiments of this application allocates the Redis query request to the preset query queue, the performance tuning method based on Redis further includes steps 601-603:
[0137] 601, retrieves the average latency of Redis query requests through the preset query service module;
[0138] 602, Receive the expected delay set by the user, and configure the number of queues and the queue length of the corresponding query queue in Redis based on the expected delay and the average delay;
[0139] 603, set the average delay to the initial timeout period of the expiration notification, and set the number of queues and the queue length to the initial queue information of the query queue.
[0140] Before performing Redis performance tuning in this embodiment, it is necessary to pre-set the relevant Redis parameters. This embodiment provides a method for setting the initial parameters, which specifically includes: the server pulls the average latency of Redis query requests through a preset query service module; the server receives the expected latency set by the user, and configures the number of queues and the queue length of the corresponding Redis query queue according to the expected latency and the average latency; the server sets the average latency as the initial timeout time for the expiration notification, and sets the number of queues and the queue length as the initial queue information of the query queue.
[0141] In this embodiment, the server can set the initial timeout for the expiration notification based on the user's average latency; configure the number and length of the corresponding query queue in Redis based on the expected latency and average latency; when the server allocates query requests, it allocates requests based on the initial queue information, which facilitates parameter adjustments later.
[0142] like Figure 8 As shown, Figure 8 This is a schematic diagram of an embodiment of the performance tuning device based on Redis provided in this application.
[0143] To better implement the Redis-based performance tuning method in this application embodiment, this application embodiment also provides a Redis-based performance tuning device, which includes:
[0144] The allocation module 701 is used to allocate Redis query requests to a preset query queue;
[0145] Assembly module 702 is used to assemble each query request in the query queue into a communication pipe and submit it to Redis if the query queue receives an expiration notification;
[0146] The determination module 703 is used to receive the query results fed back by Redis based on the communication pipeline, and determine whether the system performance of Redis meets the requirements based on the response time associated with the query results;
[0147] The adjustment module 704 is used to adjust the timeout time corresponding to the expiration notification and / or the queue information of the query queue if the system performance of Redis does not meet the requirements, until the system performance of Redis meets the requirements.
[0148] In some embodiments of this application, before the Redis-based performance tuning device performs the step of assembling each query request in the query queue into a communication pipeline and submitting it to Redis if the query queue receives an expiration notification, the following steps are included:
[0149] The system controls a preset time wheel to allocate timeout periods to the query queue and controls the query queue to request an expiration notification channel from the time wheel.
[0150] If there are at least two query queue request expiration notification channels, then obtain the queue identifier of the query queue that has exceeded the timeout period;
[0151] The expiration notification is sent to the query queue corresponding to the queue identifier through the expiration notification pipeline.
[0152] In some embodiments of this application, the determination module 703 in the Redis-based performance tuning device performs the following steps: receiving the query results fed back by Redis based on the communication pipeline, and determining whether the Redis system performance meets the requirements based on the response time associated with the query results, including:
[0153] Receive the query result fed back by Redis based on the communication pipeline, and obtain the response time associated with the query result;
[0154] Statistically analyze the response times associated with each query result and calculate the average latency of the Redis instance;
[0155] If the average latency exceeds a preset latency threshold, the system performance of Redis is determined to be unsatisfactory.
[0156] In some embodiments of this application, the adjustment module 704 in the Redis-based performance adjustment device performs the following steps: if the Redis system performance does not meet the requirements, adjust the timeout time corresponding to the expiration notification and / or the queue information of the query queue until the Redis system performance meets the requirements, including:
[0157] If the Redis system performance does not meet the requirements, the timeout period corresponding to the expiration notification, the number of queues in the query queue, or the queue length of the query queue will be adjusted.
[0158] Obtain the new query results corresponding to the adjusted query queue, and determine the new average latency based on the response time associated with the new query results;
[0159] The system performance of Redis is determined to meet the requirements until the new average latency does not exceed the preset latency threshold.
[0160] In some embodiments of this application, in the Redis-based performance tuning device, the tuning module 704 performs the step of determining that the Redis system performance meets the requirements until the new average latency does not exceed a preset latency threshold, including:
[0161] If the new average latency does not exceed the preset latency threshold, then obtain the CPU utilization and memory utilization of Redis;
[0162] If the CPU utilization of Redis exceeds a preset utilization threshold, or the memory utilization of Redis exceeds a preset utilization threshold, then the timeout period corresponding to the expiration notification, the number of queues in the query queue, or the length of the query queue will be adjusted in reverse.
[0163] If the CPU utilization and memory utilization of Redis do not exceed the preset utilization threshold, then the system performance of Redis is determined to meet the requirements.
[0164] In some embodiments of this application, the allocation module 701 in the Redis-based performance tuning device performs the allocation of Redis query requests to a preset query queue, including:
[0165] The query service module parses the query request and extracts the query request to Redis.
[0166] Get the number of query requests to Redis, the number of preset query queues, and the length of each query queue.
[0167] Based on the number of queues and the queue length, the number of query requests is allocated to each of the query queues.
[0168] In some embodiments of this application, before the Redis-based performance tuning device performs the task of allocating Redis query requests to a preset query queue, it includes:
[0169] The average latency of Redis query requests is retrieved through the preset query service module;
[0170] Receive the expected latency set by the user, and configure the number and length of the corresponding query queue in Redis based on the expected latency and the average latency;
[0171] The average delay is set as the initial timeout for the expiration notification, and the number of queues and the queue length are set as the initial queue information for the query queue.
[0172] This embodiment uses a Redis-based performance tuning device that: allocates Redis query requests to a preset query queue; if the query queue receives an expiration notification, it assembles each query request in the queue into a communication channel and submits it to Redis; it receives the query results fed back by Redis based on the communication channel, and determines whether the Redis system performance meets the requirements based on the response time associated with the query results; if the Redis system performance does not meet the requirements, it adjusts the timeout time corresponding to the expiration notification and / or the queue information of the query queue until the Redis system performance meets the requirements. In this embodiment, based on the response time associated with the query request, it is possible to determine whether the Redis system has a response delay, and then determine whether the Redis system performance meets the requirements; if the Redis system performance does not meet the requirements, the timeout time and / or the queue information of the query queue corresponding to the Redis system are dynamically adjusted to make the Redis system performance meet the requirements. This does not require adding hardware to the Redis system or manual intervention; the Redis system performance can be improved through simple parameter adjustments.
[0173] This invention also provides an electronic device, such as... Figure 9 As shown, Figure 9 This is a schematic diagram of an embodiment of the electronic device provided in this application.
[0174] The electronic device integrates any of the Redis-based performance tuning devices provided in the embodiments of the present invention, and the electronic device includes:
[0175] One or more processors;
[0176] Memory; and
[0177] One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the processor in any of the embodiments of the Redis-based performance tuning method described above.
[0178] Specifically, electronic devices may include components such as processors 801 with one or more processing cores, memory 802 with one or more computer storage media, power supply 803, and input units 804. Those skilled in the art will understand that... Figure 9 The electronic device structure shown does not constitute a limitation on the electronic device and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0179] in:
[0180] The processor 801 is the control center of the electronic device. It connects various parts of the electronic device via various interfaces and lines. By running or executing software programs and / or modules stored in the memory 802, and by calling data stored in the memory 802, it performs various functions and processes data, thereby providing overall monitoring of the electronic device. Optionally, the processor 801 may include one or more processing cores; preferably, the processor 801 may integrate an application processor and a modem processor, wherein the application processor mainly handles performance tuning systems, user interfaces, and applications, while the modem processor mainly handles wireless communication. It is understood that the modem processor may not be integrated into the processor 801.
[0181] The memory 802 can be used to store software programs and modules. The processor 801 executes various functional applications and data processing by running the software programs and modules stored in the memory 802. The memory 802 may mainly include a program storage area and a data storage area. The program storage area may store the performance tuning system, application programs required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device, etc. In addition, the memory 802 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, the memory 802 may also include a memory controller to provide the processor 801 with access to the memory 802.
[0182] The electronic device also includes a power supply 803 that supplies power to the various components. Preferably, the power supply 803 can be logically connected to the processor 801 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. The power supply 803 may also include one or more DC or AC power supplies, recharging systems, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components.
[0183] The electronic device may also include an input unit 804, which can be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.
[0184] Although not shown, the electronic device may also include a display unit, etc., which will not be described in detail here. Specifically, in this embodiment, the processor 801 in the electronic device loads the executable files corresponding to the processes of one or more application programs into the memory 802 according to the following instructions, and the processor 801 runs the application programs stored in the memory 802 to realize various functions, as follows:
[0185] Distribute Redis query requests to a predefined query queue;
[0186] If the query queue receives an expiration notification, it assembles each query request in the query queue into a communication pipe and submits it to Redis.
[0187] Receive the query results fed back by Redis based on the communication pipeline, and determine whether the system performance of Redis meets the requirements based on the response time associated with the query results;
[0188] If the Redis system performance does not meet the requirements, the timeout time corresponding to the expiration notification and / or the queue information of the query queue will be adjusted until the Redis system performance meets the requirements.
[0189] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer storage medium and loaded and executed by a processor.
[0190] Therefore, embodiments of the present invention provide a computer storage medium, which may include: read-only memory (ROM), random access memory (RAM), a disk, or an optical disk, etc. A computer program is stored thereon, which is loaded by a processor to execute the steps in any of the Redis-based performance tuning methods provided in the embodiments of the present invention. For example, the computer program loaded by the processor can execute the following steps:
[0191] Distribute Redis query requests to a predefined query queue;
[0192] If the query queue receives an expiration notification, it assembles each query request in the query queue into a communication pipe and submits it to Redis.
[0193] Receive the query results fed back by Redis based on the communication pipeline, and determine whether the system performance of Redis meets the requirements based on the response time associated with the query results;
[0194] If the Redis system performance does not meet the requirements, the timeout time corresponding to the expiration notification and / or the queue information of the query queue will be adjusted until the Redis system performance meets the requirements.
[0195] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the detailed descriptions of other embodiments above, which will not be repeated here.
[0196] In practice, each of the above units or structures can be implemented as an independent entity or can be arbitrarily combined to be implemented as the same or several entities. For the specific implementation of each of the above units or structures, please refer to the previous method embodiments, which will not be repeated here.
[0197] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.
[0198] The above provides a detailed description of a Redis-based performance tuning method provided by the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. A performance tuning method based on Redis, characterized in that, The Redis-based performance tuning method includes: Distribute Redis query requests to a predefined query queue; If the query queue receives an expiration notification, it assembles each query request in the query queue into a communication pipe and submits it to Redis. Receive the query results fed back by Redis based on the communication pipeline, and determine whether the system performance of Redis meets the requirements based on the response time associated with the query results; If the Redis system performance does not meet the requirements, the timeout time corresponding to the expiration notification and the queue information of the query queue are adjusted until the Redis system performance meets the requirements. The step of receiving the query results from Redis based on the communication pipeline, and determining whether the Redis system performance meets the requirements based on the response time associated with the query results, includes: Receive the query result fed back by Redis based on the communication pipeline, and obtain the response time associated with the query result; Statistically analyze the response times associated with each query result and calculate the average latency of the Redis instance; If the average latency exceeds a preset latency threshold, the system performance of Redis is determined to be unsatisfactory.
2. The performance tuning method based on Redis according to claim 1, characterized in that, If the query queue receives an expiration notification, before assembling the query requests in the query queue into a communication pipeline and submitting it to Redis, the method includes: The system controls a preset time wheel to allocate timeout periods to the query queue and controls the query queue to request an expiration notification channel from the time wheel. If there are at least two query queue request expiration notification channels, then obtain the queue identifier of the query queue that has exceeded the timeout period; The expiration notification is sent to the query queue corresponding to the queue identifier through the expiration notification pipeline.
3. The performance tuning method based on Redis according to claim 1, characterized in that, If the Redis system performance does not meet the requirements, the timeout time corresponding to the expiration notification and the queue information of the query queue will be adjusted until the Redis system performance meets the requirements, including: If the Redis system performance does not meet the requirements, the timeout period corresponding to the expiration notification, the number of queues in the query queue, or the queue length of the query queue will be adjusted. Obtain the new query results corresponding to the adjusted query queue, and determine the new average latency based on the response time associated with the new query results; The system performance of Redis is determined to meet the requirements until the new average latency does not exceed the preset latency threshold.
4. The performance tuning method based on Redis according to claim 3, characterized in that, The process of determining that the Redis system performance meets the requirements until the new average latency does not exceed a preset latency threshold includes: If the new average latency does not exceed the preset latency threshold, then obtain the CPU utilization and memory utilization of Redis; If the CPU utilization of Redis exceeds a preset utilization threshold, or the memory utilization of Redis exceeds a preset utilization threshold, then the timeout period corresponding to the expiration notification, the number of queues in the query queue, or the length of the query queue will be adjusted in reverse. If the CPU utilization and memory utilization of Redis do not exceed the preset utilization threshold, then the system performance of Redis is determined to meet the requirements.
5. The performance tuning method based on Redis according to claim 1, characterized in that, The step of allocating Redis query requests to a preset query queue includes: The query service module parses the query request and extracts the query request to Redis. Get the number of query requests to Redis, the number of preset query queues, and the length of each query queue. Based on the number of queues and the queue length, the number of query requests is allocated to each of the query queues.
6. The performance tuning method based on Redis according to any one of claims 1-5, characterized in that, Before allocating Redis query requests to a preset query queue, the method includes: The average latency of Redis query requests is retrieved through the preset query service module; Receive the expected latency set by the user, and configure the number and length of the corresponding query queue in Redis based on the expected latency and the average latency; The average delay is set as the initial timeout for the expiration notification, and the number of queues and the queue length are set as the initial queue information for the query queue.
7. A performance tuning device based on Redis, characterized in that, The Redis-based performance tuning device includes: The allocation module is used to distribute Redis query requests to a preset query queue; An assembly module is used to assemble each query request in the query queue into a communication pipe and submit it to Redis if the query queue receives an expiration notification; The determination module is used to receive the query results fed back by Redis based on the communication pipeline, and determine whether the system performance of Redis meets the requirements based on the response time associated with the query results; An adjustment module is used to adjust the timeout time corresponding to the expiration notification and the queue information of the query queue if the system performance of Redis does not meet the requirements, until the system performance of Redis meets the requirements. The determining module is specifically used for: Receive the query result fed back by Redis based on the communication pipeline, and obtain the response time associated with the query result; Statistically analyze the response times associated with each query result and calculate the average latency of the Redis instance; If the average latency exceeds a preset latency threshold, the system performance of Redis is determined to be unsatisfactory.
8. An electronic device, characterized in that, The electronic device includes: One or more processors; Memory; and One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the processor to implement the steps in the Redis-based performance tuning method according to any one of claims 1 to 6.
9. A computer storage medium, characterized in that, It stores a computer program, which is loaded by a processor to perform the steps in the Redis-based performance tuning method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Timeout time dynamic adjustment method and system based on Redis distributed lock
CN110162384A
Distributed ID generation method and device based on Redis and medium
CN114153893A