Server time consumption optimization method

By implementing a server-side time-consuming optimization method, including querying Redis cache interface data in node service and creating scheduling task services, the problem of small time-consuming optimization space on the server and difficult to take into account timeliness and performance optimization on the server is solved, and the effect of improving interface hit rate and ensuring timeliness is achieved, reducing the time-consuming of the server.

CN119892632APending Publication Date: 2025-04-25BEIJING BITE YIPAI INFORMATION TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510005061.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-02
Publication Date
2025-04-25

AI Technical Summary

Technical Problem

In the existing technology, the server side consumes little time-consuming optimization space, the business processing itself takes short time, the necessary business processing logic cannot be optimized, and the overall optimization space is small, requiring assistance from other teams; interface performance optimization is difficult to take into account both timeliness and performance. Redis cache time is short, the hit rate is not high, and the performance optimization effect is not obvious; cache time is long, data update is not timely, affecting the business.

Method used

By implementing a server-side time-consuming optimization method, including querying Redis cache interface data in the node service first, if it cannot be found, then requesting downstream interfaces and storing Redis; creating a scheduling task service, collecting, storing, and distributing interface information, using WebSocket to establish a connection with the node service, cache the interface data and synchronizing it to Redis; scheduling service regularly querying the interface list, and the node service querying the interface information from Redis based on the interface list and requesting the interface, and the correct result is stored in Redis; when the interface is added or updated, the interface information is sent to the scheduling service, and the scheduling service querys whether the interface exists and updates or adds the interface; and the invalid interface is cleared.

Benefits of technology

It solves the contradiction between interface hit rate and timeliness in Redis cache, improves interface hit rate and ensures interface timeliness, thereby reducing the timeliness of the server, optimizing code logic, reducing unnecessary loop code and steps, reducing code execution time and time-consuming requesting interfaces in the business.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119892632A_ABST
    Figure CN119892632A_ABST
Patent Text Reader

Abstract

The invention discloses a server-side time consumption optimization method, which comprises the following steps that: a node service creates a scheduling task service according to the access of a client, and is responsible for collecting, storing and distributing interface information; establishing connection with the node service by using the webSocket service, distributing an interface list Key by the node service according to the scheduling service, querying complete interface request information from the Redis, respectively requesting the interface information, and clearing invalid interfaces; according to the method, the contradiction between the interface hit rate and the interface timeliness in the conventional Redis cache is solved, the interface timeliness is ensured while the interface hit rate is improved, so that the time consumption of a server side is reduced, the code logic is optimized, unnecessary loop codes are reduced, unnecessary steps are combined, the code execution time is shortened, and the service life of the server side is prolonged. According to the method, the time consumed for requesting the interface in the service is shortened, and the method mainly comprises the steps of optimizing the downstream interface, caching the interface data by using Redis and caching the downstream interface data by using Redis, so that the time consumed for requesting the downstream interface is shortened.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a server-side time-consuming optimization method, and belongs to the technical field of server-side time-consuming optimization application. Background Art

[0002] Server time consumption usually refers to the time it takes for the server to process the client request. This time includes the entire process from the server receiving the request to the server completing the request processing and returning a response to the client. Server time consumption is an important indicator to measure server performance, which is of great significance for optimizing user experience and improving system efficiency.

[0003] There is little room for optimization. Business processing itself takes a very short time. The necessary business processing logic cannot be optimized. The overall room for optimization is small and requires assistance from other teams: Interface performance optimization is what the downstream team has to do, and interface optimization will stabilize after reaching a certain value. It is difficult to choose between timeliness and performance. If the Redis cache is set for a short time, the Redis hit rate is not high, and the performance optimization effect is not obvious; if the Redis cache time is set for a long time, data updates are not timely, which can easily affect the business. Summary of the invention

[0004] In this embodiment, a server-side time-consuming optimization method is provided to solve the problems in the prior art where the optimization space is small, the business processing itself takes a very short time, the necessary business processing logic cannot be optimized, and the overall optimization space is small, requiring assistance from other teams: interface performance optimization is what the downstream team has to do, and the interface optimization will stabilize after reaching a certain value. It is difficult to make a trade-off between timeliness and performance. If the Redis cache time is set to a short time, the Redis hit rate is not high, and the performance optimization effect is not obvious; if the Redis cache time is set to a long time, the data is not updated in time, which is easy to affect the business.

[0005] The present invention achieves the above-mentioned purpose through the following technical scheme, a server-side time consumption optimization method, and the server-side time consumption optimization method comprises the following steps:

[0006] S1. Node service queries Redis cache interface data based on client access. If data is found, it returns directly to the client. If no Redis data is found, it requests the downstream interface and returns it to the client. If there is no abnormality in the interface data, it is stored in the redis data and the interface is added or updated to the scheduling service.

[0007] S2. Create a scheduling task service to collect, store, and distribute interface information. Use the webSocket service to establish a connection with the node service. Compress the interface information received from the node service into a data string of a certain size according to certain rules. Cache the data locally to increase query speed. And store a copy in the Redis database synchronously to ensure unique and long-term storage of data.

[0008] S3, the scheduling service queries the corresponding time to the interface list according to a certain time interval of 1 minute, 5 minutes, 10 minutes, 30 minutes, and 60 minutes;

[0009] S4. The node service queries the complete interface request information from Redis according to the interface list key assigned by the scheduling service, and then requests the interface information separately. If the result is correct, it will be stored in the Redis cache.

[0010] S5, interface addition or update: the node service sends the interface information to the scheduling service, and the scheduling service queries whether the current interface exists according to certain rules;

[0011] S6. Invalid interface clearing.

[0012] Preferably, the WebSocket service in step (S2) is a network service based on the WebSocket protocol, which realizes full-duplex communication between the client and the server.

[0013] Preferably, the Node service in the step (S2) generally refers to a service developed based on the Node.js platform. Node.js is a JavaScript runtime environment based on the Chrome V8 engine, which allows JavaScript code to run on the server side. The Node service is widely used in real-time communication, high concurrency, microservices and other fields due to its high efficiency, asynchronous, non-blocking I / O characteristics and event-driven design mode.

[0014] Preferably, the key is a string type, and the value supports multiple data types, including string, linked list, set, ordered set and hash type.

[0015] Preferably, in the step (S3), the time interface list is first obtained from the local cache, and if not, the interface list is obtained from Redis; and the list is evenly distributed and sent to the corresponding node services.

[0016] Preferably, the Redis database in step (S2) is an open source non-relational database, which can also be called a key-value storage. It runs based on memory and supports persistence. Redis is a key-value storage system inside.

[0017] Preferably, in the step (S5), the scheduling service inquires whether the current interface exists according to certain rules, and if so, updates the last request time of the interface; if not, adds the interface to the interface list.

[0018] Preferably, the time consumed by the server in the step (S6) is the time taken from entering the service, requesting the downstream interface and processing a series of operations by the business logic, to returning the business data.

[0019] Preferably, the scheduling service in step (S5) refers to orderly and efficient planning and arrangement of various resources or tasks to ensure that they can be completed within a specified time while meeting specific quality, cost and safety requirements;

[0020] Preferably, in the step (S6), the invalid interfaces are cleared when an interface has not initiated a request for one day and is considered an invalid interface. The invalid interfaces are checked at dawn every day and deleted to avoid multiple requests for useless interfaces.

[0021] The beneficial effects of the present invention are as follows: the server-side time-consuming optimization method in the present invention solves the contradiction between the interface hit rate and the interface timeliness in the conventional Redis cache, and improves the interface hit rate while ensuring the timeliness of the interface, thereby reducing the server-side time consumption, optimizing code logic, reducing unnecessary loop codes, merging unnecessary steps, reducing code execution time, and reducing the time consumption of requesting interfaces in the business, mainly downstream interface optimization, using Redis to cache interface data, and using Redis to cache downstream interface data to reduce the time consumption of requesting downstream interfaces. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] Figure 1 The figure is a flow chart of the method of the present invention.

[0023] Figure 2 It is a flow chart of the scheduling task of the present invention. DETAILED DESCRIPTION

[0024] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0025] Embodiment 1:

[0026] The server-side time-consuming optimization method comprises the following steps:

[0027] S1. Node service queries Redis cache interface data based on client access. If data is found, it returns directly to the client. If no Redis data is found, it requests the downstream interface and returns it to the client. If there is no abnormality in the interface data, it is stored in the redis data and the interface is added or updated to the scheduling service.

[0028] S2. Create a scheduling task service to collect, store, and distribute interface information. Use the webSocket service to establish a connection with the node service. Compress the interface information received from the node service into a data string of a certain size according to certain rules. Cache the data locally to increase query speed. And store a copy in the Redis database synchronously to ensure unique and long-term storage of data.

[0029] S3, the scheduling service queries the corresponding time to the interface list according to a certain time interval of 1 minute, 5 minutes, 10 minutes, 30 minutes, and 60 minutes;

[0030] S4. The node service queries the complete interface request information from Redis according to the interface list key assigned by the scheduling service, and then requests the interface information separately. If the result is correct, it will be stored in the Redis cache.

[0031] S5, interface addition or update: the node service sends the interface information to the scheduling service, and the scheduling service queries whether the current interface exists according to certain rules;

[0032] S6. Invalid interface clearing.

[0033] Preferably, the WebSocket service in step (S2) is a network service based on the WebSocket protocol, which realizes full-duplex communication between the client and the server.

[0034] Preferably, the Node service in the step (S2) generally refers to a service developed based on the Node.js platform. Node.js is a JavaScript runtime environment based on the Chrome V8 engine, which allows JavaScript code to run on the server side. The Node service is widely used in real-time communication, high concurrency, microservices and other fields due to its high efficiency, asynchronous, non-blocking I / O characteristics and event-driven design mode.

[0035] Preferably, the key is a string type, and the value supports multiple data types, including string, linked list, set, ordered set and hash type.

[0036] Preferably, in the step (S3), the time interface list is first obtained from the local cache, and if not, the interface list is obtained from Redis; and the list is evenly distributed and sent to the corresponding node services.

[0037] Preferably, the Redis database in step (S2) is an open source non-relational database, which can also be called a key-value storage. It runs based on memory and supports persistence. Redis is a key-value storage system inside.

[0038] Preferably, in the step (S5), the scheduling service inquires whether the current interface exists according to certain rules, and if so, updates the last request time of the interface; if not, adds the interface to the interface list.

[0039] Preferably, the time consumed by the server in the step (S6) is the time taken from entering the service, requesting the downstream interface and processing a series of operations by the business logic, to returning the business data.

[0040] Preferably, the scheduling service in step (S5) refers to orderly and efficient planning and arrangement of various resources or tasks to ensure that they can be completed within a specified time while meeting specific quality, cost and safety requirements;

[0041] Preferably, in the step (S6), the invalid interfaces are cleared when an interface has not initiated a request for one day and is considered an invalid interface. The invalid interfaces are checked at dawn every day and deleted to avoid multiple requests for useless interfaces.

[0042] The above server-side time-consuming optimization method solves the contradiction between the interface hit rate and the interface timeliness in the conventional Redis cache, and improves the interface hit rate while ensuring the timeliness of the interface, thereby reducing the server-side time consumption, optimizing code logic, reducing unnecessary loop codes, merging unnecessary steps, reducing code execution time, and reducing the time consumption of requesting interfaces in the business. It is mainly downstream interface optimization, using Redis to cache interface data, and using Redis to cache downstream interface data to reduce the time consumption of requesting downstream interfaces.

[0043] Embodiment 2:

[0044] The server-side time-consuming optimization method comprises the following steps:

[0045] S1. Node service queries Redis cache interface data based on client access. If data is found, it returns directly to the client. If no Redis data is found, it requests the downstream interface and returns it to the client. If there is no abnormality in the interface data, it is stored in the redis data and the interface is added or updated to the scheduling service.

[0046] S2. Create a scheduling task service to collect, store, and distribute interface information. Use the webSocket service to establish a connection with the node service. Compress the interface information received from the node service into a data string of a certain size according to certain rules. Cache the data locally to increase query speed. And store a copy in the Redis database synchronously to ensure unique and long-term storage of data.

[0047] S3, the scheduling service queries the corresponding time to the interface list according to a certain time interval of 1 minute, 5 minutes, 10 minutes, 30 minutes, and 60 minutes;

[0048] S4. The node service queries the complete interface request information from Redis according to the interface list key assigned by the scheduling service, and then requests the interface information separately. If the result is correct, it will be stored in the Redis cache.

[0049] S5, interface addition or update: the node service sends the interface information to the scheduling service, and the scheduling service queries whether the current interface exists according to certain rules;

[0050] S6. Invalid interface clearing.

[0051] Preferably, the WebSocket service in step (S2) is a network service based on the WebSocket protocol, which realizes full-duplex communication between the client and the server.

[0052] Preferably, the Node service in the step (S2) generally refers to a service developed based on the Node.js platform. Node.js is a JavaScript runtime environment based on the Chrome V8 engine, which allows JavaScript code to run on the server side. The Node service is widely used in real-time communication, high concurrency, microservices and other fields due to its high efficiency, asynchronous, non-blocking I / O characteristics and event-driven design mode.

[0053] Preferably, the key is a string type, and the value supports multiple data types, including string, linked list, set, ordered set and hash type.

[0054] Preferably, in the step (S3), the time interface list is first obtained from the local cache, and if not, the interface list is obtained from Redis; and the list is evenly distributed and sent to the corresponding node services.

[0055] Preferably, the Redis database in step (S2) is an open source non-relational database, which can also be called a key-value storage. It runs based on memory and supports persistence. Redis is a key-value storage system inside.

[0056] Preferably, in the step (S5), the scheduling service inquires whether the current interface exists according to certain rules, and if so, updates the last request time of the interface; if not, adds the interface to the interface list.

[0057] Preferably, the time consumed by the server in the step (S6) is the time taken from entering the service, requesting the downstream interface and processing a series of operations by the business logic, to returning the business data.

[0058] Preferably, the scheduling service in step (S5) refers to orderly and efficient planning and arrangement of various resources or tasks to ensure that they can be completed within a specified time while meeting specific quality, cost and safety requirements;

[0059] Preferably, in the step (S6), the invalid interfaces are cleared when an interface has not initiated a request for one day and is considered an invalid interface. The invalid interfaces are checked at dawn every day and deleted to avoid multiple requests for useless interfaces.

[0060] The above server-side time-consuming optimization method solves the contradiction between the interface hit rate and the interface timeliness in the conventional Redis cache, and improves the interface hit rate while ensuring the timeliness of the interface, thereby reducing the server-side time consumption, optimizing code logic, reducing unnecessary loop codes, merging unnecessary steps, reducing code execution time, and reducing the time consumption of requesting interfaces in the business. It is mainly downstream interface optimization, using Redis to cache interface data, and using Redis to cache downstream interface data to reduce the time consumption of requesting downstream interfaces.

[0061] It will be apparent to those skilled in the art that the invention is not limited to the details of the exemplary embodiments described above and that the invention can be implemented in other specific forms without departing from the spirit or essential features of the invention. Therefore, the embodiments should be considered exemplary and non-limiting in all respects, and the scope of the invention is defined by the appended claims rather than the foregoing description, and it is intended that all variations falling within the meaning and scope of the equivalent elements of the claims be included in the invention. Any reference numeral in a claim should not be considered as limiting the claim to which it relates.

[0062] In addition, it should be understood that although the present specification is described according to implementation modes, not every implementation mode contains only one independent technical solution. This description of the specification is only for the sake of clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment may also be appropriately combined to form other implementation modes that can be understood by those skilled in the art.

Claims

1. A method for optimizing server-side time consumption, characterized in that: The server-side time-consuming optimization method comprises the following steps: S1. Node service queries Redis cache interface data based on client access. If data is found, it returns directly to the client. If no Redis data is found, it requests the downstream interface and returns it to the client. If there is no abnormality in the interface data, it is stored in the redis data and the interface is added or updated to the scheduling service. S2. Create a scheduling task service to collect, store and distribute interface information; Use the webSocket service to establish a connection with the node service, and compress the interface information received from the node service into a data string of a certain size according to certain rules. The data is cached locally to improve the query speed; and a copy is synchronously stored in the Redis database to ensure the uniqueness and long-term storage of the data. S3, the scheduling service queries the corresponding time to the interface list according to a certain time interval of 1 minute, 5 minutes, 10 minutes, 30 minutes, and 60 minutes; S4. The node service queries the complete interface request information from Redis according to the interface list key assigned by the scheduling service, and then requests the interface information separately. If the result is correct, it will be stored in the Redis cache. S5, interface addition or update: the node service sends the interface information to the scheduling service, and the scheduling service queries whether the current interface exists according to certain rules; S6. Invalid interface clearing.

2. The method for optimizing the time consumption of the server according to claim 1, characterized in that: The WebSocket service in step (S2) is a network service based on the WebSocket protocol, which implements full-duplex communication between the client and the server.

3. The method for optimizing the time consumption of the server according to claim 1, characterized in that: The Node service in the step (S2) generally refers to a service developed based on the Node.js platform. Node.js is a JavaScript runtime environment based on the Chrome V8 engine, which allows JavaScript code to run on the server side. The Node service is widely used in real-time communication, high concurrency, microservices and other fields due to its high efficiency, asynchronous, non-blocking I / O characteristics and event-driven design mode.

4. The method for optimizing the time consumption of the server according to claim 1, characterized in that: The key is of string type, and the value supports multiple data types, including string, linked list, set, ordered set and hash type.

5. The method for optimizing the time consumption of the server according to claim 1, characterized in that: In the step (S3), the time interface list is first obtained from the local cache. If not, the interface list is obtained from Redis; and the list is evenly distributed and sent to the corresponding node service.

6. The method for optimizing the time consumption of the server according to claim 1, characterized in that: In the step (S2), the Redis database is an open source non-relational database, which can also be called a key-value store. It runs based on memory and supports persistence. Redis is a key-value storage system inside.

7. The method for optimizing the time consumption of the server according to claim 1, characterized in that: In the step (S5), the scheduling service inquires whether the current interface exists according to certain rules. If it exists, the last request time of the interface is updated. If it does not exist, the interface is added to the interface list.

8. The method for optimizing the time consumption of the server according to claim 1, characterized in that: The time consumed by the server in the step (S6) is the time taken from entering the service, requesting the downstream interface and processing a series of operations by the business logic, to returning the business data.

9. The method for optimizing the time consumption of the server according to claim 1, characterized in that: The scheduling service in step (S5) refers to the orderly and efficient planning and arrangement of various resources or tasks to ensure that they can be completed within the specified time while meeting specific quality, cost and safety requirements.

10. The method for optimizing the time consumption of the server according to claim 1, characterized in that: In the step (S6), the invalid interface is cleared when an interface has not initiated a request for one day and is considered an invalid interface. The invalid interfaces are checked at dawn every day and deleted to avoid multiple requests for useless interfaces.