Program startup method, system, electronic device and storage medium
By allowing external requests to be received when the program is started and requesting the cache center to obtain data through the network, the cached data is loaded directly from the server's local file, which solves the problem of slow cache loading in the existing technology and achieves fast startup and reduced service unavailability time. Effect.
Patent Information
- Application Number
- CN202311413233.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-27
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2043-10-27
AI Technical Summary
In the existing technology, the slow loading of cached data during application startup results in system startup speed bottlenecks and long service unavailability. In particular, when a large amount of data is loaded, the application needs to wait for the local cache to be loaded.
When the business program starts, it is allowed to receive external requests and obtain cached data through the network request cache center interface, load the cached data directly from the server's local file, reduce the time-consuming network and database queries, and use the cache center to process unloaded requests.
It significantly speeds up program startup, reduces service unavailability time, relieves load pressure by distributing requests to multiple cache centers for processing, and optimizes the large cache loading process.
Smart Images

Figure CN117608679B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a program startup method, system, electronic device and storage medium. Background Art
[0002] Local caching is a technology that stores data in application memory, including database query result cache, calculation result cache, API response result cache, etc. When the application starts, some commonly used data can be loaded and preheated to the local cache in advance to improve the performance and response speed of subsequent applications.
[0003] Reference Figure 1 The existing technology is to load data into the local cache by continuously accessing the database to query data during the application startup process. Because the program operation depends on the access to this part of data, the current common solution is to synchronously wait for the cache to be loaded before the program can provide normal services to the outside world.
[0004] Under the above application local cache loading strategy, as the program runs, more and more cached data will be cached, and database queries will become slower and slower. Since the number of times the database needs to be queried increases, the time spent on the network link will also increase. For each restart of the program, the time required to wait for the local cache to load will become longer and longer, ranging from a few minutes to more than ten minutes.
[0005] In the existing cache loading solution, when loading a large amount of data, it is necessary to continuously go through the following links: business program → network (time consumption T0) → database → disk access (time consumption T1) → database → network (time consumption T2) → business program. The main time consumption points of the whole process are calculated as: total time consumption = T0 + T1 + T2. A large number of network transmission and database query operations will cause the entire system cache data to load very slowly, becoming a bottleneck for the system startup speed. At the same time, the business program needs to wait for the cache to be loaded before it can provide services to the outside world. During this period, the service will be unavailable. Summary of the invention
[0006] The present invention aims to solve one of the technical problems in the related art at least to a certain extent. To this end, the present invention provides a method, system, electronic device and storage medium for starting a program with high speed and short time consumption.
[0007] On the one hand, an embodiment of the present invention provides a program startup method, including:
[0008] When the first cache data does not exist locally on the server where the business program is located, loading the first cache data from the database to the business local cache, and saving the first cache data locally on the server;
[0009] When the first cache data exists locally on the server, loading the first cache data from the local server to the service local cache;
[0010] During the loading process of the first cache data, allowing the business program to receive external requests;
[0011] According to the external request, request the cache center for the second data through the network request cache center interface;
[0012] The external request is processed according to the second data until the first cache data is loaded completely.
[0013] Optionally, when the first cache data does not exist locally on the server where the business program is located, loading the first cache data from the database to the business local cache, and saving the first cache data locally on the server includes:
[0014] Accessing the database to perform a query operation and obtain first cache data;
[0015] Saving the first cache data to the business local cache;
[0016] The first cache data is compressed and written into a local file on the server.
[0017] Optionally, when the first cache data exists locally on the server, loading the first cache data from the local server includes:
[0018] Reading a local file on the server to obtain first cache data;
[0019] The first cache data is refreshed to the service local cache.
[0020] Optionally, the step of the cache center processing the external request includes:
[0021] Receiving the external request sent by the business program to the cache center through the network request cache center interface;
[0022] Detect whether the second cache data has been loaded and obtain a detection result;
[0023] When the detection result is loading, querying the database data through the request key value of the external request to obtain the third data;
[0024] When the detection result is loaded, query the local cache of the cache center through the request key value of the external request to obtain the second cache data;
[0025] The third data or the second cache data is used as the second data and returned to the business program.
[0026] Optionally, the business program includes a global business local cache identifier for identifying a loading state of the business local cache;
[0027] The cache center includes a global cache center local cache identifier, which is used to identify the loading status of the cache center cache.
[0028] Optionally, the network request cache center interface is a REST interface or an RPC interface.
[0029] Optionally, the method further comprises:
[0030] The external request is distributed to the plurality of cache centers for processing.
[0031] On the other hand, an embodiment of the present invention further provides a program startup system, including:
[0032] The first module is used for loading the first cache data from the database to the business local cache when the first cache data does not exist locally on the server where the business program is located, and saving the first cache data locally on the server;
[0033] A second module is configured to load the first cache data from the local server to the service local cache when the first cache data exists locally on the server;
[0034] A third module is used to allow the business program to receive an external request during the loading process of the first cache data;
[0035] A fourth module is used to request second data from the cache center through a network request cache center interface according to the external request;
[0036] The fifth module is used to process the external request according to the second data until the first cache data is loaded.
[0037] On the other hand, an embodiment of the present invention further provides an electronic device, including: a processor and a memory; the memory is used to store programs; the processor executes the program to implement the method described above.
[0038] On the other hand, an embodiment of the present invention further provides a computer storage medium, in which a program executable by a processor is stored. When the program executable by the processor is executed by the processor, it is used to implement the method as described above.
[0039] The embodiment of the present invention has the following beneficial effects: when the business program is started for the second time to the Nth time, since the server has saved the first cache data locally at the first startup, and directly reads the file from the local hard disk for sequential reading and writing, the data reading efficiency is high, and no network link consumption is required, thereby reducing network requests and database queries, avoiding time-consuming operations in the process of obtaining cache data, and multiple startups significantly speed up the program startup speed as a whole; in addition, when the business program is started, if the local cache is not loaded, when an external request enters the service at this time, the specified cache data can be obtained through the network request cache center interface, which solves the problem that the program must wait for the local cache data to be loaded before it can start and provide services to the outside world, improves the program startup speed under a large cache, and greatly reduces the time when the service is unavailable. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] The accompanying drawings are used to provide a further understanding of the technical solution of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the technical solution of the present invention and do not constitute a limitation on the technical solution of the present invention.
[0041] Figure 1 It is a schematic diagram of the existing program startup flow;
[0042] Figure 2 is a step diagram of a program startup method provided by an embodiment of the present invention;
[0043] Figure 3 is a flowchart of a program startup method provided by an embodiment of the present invention;
[0044] Figure 4 is a flowchart of step S100 provided in an embodiment of the present invention;
[0045] Figure 5 is a flowchart of step S200 provided in an embodiment of the present invention;
[0046] Figure 6 It is a schematic diagram of the interaction between the business program and the cache center provided by an embodiment of the present invention;
[0047] Figure 7 It is a schematic diagram of a process of a cache center processing a request provided by an embodiment of the present invention;
[0048] Figure 8 It is a schematic diagram of allocating external requests of a business program provided by an embodiment of the present invention to multiple cache centers for processing;
[0049] Fig. 9 is a schematic diagram of the structure of a program startup system provided by an embodiment of the present invention;
[0050] Fig.10is a schematic structural diagram of an electronic device provided by an embodiment of the present invention;
[0051] Fig.11 It is a comparison diagram of the existing solution provided by the embodiment of the present invention and the method flow of the embodiment of the present invention. DETAILED DESCRIPTION
[0052] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0053] It should be noted that, although the functional modules are divided in the system schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the system or the order in the flowchart. The terms "first / S100", "second / S200", etc. in the specification, claims and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0054] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present invention. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0055] In view of the problems of slow startup speed, high startup time and long service unavailability of large cache programs in the prior art, the embodiments of the present invention provide a program startup method, system, electronic device and storage medium.
[0056] First, some technical terms involved in the embodiments of the present invention are explained as follows:
[0057] Local cache: Local cache is a technology that stores data in application memory, including database query result cache, calculation result cache, API response result cache, etc. When the application starts, some commonly used data can be loaded and preheated to the local cache in advance to improve the performance and response speed of subsequent applications.
[0058] Business local cache: Business local cache refers to the local cache in the business program.
[0059] Local server: The server is a hardware device that carries business programs. The local hard disk of the server has file locations that can store business program data. The stored business files can be called local files.
[0060] Network request cache center interface: The network request cache center interface is an interface for business programs to interact with the cache center for data requests. In the present invention, the interface can be a REST interface or an RPC interface.
[0061] Cache center: The cache center is a service similar to ordinary business programs. Its main function is to achieve unified management of business caches and provide a way to obtain business caches through interface requests when business programs need them. Multiple cache center nodes can be deployed, and when business programs make network requests, they can be load balanced to any cache center node for processing, thereby improving the load capacity of the cache center.
[0062] Cache center local cache: Cache center local cache refers to the local cache in the cache center. The following describes the program startup method of the embodiment of the present invention, referring to Figure 2 and Figure 3 , Figure 2 is a step diagram of a program startup method provided by an embodiment of the present invention, Figure 3 It is a flowchart of a program startup method provided by an embodiment of the present invention. The method may include but is not limited to the following S100 to S500.
[0063] S100: When the first cache data does not exist locally on the server where the business program is located, the first cache data is loaded from the database to the business local cache, and the first cache data is saved locally on the server.
[0064] Reference Figure 4 , Figure 4 This is a flow chart of step S100 provided by an embodiment of the present invention. When there is no local file, the first cache data is still loaded by querying the database and the first cache data is saved in the service local file. Step S100 may specifically include the following S110 to S130.
[0065] S110: Access a database to perform a query operation and obtain first cache data.
[0066] S120: Save the first cache data to the service local cache.
[0067] S130: compress the first cache data and write the data into a local file of the server.
[0068] S200: When the first cache data exists locally on the server, load the first cache data from the local server to the service local cache.
[0069] Reference Figure 5 , Figure 5 This is a flow chart of step S200 provided by an embodiment of the present invention. When there is a local file, it is only necessary to directly access the local file to load the first cache data. Step S200 may specifically include the following steps S210 to S220.
[0070] S210: Read the local file of the server to obtain first cache data.
[0071] S220: Refresh the first cache data to the service local cache.
[0072] In combination with S100 and S200, it should be noted that when the business program is started for the second time to the Nth time, since the server has saved the first cache data locally when it was started for the first time, and reads the file directly from the local hard disk for sequential reading and writing, the data reading efficiency is high, and does not require the consumption of network links, thereby reducing network requests and database queries, avoiding time-consuming operations in the process of obtaining cached data, and multiple startups have significantly accelerated the speed of program startup as a whole.
[0073] S300: During the loading process of the first cache data, the business program is allowed to receive external requests.
[0074] In the embodiment of the present invention, when the program is started, the service program is allowed to receive external access requests during the loading process of the first cache data.
[0075] S400. According to the external request, request the cache center for second data through a network request cache center interface.
[0076] Reference Figure 6 , Figure 6 This is a schematic diagram of the interaction between the business program and the cache center provided by an embodiment of the present invention. According to an external request, when the cache data is not loaded, the business program (business program) can request the cache center through the network request cache center interface to request the second data to process the request. The second data refers to the data obtained by the cache center, which can come from the cache of the cache center, or from the cache center accessing the database according to the request.
[0077] A global identifier is maintained inside the business program, which is called the business local cache representation. When the local cache is loaded, the business local cache identifier can be represented as "loaded", and when the local cache is not loaded, the business local cache identifier can be represented as "loading". By judging the representation state of the business local cache identifier, it is judged whether it is currently necessary to request the second data from the cache center through the network request cache center interface.
[0078] Specifically, when the business local cache is marked as "loading", if an external request comes in, the second data is requested from the cache center through the network cache center interface to process the request; if the mark is "loaded", the local cache is directly accessed to obtain the required data.
[0079] Reference Figure 7 , Figure 7 It is a flowchart of the cache center processing request provided in the embodiment of the present invention. The cache center is a buffer module between the business program and the database in the embodiment of the present invention. The cache center loads data from the database and temporarily stores it in the cache center for providing it to the business program to process external requests. The data loading process of the cache center is the same as that of the business program module, and also retains a cache loading identifier, which is called the cache center cache identifier. When the cache status of the cache center is "loaded", the cache center searches the local cache by requesting the key value and returns the result to the requester; when the cache status of the cache center is "loading", the database is queried by requesting the key value to obtain data.
[0080] Based on this, the steps of the cache center processing external requests may include the following steps a to e:
[0081] a. receiving the external request sent by the business program to the cache center through the network request cache center interface;
[0082] b. Detect whether the second cache data has been loaded and obtain a detection result;
[0083] c. When the detection result is loading, query the database data through the request key value of the external request to obtain the third data;
[0084] d. When the detection result is that the data has been loaded, query the local cache of the cache center through the request key value of the external request to obtain the second cache data;
[0085] e. Use the third data or the second cache data as the second data and return it to the business program.
[0086] The network request cache center interface may be a REST interface or an RPC interface.
[0087] S500: Process the external request according to the second data until the first cache data is loaded completely.
[0088] In some embodiments, the program starting method of the embodiment of the present invention may further include S600.
[0089] S600: Distribute the external request to multiple cache centers for processing.
[0090] like Figure 8 As shown, there can be multiple cache centers in the embodiment of the present invention, and the cache centers are indifferent, that is, when multiple cache center services are deployed, the result returned by the requester is the same no matter which cache center the requester requests. Distributing external requests to multiple cache centers for processing can alleviate the load pressure that may be caused by receiving a large number of business requests and sending them to the cache center during the business program loading process.
[0091] On the other hand, Fig. 9 As shown, the embodiment of the present invention further provides a program startup system, including:
[0092] The first module is used for loading the first cache data from the database to the business local cache when the first cache data does not exist locally on the server where the business program is located, and saving the first cache data locally on the server;
[0093] A second module is configured to load the first cache data from the local server to the service local cache when the first cache data exists locally on the server;
[0094] A third module is used to allow the business program to receive an external request during the loading process of the first cache data;
[0095] A fourth module is used to request second data from the cache center through a network request cache center interface according to the external request;
[0096] The fifth module is used to process the external request according to the second data until the first cache data is loaded.
[0097] It should be noted that in some embodiments, the system may further include the following modules:
[0098] The sixth module is used to distribute the external request to multiple cache centers for processing.
[0099] On the other hand, Fig.10 As shown, an embodiment of the present invention further provides an electronic device, including: a processor and a memory; the memory is used to store programs; the processor executes the program to implement the method described above.
[0100] On the other hand, an embodiment of the present invention further provides a computer storage medium, in which a program executable by a processor is stored. When the program executable by the processor is executed by the processor, it is used to implement the method as described above.
[0101] The embodiments of the present invention have the following beneficial effects:
[0102] 1. By optimizing the method of reading the database to obtain cache data when the business program starts, it is optimized to read the local files of the server where the business program is located. At the same time, a cache center module is created. When the business program has not loaded the cache, the cache center is requested to obtain the cache data through the network. This achieves a faster loading speed for the large cache when the business program is restarted, and the service can be provided to the outside without waiting for the local large amount of cache to be loaded, which greatly optimizes the startup speed.
[0103] 2. Reference Fig.11 The present invention creates a cache center module. When the business program has not loaded the cache completely, it requests the cache center to obtain cache data through the network. This achieves a faster loading speed for the large cache when the business program is restarted, and the service can be provided to the outside without waiting for the local large amount of cache to be loaded. The startup speed is greatly optimized compared with the existing solution.
[0104] 3. Distributing external requests to multiple cache centers for processing can alleviate the load pressure that may be caused by receiving a large number of business requests and sending them to the cache center during the business program loading process.
[0105] In some selectable embodiments, the function / operation mentioned in the block diagram may not occur in the order mentioned in the operation diagram. For example, depending on the function / operation involved, the two boxes shown in succession can actually be executed substantially simultaneously or the boxes can sometimes be executed in reverse order. In addition, the embodiment presented and described in the flow chart of the present invention is provided by way of example, for the purpose of providing a more comprehensive understanding of technology. The disclosed method is not limited to the operation and logic flow presented herein. Selectable embodiments are expected, wherein the order of various operations is changed and the sub-operation of a part for which is described as a larger operation is performed independently.
[0106] In addition, although the present invention is described in the context of functional modules, it should be understood that, unless otherwise specified, one or more of the functions and / or features described may be integrated into a single physical device and / or software module, or one or more functions and / or features may be implemented in separate physical devices or software modules. It is also understood that a detailed discussion of the actual implementation of each module is unnecessary for understanding the present invention. More specifically, in view of the properties, functions, and internal relationships of the various functional modules in the device disclosed herein, the actual implementation of the module will be understood within the conventional skills of the engineer. Therefore, those skilled in the art can implement the present invention set forth in the claims without excessive experimentation using ordinary techniques. It is also understood that the specific concepts disclosed are merely illustrative and are not intended to limit the scope of the present invention, which is determined by the full scope of the appended claims and their equivalents.
[0107] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc., which can store program codes.
[0108] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by an instruction execution system, device or apparatus (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or apparatus and execute instructions), or in conjunction with such instruction execution systems, devices or apparatuses. For the purposes of this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate or transmit a program for use by an instruction execution system, device or apparatus, or in conjunction with such instruction execution systems, devices or apparatuses.
[0109] More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection with one or more wires (electronic device), a portable computer disk case (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be a paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, deciphering or, if necessary, processing in another suitable manner, and then stored in a computer memory.
[0110] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, a plurality of steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0111] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "examples", "specific examples", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
[0112] Although the embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the claims and their equivalents.
[0113] The above is a specific description of the preferred implementation of the present invention, but the present invention is not limited to the described embodiments. Those skilled in the art may make various equivalent modifications or substitutions without violating the spirit of the present invention. These equivalent modifications or substitutions are all included in the scope defined by the claims of the present invention.
Claims
1. A program startup method, It is characterized in that include: When the first cache data does not exist locally on the server where the business program is located, loading the first cache data from the database to the business local cache, and saving the first cache data locally on the server; When the first cache data exists locally on the server, loading the first cache data from the local server to the service local cache; During the loading process of the first cache data, allowing the business program to receive external requests; According to the external request, request the cache center for second data through a network request cache center interface to process the external request; The external request is processed according to the second data until the first cache data is loaded completely.
2. A program startup method according to claim 1, It is characterized in that When the first cache data does not exist locally on the server where the business program is located, loading the first cache data from the database to the business local cache, and saving the first cache data locally on the server, includes: Accessing the database to perform a query operation and obtain first cache data; Saving the first cache data to the business local cache; The first cache data is compressed and written into a local file on the server.
3. A program startup method according to claim 1, It is characterized in that When the first cache data exists locally on the server, loading the first cache data from the local server includes: Reading a local file on the server to obtain first cache data; The first cache data is refreshed to the service local cache.
4. A program startup method according to claim 1, It is characterized in that The business program includes a global business local cache identifier inside, which is used to identify the loading status of the business local cache; The cache center includes a global cache center local cache identifier, which is used to identify the loading status of the cache center cache.
5. A program startup method according to claim 1, It is characterized in that The network request cache center interface is a REST interface or an RPC interface.
6. A program startup method according to claim 1, It is characterized in that The method further comprises: The external request is distributed to the plurality of cache centers for processing.
7. A program startup system, It is characterized in that include: The first module is used for loading the first cache data from the database to the business local cache when the first cache data does not exist locally on the server where the business program is located, and saving the first cache data locally on the server; A second module is configured to load the first cache data from the local server to the service local cache when the first cache data exists locally on the server; A third module is used to allow the business program to receive an external request during the loading process of the first cache data; A fourth module is used to request second data from the cache center through a network request cache center interface according to the external request, so as to process the external request; The fifth module is used to process the external request according to the second data until the first cache data is loaded.
8. An electronic device, It is characterized in that including a processor and a memory; The memory is used to store programs; The processor executes the program to implement the method according to any one of claims 1 to 6.
9. A computer storage medium having stored therein a program executable by a processor, It is characterized in that The program executable by the processor is used to implement the method according to any one of claims 1 to 6 when executed by the processor.
