Data caching method, device, equipment, and storage medium
By counting the number of requests from multiple servers in the server cluster to determine hotspot data and caching it locally, it solves the problem of hotspot data judgment bias and system stability in a distributed environment, and achieves system stability under massive requests. Assure.
Patent Information
- Application Number
- CN202110331569.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-26
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2041-03-26
AI Technical Summary
In a distributed environment, a single server cannot accurately determine the hotspot data in the entire server cluster, resulting in hotspot data judgment bias and system stability problems. Especially when there are instantaneous massive requests, it may lead to a system avalanche.
By counting the number of requests for similar data received by multiple servers in the server cluster, it is determined whether the data is hot data. After it is determined to be hot data, all servers are notified to cache it locally to avoid impact on the data storage layer.
It improves the accuracy of hotspot data judgment, reduces the impact on the data storage layer and related dependent services, ensures the stability of the system, and avoids system avalanche.
Smart Images

Figure CN113765991B
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computer technology, and relate to but are not limited to data caching methods and devices, equipment, and storage media. Background Art
[0002] The network platform may receive a large number of data access requests in a short period of time. For example, when an e-commerce platform is promoting a product, it may receive a large number of access requests for product prices in a short period of time. When the network platform receives a large number of data access requests, it will cause excessive pressure on the server cluster, causing the system to avalanche and unable to continue to provide services to the outside world. Summary of the invention
[0003] In view of this, the data caching method, device, equipment, and storage medium provided in the embodiments of the present application can improve the accuracy of hot spot data judgment and cache hot spot data locally, thereby avoiding the impact of instantaneous massive requests on the data storage layer of the server cluster and related dependent services, and ensuring the stability of the system. The data caching method, device, equipment, and storage medium provided in the embodiments of the present application are implemented as follows:
[0004] The data caching method provided in an embodiment of the present application includes: determining the number of requests for the same type of data received by N servers in a server cluster; wherein N is greater than 1 and less than or equal to the total number of servers in the server cluster; determining whether the same type of data is hot data based on the number of requests; and in the case where the same type of data is the hot data, notifying each server in the server cluster to cache the hot data locally.
[0005] The data caching device provided in the embodiment of the present application includes: a determination module, used to determine the number of requests for the same type of data received by N servers in a server cluster; wherein N is greater than 1 and less than or equal to the total number of servers in the server cluster; the determination module is also used to determine whether the same type of data is the hot data based on the number of requests; a notification module is used to notify each server in the server cluster to cache the hot data locally when the same type of data is hot data.
[0006] An electronic device provided in an embodiment of the present application includes a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the processor executes the program, the method described in the embodiment of the present application is implemented.
[0007] The computer-readable storage medium provided in the embodiment of the present application stores a computer program thereon, and when the computer program is executed by a processor, the method provided in the embodiment of the present application is implemented.
[0008] In an embodiment of the present application, whether the same type of data is hot data is determined by determining the number of requests for the same type of data received by multiple servers in a server cluster, rather than determining whether the same type of data is hot data simply by the number of requests for the same type of data received by one server; in this way, the judgment result will not deviate too much, reducing the probability of judging hot data as non-hot data, thereby improving the accuracy of hot data judgment; and after determining the hot data, notifying each server in the server cluster to cache the hot data locally, so that when the server cluster receives an instantaneous massive request, it can directly obtain the data from the local cache of the server, without the need to centrally obtain the data from the data storage layer of the server cluster, thus avoiding the impact of instantaneous massive requests on the data storage layer of the server cluster and related dependent services, thereby ensuring the stability of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present application and are used together with the specification to illustrate the technical solution of the present application.
[0010] Figure 1 A schematic diagram of the implementation flow of the data caching method provided in the embodiment of the present application;
[0011] Figure 2 A schematic diagram of the implementation flow of another data caching method provided in an embodiment of the present application;
[0012] Figure 3 A schematic diagram of an implementation flow of another data caching method provided in an embodiment of the present application;
[0013] Figure 4 A schematic diagram of the relationship between the number of servers and the hit rate provided in the embodiment of the present application;
[0014] Figure 5 A schematic diagram of an implementation flow of another data caching method provided in an embodiment of the present application;
[0015] Figure 6 A flowchart of a method for determining hotspot data provided by an embodiment of the present application;
[0016] Figure 7 A schematic diagram of the main data structure of the computing queue provided in an embodiment of the present application;
[0017] Figure 8 A schematic diagram of the structure of a data cache device provided in an embodiment of the present application;
[0018] Fig. 9 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0019] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the specific technical solution of the present application will be further described in detail below in conjunction with the drawings in the embodiments of the present application. The following embodiments are used to illustrate the present application, but are not used to limit the scope of the present application.
[0020] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0021] In the following description, reference is made to “some embodiments”, which describe a subset of all possible embodiments, but it will be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0022] It should be pointed out that the terms "first\second\third" involved in the embodiments of the present application are used to distinguish similar or different objects, and do not represent a specific ordering of the objects. It can be understood that "first\second\third" can be interchanged in a specific order or sequence where permitted, so that the embodiments of the present application described here can be implemented in an order other than that illustrated or described here.
[0023] The embodiment of the present application provides a data caching method, which is applied to an electronic device, which can be a mobile terminal (such as a mobile phone, a tablet computer or a laptop computer, etc.), or a physical server, or a cloud server that provides basic cloud computing such as cloud services, cloud databases or cloud computing; the electronic device is included in a server cluster, which can be a server cluster composed of multiple independent physical servers, or a cloud server cluster composed of cloud servers. The function implemented by the method can be implemented by calling the program code by the processor in the electronic device, and of course the program code can be stored in an electronic storage medium. It can be seen that the electronic device at least includes a processor and a storage medium.
[0024] In order to facilitate a clear understanding of the solution, the data caching method provided by the embodiment of the present application is described by taking the first server implementing the following method as an example. However, this does not limit the type of the execution subject.
[0025] Figure 1 A schematic diagram of the implementation flow of the data caching method provided in the embodiment of the present application is shown in FIG. Figure 1 As shown, the method may include the following steps 101 to 103:
[0026] Step 101, a first server determines the number of requests for the same type of data received by N servers in a server cluster; wherein N is greater than 1 and less than or equal to the total number of servers in the server cluster;
[0027] It can be understood that the same type of data refers to data corresponding to data access requests of the same category. For example, when a user queries the prices of multiple items, if the multiple items belong to the same category, the prices of the multiple items and the prices of all items in this category are the same type of data.
[0028] In a distributed environment, the same type of data access requests sent by different clients may be assigned to different servers. Therefore, the data access requests received by a single server cannot reflect the number of requests for the same type of data in the entire distributed environment. Therefore, in order to accurately determine the number of requests for the same type of data in a distributed environment, it is necessary to determine the total number of requests for the same type of data received by multiple servers (e.g., all servers) in a server cluster.
[0029] In some embodiments, the number of requests for the same type of data received by N servers in a server cluster in a distributed environment can be determined by counting the number of requests for the same type of data on the same server. For example, after receiving a data access request sent by a client, the application layer of the server cluster allocates the request to a server in the cluster, and the server responds to the client according to the request, returns the request data corresponding to the request to the client, and sends the key value of the request data to the allocation server in the server cluster, which sends the key value to the corresponding server, for example, to the first server, and the first server receives the key value of the request data; wherein the receiving server of the key value of the same type of data is the same server; then, the first server determines the number of requests according to the received key value.
[0030] Step 102, the first server determines whether the same type of data is the hot data according to the number of requests;
[0031] In some embodiments, when the number of requests within a preset time period is greater than or equal to a first threshold, and / or when the increment of the number of requests per unit time is greater than or equal to a second threshold, the first server determines that the same type of data is the hot data. By determining that the same type of data corresponding to instantaneous massive requests is hot data, the impact of instantaneous massive requests on the data storage layer of the server cluster can be dealt with.
[0032] Step 103: When the data of the same type is hot data, the first server notifies each server in the server cluster to cache the hot data locally.
[0033] In some embodiments, after the first server notifies each server in the server cluster to cache the accurately determined hotspot data locally, when the user sends a data access request corresponding to the hotspot data to the server cluster through the terminal client, no matter which server the data access request is assigned to, the data corresponding to the data access request can be directly read from the local cache of the server, without going to the data storage layer of the server cluster to obtain the data corresponding to the request, thereby reducing the impact of hotspot data requests on the data storage layer and related dependent services, ensuring the stability of the system, and avoiding the situation where the hotspot data that should be stored in the server local cache is not stored in the server local cache in the case of incorrect hotspot data judgment. Therefore, when the server cluster receives massive data requests, it directly goes to the data storage layer in the server cluster to centrally obtain data, resulting in excessive system pressure and system avalanche.
[0034] In an embodiment of the present application, whether the same type of data is hot data is determined by determining the number of requests for the same type of data received by multiple servers in a server cluster, rather than determining whether the same type of data is hot data simply by the number of requests for the same type of data received by one server. In this way, the judgment result will not deviate too much, reducing the probability of judging hot data as non-hot data, thereby improving the accuracy of hot data judgment. After determining the hot data, each server in the server cluster is notified to cache the hot data locally. In this way, when the server cluster receives an instantaneous massive request, it can directly obtain the data from the local cache of the server without having to centrally obtain the data from the data storage layer of the server cluster. This can avoid the impact of instantaneous massive requests on the data storage layer of the server cluster and related dependent services, thereby ensuring the stability of the system.
[0035] Figure 2 Another implementation flow diagram of the data caching method provided in the embodiment of the present application is as follows: Figure 2 As shown, the method may include the following steps 201 to 205:
[0036] Step 201, a first server receives a key value of requested data; wherein the receiving server of the key value of the same type of data is the same server;
[0037] In some embodiments, the hash values of key values of the same type are the same. After receiving the key value sent by the server that processes the data access request, the allocation server in the server cluster determines the first server to which the key value is assigned based on the characteristic value of the key value and the total number of servers used to determine the number of requests. After receiving the key value, the first server counts the number of key values to determine the number of requests corresponding to the key value.
[0038] In some embodiments, the allocation server can perform a modulo operation on the characteristic value of the key value and the total number of servers to obtain a remainder; determine the server corresponding to the server identifier that matches the remainder, thereby ensuring that the number of data access requests for the same type of data are counted by the same server, thereby improving the accuracy of hot spot data judgment.
[0039] In some embodiments, the total number of servers is used as a divisor, the characteristic value of the key value is used as a dividend, and the remainder obtained after taking the remainder is the server identifier of the server corresponding to the key value; wherein the server identifier can be preset, for example, the server identifier of the first server is "1", the server identifier of the second server is "2", ..., and the server identifier of the Nth server is "N". For example, when the allocation server performs a remainder operation on the characteristic value of the key value and the total number of servers, and the remainder obtained is 1, it is determined that the key value is allocated to the server with the server identifier "1".
[0040] In some embodiments, the first server receives the key value by starting a receiving thread and placing the received key value into a request queue to increase the throughput of the key value. In some embodiments, the number of started receiving threads is consistent with the number of cores of a central processing unit (CPU) of the first server.
[0041] Step 202: the first server determines a target computing thread according to the key value and the number of enabled computing threads; wherein the target computing thread is used to count the number of key values of the same type;
[0042] It can be understood that the computing thread that counts the number of similar key values is the same computing thread of the same server; in this way, it can be ensured that one computing thread only counts the number of one similar key value, rather than multiple computing threads counting the number of one similar key value; in this way, the accuracy of the final determined number of similar key values is guaranteed, thereby ensuring the accuracy of the final determined number of requests, thereby improving the accuracy of hot spot data judgment.
[0043] In some embodiments, the first server determines the number of computing threads to be enabled based on the number of cores of a central processing unit (CPU). In some embodiments, the number of computing threads enabled by the first server is twice the number of cores to ensure the statistical speed of the number of key values.
[0044] In some embodiments, after receiving the key value through the request queue in the first server, steps 302 to 304 of the following embodiment may be executed to implement step 202, which will not be described here to avoid repetition.
[0045] Step 203, the first server determines the number of key values of the same type through the target computing thread, thereby obtaining the request number;
[0046] In some embodiments, the first server places the same type of key values into the corresponding computing queue through the target computing thread to determine the number of the same type of key values. In some embodiments, the target computing thread inserts the received key value into the head position of the corresponding computing queue according to the key value according to the time of receipt.
[0047] Step 204, when the number of requests within a preset time period is greater than or equal to a first threshold, and / or when the increment of the number of requests per unit time is greater than or equal to a second threshold, determining that the same type of data is the hot data;
[0048] In some embodiments, the first server intercepts the number of key values in the calculation queue within a preset time period through the target calculation thread. If the number of key values in the calculation queue is greater than or equal to the first threshold, it is determined that the number of requests within the preset time period is greater than or equal to the first threshold, and the same type of data is determined to be hot data.
[0049] In other embodiments, the first server determines whether the same type of data is hot data based on the growth rate of the number of key values in the calculation queue; that is, when the increment of the number of key values per unit time is greater than or equal to the second threshold, that is, when the increment of the number of requests per unit time is greater than or equal to the second threshold, the same type of data is determined to be the hot data.
[0050] In other embodiments, when the number of requests within a preset time period is greater than or equal to a first threshold and the increment of the number of requests per unit time is greater than or equal to a second threshold, the same type of data is determined to be the hot data.
[0051] Step 205: The first server notifies each server in the server cluster to cache the hotspot data locally.
[0052] Figure 3 A schematic diagram of the implementation flow of another data caching method provided in an embodiment of the present application is shown in FIG. Figure 3 As shown, the method may include the following steps 301 to 307:
[0053] Step 301, a first server receives a key value of requested data; wherein the receiving server of the key value of the same type of data is the same server;
[0054] Step 302, the first server determines a characteristic value of the key value;
[0055] The characteristic value of the key value is a unique value used to characterize the same type of key value. In some embodiments, the characteristic value of the key value is a hash value of the key value. The characteristic value can be a hash value calculated by the request queue in the first server using a preset hash function on the key value.
[0056] Step 303: the first server performs a modulo operation on the characteristic value of the key value and the number of the computing threads to obtain a remainder;
[0057] Step 304: the first server determines the computing thread corresponding to the thread identifier matching the remainder among the opened computing threads as the target computing thread;
[0058] In some embodiments, the request queue in the first server performs a remainder operation with the characteristic value of the key value as the dividend and the number of enabled computing threads as the divisor, and the remainder obtained is the thread identifier of the target computing thread; wherein the thread identifier can be preset, for example, the thread identifier of the first computing thread is "1", the thread identifier of the second computing thread is "2", ..., and the thread identifier of the Nth computing thread is N. For example, when the request queue in the first server performs a remainder operation on the characteristic value of the key value and the total number of servers, and the remainder obtained is 1, the key value is assigned to the computing thread with the thread identifier "1".
[0059] By performing a modulo operation on the characteristic value of the key value and the number of enabled computing threads, it can be ensured that the key values of the same type of data correspond to the same computing thread, thereby avoiding errors in the calculation of the number of requests caused by multiple computing threads simultaneously counting the key values of the same type of data, thereby ensuring the accuracy of the final determined number of requests, and thereby ensuring the accuracy of the final determined hotspot data.
[0060] Step 305, the first server determines the number of the key values of the same type through the target calculation thread, thereby obtaining the request number;
[0061] Step 306, when the number of requests within a preset time period is greater than or equal to a first threshold, and / or when the increment of the number of requests per unit time is greater than or equal to a second threshold, determining the same type of data as the hot data;
[0062] Step 307: The first server notifies each server in the server cluster to cache the hotspot data locally.
[0063] In order to avoid the impact of massive requests on the data storage layer and related dependent services, the hot data will be saved in the server's memory for a period of time as a local cache. After receiving a hot data request, if the data already exists in the server's local cache, the content in the local cache will be returned directly, thereby reducing the impact of hot data requests on the data storage layer and related dependent services and ensuring the stability of the system.
[0064] In the related art, local hot data cache is set by the server in the cluster, and the server determines whether to cache hot data according to the received request. The content determined as hot data is saved in the server memory, and after receiving the hot data request, the hot data in the server is directly obtained.
[0065] However, the related technology has the following problems:
[0066] 1. Problems in determining hotspot data in a distributed environment:
[0067] Whether the data is hot data is determined by the server that receives the request. In a distributed environment, since the requests are distributed to different servers, the request volume of a single server cannot reflect the request volume in the entire distributed environment, and the judgment of hot data will have a large deviation.
[0068] 2. The problem of cache hit rate in distributed environment:
[0069] In a distributed environment, requests will be assigned to different servers for execution. Hot data is cached locally on server A. The second request may be assigned to server B. At this time, server B may not have a local cache of the corresponding hot data, resulting in a low local cache hit rate. In a distributed environment, the relationship between the number of servers and the hit rate is as follows: Figure 4 As shown in the figure, it can be seen that the more servers there are in a distributed environment, the lower the hit rate.
[0070] Based on this, an exemplary application of an embodiment of the present application in a practical application scenario will be described below.
[0071] The embodiment of the present application is intended to solve the problem of determining hot data in a distributed environment according to the data request volume of all servers in the distributed environment, calculating the hot data in the entire environment, and after determining the hot data, asynchronously notifying all servers in the distributed environment to cache the hot data locally. The hot data is determined more accurately, and the hit rate of the local cache is no longer affected by the number of servers in the distributed environment.
[0072] The embodiment of the present application collects the request volume of all servers in the distributed environment to perform hotspot data analysis, determines the hotspot data in the environment, and asynchronously notifies all servers in the distributed environment to locally cache the hotspot data, thereby more accurately determining the hotspot data. The hit rate of the local cache is no longer affected by the number of servers in the distributed environment.
[0073] Figure 5 A schematic diagram of the implementation flow of another data caching method provided in an embodiment of the present application is shown in FIG. Figure 5 As shown, the method may include the following steps 501 to 505:
[0074] Step 501, after receiving the request, the application will assign the request to one of the servers in the application cluster for processing;
[0075] Step 502, after processing the request, the server receiving the request asynchronously synchronizes the key value of the request data to the server cluster;
[0076] Step 503, the server cluster distributes the key value of the request data to a corresponding server; in some embodiments, the distribution server in the server cluster distributes the key value of the request data to the corresponding server according to the hash value of the key value of the request data;
[0077] Step 504, the server determines whether the same type of data corresponding to the key value is hot data; if yes, execute step 505;
[0078] Step 505: The server notifies all servers in the server cluster to synchronize the hotspot data.
[0079] Figure 6 A flow chart of a method for determining hotspot data provided in an embodiment of the present application is shown in FIG. Figure 6 As shown, the method may include the following steps 601 to 606:
[0080] Step 601, after receiving the key value of the request data, the server cluster will determine the server (i.e., the first server) to which the key value is assigned based on the hash value (hash) of the key value and the number of servers in the server cluster. When the computing power of the server cluster is insufficient, it can be expanded horizontally by increasing the number of servers in the server cluster. In order to increase the corresponding processing capacity, there is no single point problem, and there is no performance bottleneck in horizontal expansion.
[0081] Step 602, the server starts a receiving thread and a computing thread according to the number of CPU cores. In some embodiments, the number of receiving threads is consistent with the number of CPU cores, and the number of computing threads is twice the number of CPU cores.
[0082] Step 603: The server receiving thread mainly processes the requests received by the server, puts the requests into the request queue, and increases the throughput of the server receiving requests.
[0083] In step 604, the request queue in the server will determine the server computing thread to which the request is assigned based on the hash value of the key value received and the number of computing threads opened by the server, to ensure that the same request is assigned to the computing thread of the same server for calculation, to avoid multiple threads accumulating the same key value at the same time and causing quantity calculation errors, and to reduce the complexity of calculations in a concurrent environment.
[0084] Step 605: After receiving the assigned request, the server computing thread starts computing the hotspot data. Figure 7 Schematic diagram of the main data structure of the computing queue of the embodiment of the present application, such as Figure 7 As shown, the computing thread inserts the key value into the head position of the unique queue corresponding to the key value according to the received time.
[0085] Step 606, the server computing thread calculates according to the amount of data requests within the time period, monitors the computing queue, uses the current time to the specified time period, intercepts the computing queue, and identifies hot data if the number in the computing queue is greater than the specified number (i.e., the first threshold), and / or, the server computing thread calculates the hot data according to the queue growth rate, monitors the computing queue, and identifies hot data if the length of the monitored computing queue surges to a certain threshold (i.e., the second threshold) per unit time, mainly to deal with the impact of instantaneous massive requests on the application.
[0086] After the server determines that the data is hot data, it will synchronize the hot data to each server in the application cluster for caching. When the application receives a hot data request again, no matter which server in the application cluster the request is assigned to, it will hit the server's local cache and directly use the data in the server's memory.
[0087] The embodiment of the present application collects the request volume of all servers in a distributed environment through a server cluster to perform hot data analysis, thereby more accurately determining hot data; achieving the purpose of improving server throughput through the coordinated processing of receiving threads, request queues, and computing threads; determining the server computing thread to which the request is assigned by dividing the hash value of the request's key value by the number of server computing threads, thereby ensuring that the same request is assigned to the computing thread of the same server for calculation, thereby avoiding errors in quantity calculation caused by multiple threads accumulating the same key value at the same time, and reducing the complexity of calculation in a concurrent environment; according to the server computing queue, using the current time to the specified time period, intercepting the computing queue calculation method, and identifying the hot data method; according to the server computing queue, monitoring the computing queue length speed per unit time, and identifying the hot data method; the server notifies the application cluster to set a local cache, so that the hit rate of the hot data cache in the cluster is no longer affected by the number of servers in the cluster.
[0088] Based on the foregoing embodiments, an embodiment of the present application provides a data cache device, which includes the modules included and the units included in the modules, and can be implemented by a processor; of course, it can also be implemented by a specific logic circuit; in the implementation process, the processor can be a central processing unit (CPU), a microprocessor (MPU), a digital signal processor (DSP) or a field programmable gate array (FPGA), etc.
[0089] Figure 8 Schematic diagram of the structure of the data cache device of the embodiment of the present application. Figure 8 As shown, the device 800 includes a determination module 801 and a notification module 802, wherein:
[0090] The determination module 801 is used to determine the number of requests for the same type of data received by N servers in the server cluster; wherein N is greater than 1 and less than or equal to the total number of servers in the server cluster;
[0091] The determination module 801 is further used to determine whether the same type of data is hot data according to the number of requests;
[0092] The notification module 802 is used to notify each server in the server cluster to cache the hot data locally when the data of the same type is hot data.
[0093] In some embodiments, the determination module 801 is used to receive a key value of request data; wherein the receiving server of the key value of the same type of request data is the same server; and the request quantity is determined according to the received key value.
[0094] In some embodiments, the determination module 801 is used to determine the target computing thread based on the key value and the number of opened computing threads; wherein the target computing thread is used to count the number of key values of the same type; and the number of key values of the same type is determined through the target computing thread, thereby obtaining the request number.
[0095] In some embodiments, the determination module 801 is used to determine the characteristic value of the key value; perform a modulo operation on the characteristic value of the key value and the number of the computing threads to obtain a remainder; and determine the computing thread corresponding to the thread identifier matching the remainder among the opened computing threads as the target computing thread.
[0096] In some embodiments, the determination module 801 is used to calculate the key value using a preset hash function, and use the obtained hash value as the characteristic value of the key value.
[0097] In some embodiments, determination module 801 is used to determine that the same type of data is the hot data when the number of requests within a preset time period is greater than or equal to a first threshold and / or when the increment of the number of requests per unit time is greater than or equal to a second threshold.
[0098] The description of the above device embodiment is similar to the description of the above method embodiment, and has similar beneficial effects as the method embodiment. For technical details not disclosed in the device embodiment of the present application, please refer to the description of the method embodiment of the present application for understanding.
[0099] It should be noted that in the embodiments of this application Figure 8 The division of modules in the data cache device shown is schematic and is only a logical function division. There may be other division methods in actual implementation. In addition, each functional unit in each embodiment of the present application may be integrated into a processing unit, or may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of a software functional unit. It may also be implemented in the form of a combination of software and hardware.
[0100] It should be noted that in the embodiment of the present application, if the above method is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the embodiment of the present application can be essentially or partly embodied in the form of a software product that contributes to the relevant technology. The computer software product is stored in a storage medium, including several instructions to enable an electronic device to execute all or part of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a U disk, a mobile hard disk, a read-only memory (ROM), a magnetic disk or an optical disk. In this way, the embodiment of the present application is not limited to any specific combination of hardware and software.
[0101] An embodiment of the present application provides an electronic device, Fig. 9 Schematic diagram of the hardware entity of the electronic device of the embodiment of the present application, such as Fig. 9 As shown, the electronic device 900 includes a memory 901 and a processor 902, wherein the memory 901 stores a computer program that can be run on the processor 902, and the processor 902 implements the steps in the method provided in the above embodiment when executing the program.
[0102] It should be noted that the memory 901 is configured to store instructions and applications executable by the processor 902, and can also cache data to be processed or processed by the processor 902 and various modules in the electronic device 900 (for example, image data, audio data, voice communication data, and video communication data), which can be implemented through flash memory (FLASH) or random access memory (Random Access Memory, RAM).
[0103] An embodiment of the present application provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps in the method provided in the above embodiment are implemented.
[0104] An embodiment of the present application provides a computer program product including instructions, which, when executed on a computer, enables the computer to execute the steps of the method provided in the above method embodiment.
[0105] It should be noted here that the description of the above storage medium and device embodiments is similar to the description of the above method embodiments, and has similar beneficial effects as the method embodiments. For technical details not disclosed in the storage medium, storage medium and device embodiments of this application, please refer to the description of the method embodiments of this application for understanding.
[0106] It should be understood that "one embodiment" or "an embodiment" or "some embodiments" mentioned throughout the specification means that specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present application. Therefore, "in one embodiment" or "in one embodiment" or "in some embodiments" appearing throughout the specification may not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. It should be understood that in various embodiments of the present application, the size of the sequence number of the above-mentioned processes does not mean the order of execution, and the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present application. The above-mentioned sequence numbers of the embodiments of the present application are only for description and do not represent the advantages and disadvantages of the embodiments. The above description of each embodiment tends to emphasize the differences between the various embodiments, and the same or similar aspects can be referenced to each other. For the sake of brevity, this article will not repeat them.
[0107] The term "and / or" in this article is only a description of the association relationship of associated objects, indicating that there may be three relationships. For example, object A and / or object B can represent three situations: object A exists alone, object A and object B exist at the same time, and object B exists alone.
[0108] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0109] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, such as: multiple modules or components can be combined, or can be integrated into another system, or some features can be ignored, or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of devices or modules can be electrical, mechanical or other forms.
[0110] The modules described above as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules; they may be located in one place or distributed on multiple network units; some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment.
[0111] In addition, all functional modules in the embodiments of the present application may be integrated into one processing unit, or each module may be a separate unit, or two or more modules may be integrated into one unit; the above-mentioned integrated modules may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0112] A person skilled in the art can understand that all or part of the steps of implementing the above method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above method embodiment; and the aforementioned storage medium includes: mobile storage devices, read-only memories (ROM), magnetic disks or optical disks, etc., various media that can store program codes.
[0113] Alternatively, if the above-mentioned integrated unit of the present application is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application can essentially or in other words, the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for enabling an electronic device to execute all or part of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROMs, magnetic disks, or optical disks.
[0114] The methods disclosed in several method embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments.
[0115] The features disclosed in several product embodiments provided in this application can be arbitrarily combined without conflict to obtain new product embodiments.
[0116] The features disclosed in several method or device embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments or device embodiments.
[0117] The above is only an implementation method of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A data caching method, It is characterized in that The method comprises: Determine the number of requests for the same type of data received by N servers in the server cluster; wherein N is greater than 1 and less than or equal to the total number of servers in the server cluster; Determining whether the same type of data is hot data according to the number of requests; In the case where the data of the same type is the hot data, notifying each server in the server cluster to cache the hot data locally; Determining the number of requests for the same type of data received by N servers in the server cluster includes: Receive the key value of the requested data; wherein the receiving server of the key values of the same type of data is the same server; the server identifier corresponding to the receiving server of the key values of the same type of data matches the remainder obtained by performing a modulo operation on the characteristic value of the key value and the total amount of the server; The request quantity is determined according to the received key value.
2. The method according to claim 1, It is characterized in that Determining the request quantity according to the received key value includes: Determine a target computing thread according to the key value and the number of enabled computing threads; wherein the target computing thread is used to count the number of key values of the same type; The number of key values of the same type is determined through the target computing thread, thereby obtaining the request number.
3. The method according to claim 2, It is characterized in that The step of determining the target computing thread according to the key value and the number of enabled computing threads includes: determining a characteristic value of the key value; Performing a modulo operation on the characteristic value of the key value and the number of the computing threads to obtain a remainder; The computing thread corresponding to the thread identifier matching the remainder among the enabled computing threads is determined as the target computing thread.
4. The method according to claim 3, It is characterized in that The determining of the characteristic value of the key value comprises: The key value is calculated using a preset hash function, and the obtained hash value is used as the characteristic value of the key value.
5. The method according to any one of claims 1 to 4, It is characterized in that The determining, according to the number of requests, whether the data of the same type is hot data includes: When the number of requests within a preset time period is greater than or equal to a first threshold, and / or when the increment of the number of requests per unit time is greater than or equal to a second threshold, the same type of data is determined to be the hot data.
6. A data caching device, It is characterized in that include: A determination module, used to determine the number of requests for the same type of data received by N servers in the server cluster; wherein N is greater than 1 and less than or equal to the total number of servers in the server cluster; The determination module is further used to determine whether the same type of data is hot data according to the number of requests; A notification module, used for notifying each server in the server cluster to cache the hot data locally when the same type of data is the hot data; The determination module is specifically used to receive the key value of the requested data, wherein the receiving server for the key value of the same type of data is the same server; the server identifier corresponding to the receiving server for the key value of the same type of data matches the remainder obtained by taking the remainder of the modulo operation between the characteristic value of the key value and the total number of servers; and the request quantity is determined based on the received key value.
7. An electronic device comprising a memory and a processor, wherein the memory stores a computer program executable on the processor, It is characterized in that When the processor executes the program, the method according to any one of claims 1 to 5 is implemented.
8. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.
