Data sending method and device and application server
By adding a queue for identifying data to be updated in the cache server, using the first thread to respond to data query requests and asynchronously updating cached data through the second thread, the system performance problem caused by cached data expiration is solved, and efficient data update and query are achieved.
Patent Information
- Application Number
- CN202510977027.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-15
- Publication Date
- 2025-09-16
AI Technical Summary
In the prior art, cached data needs to be updated using a synchronization lock mechanism after it becomes invalid, which causes data refresh to take too long and affects system performance.
When cache data that meets the preset refresh condition exists in the cache server, the data identifier is added to the queue of data identifiers to be updated, and while responding to the data query request through the first thread, the cache data is asynchronously updated using the second thread.
Improves system performance, avoids increased data request time and lag caused by cache failure, and ensures that the system updates the cache while responding to data queries.
Smart Images

Figure CN120653684A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and more particularly to a data transmission method, a data transmission device, and an application server. Background Art
[0002] With the rapid development of information technology, information systems are facing increasing pressure from concurrent requests. Caching technology can generally be used to cache data from data providers to reduce the request pressure they face. However, cached data is time-sensitive. Once cached data expires, a synchronization lock mechanism is required to ensure that a single thread executes the task of updating the cached data. The synchronization lock resource cannot be released until all cached data has been updated. This can easily lead to excessive data refresh times and reduced system performance.
[0003] It is urgent to solve how to provide a data sending method that can improve data update efficiency without affecting system performance by using cache. Summary of the Invention
[0004] In view of this, embodiments of the present application provide a data sending method, device, and application server to solve the problem of poor system performance in existing data sending methods using application caching.
[0005] According to a first aspect of an embodiment of the present application, a data sending method is provided, which is applied to a distributed system, wherein the distributed system includes a cache server and multiple application servers, and the method includes: a first server among the multiple application servers receives a data query request including a first data identifier through a first thread; if there is cached data corresponding to the first data identifier and meeting a preset refresh condition in the cache server, the first data identifier is added to a queue of data identifiers to be updated; the preset refresh condition includes that the current moment has not reached the expiration moment of the cached data and has reached the refresh moment of the cached data; the queue of data identifiers to be updated is used for the first server to obtain source data corresponding to the first data identifier from a data provider according to the first data identifier through a second thread, and update the source data to the cache server; and send the cached data to the data query party.
[0006] According to a second aspect of an embodiment of the present application, a data sending device is provided, which is applied to an application server, and a distributed system includes a cache server and a plurality of the application servers. The data sending device includes: a request receiving module, which is used to receive a data query request containing a first data identifier through a first thread; a data identifier queue updating module, which is used to add the first data identifier to the data identifier queue to be updated if there is cache data corresponding to the first data identifier and meeting a preset refresh condition in the cache server; the preset refresh condition includes that the current moment has not reached the expiration moment of the cache data and has reached the refresh moment of the cache data; the data identifier queue to be updated is used for the application server to obtain the source data corresponding to the first data identifier from the data provider through the second thread according to the first data identifier, and update the source data to the cache server; the data sending module is used to send the cache data to the data query party.
[0007] According to a third aspect of an embodiment of the present application, an application server is provided, a distributed system including a cache server and a plurality of the application servers, the application server including: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor so as to enable the at least one processor to: receive a data query request containing a first data identifier through a first thread; if there is cached data corresponding to the first data identifier and meeting a preset refresh condition in the cache server, the first data identifier is added to a queue of data identifiers to be updated; the preset refresh condition includes that the current moment has not reached the expiration moment of the cached data and has reached the refresh moment of the cached data; the queue of data identifiers to be updated is used for the application server to obtain the source data corresponding to the first data identifier from the data provider through a second thread according to the first data identifier, and update the source data to the cache server; and send the cached data to the data query party.
[0008] One embodiment of the present specification can at least achieve the following beneficial effects: a first server among multiple application servers included in a distributed system can receive a data query request containing a first data identifier through a first thread. If cache data corresponding to the first data identifier and meeting a preset refresh condition exists in the cache server, the first data identifier can be added to a queue of data identifiers to be updated, so that when the expiration time of the cache data corresponding to the first data identifier has not yet been reached and the refresh time of the cache data has been reached, the first server obtains the source data corresponding to the first data identifier from the data provider through a second thread according to the first data identifier, and updates the source data to the cache server while also sending the cache data to the data query party. Thus, the application server can continue to respond to data query requests and return cached data through the first thread, while also updating cached data through the second thread. This improves system performance while avoiding problems such as a significant increase in data request time due to cache failure and causing lag to customers. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] In order to more clearly illustrate the embodiments of this specification or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments recorded in this application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0010] Figure 1 This is a schematic diagram of the overall architecture of a data sending method provided in an embodiment of this specification; Figure 2 This is a flow chart of a data sending method provided in an embodiment of this specification; Figure 3 This is a schematic diagram of an embodiment of this specification providing a method of updating cached data by obtaining a data identifier from a to-be-updated data identifier through a second thread; Figure 4 This is a schematic diagram of different application servers updating the same cache data provided by an embodiment of this specification; Figure 5 This is a flow chart of a data sending method provided in an embodiment of this specification; Figure 6 This specification provides the corresponding embodiment Figure 2 A structural diagram of a data sending device; Figure 7 This specification provides the corresponding embodiment Figure 2 A structural diagram of a data sending device. DETAILED DESCRIPTION
[0011] The following description sets forth many specific details to facilitate a thorough understanding of the present application. However, the present application can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the scope of the present application. Therefore, the present application is not limited to the specific implementations disclosed below.
[0012] The terms used in one or more embodiments of the present application are for the purpose of describing specific embodiments only and are not intended to limit one or more embodiments of the present application. The singular forms "a", "the" and "the" used in one or more embodiments of the present application and the appended claims are also intended to include plural forms, unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used in one or more embodiments of the present application refers to and includes any or all possible combinations of one or more associated listed items.
[0013] It should be understood that although the terms first, second, etc. may be used to describe various information in one or more embodiments of the present application, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from each other. For example, without departing from the scope of one or more embodiments of the present application, the first may also be referred to as the second, and similarly, the second may also be referred to as the first. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0014] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0015] First, the terms involved in one or more embodiments of the present application are explained.
[0016] Cache: A storage mechanism that temporarily stores data to improve data access speed. Caching reduces the number of direct queries to the original data source, further improving application performance and responsiveness.
[0017] Local caching: This refers to storing data locally on an application or server, typically used to accelerate data access and improve response times. Local caching typically uses memory as the storage medium, leveraging the high read and write speeds of memory to increase data access speed.
[0018] Distributed caching: This involves storing data across multiple distributed nodes, working together to provide high-performance data access services. Distributed caching is typically deployed in a cluster, using multiple servers to share the burden of data storage and access.
[0019] Asynchronous operation is a method of processing operations or events in which a task or function call does not complete or return results immediately, allowing the program to continue executing subsequent code while waiting for the task or call to complete at a future point in time. Asynchronous operations do not block the program's execution flow; control can be returned immediately, allowing other tasks or code to continue executing without waiting for the current task to complete.
[0020] Back-to-source: When the data requested by the user does not exist on the node or has expired, the system node will request the latest data from the data provider of the source data, update the obtained data to the cache, and then pass the data to the user.
[0021] Cache timeout: This means that the cached data is set with an expiration date. If the cached data exceeds the expiration date, it can be determined that the cache has timed out. The data in the cache can be determined as unreliable data and marked invalid.
[0022] Synchronization locks are a mechanism used to control access to shared resources by multiple threads. In a multithreaded programming environment, when multiple threads access shared data simultaneously, data inconsistencies or other concurrency issues may occur. Synchronization locks can be used to ensure that only one thread can access a locked code block or shared resource at a time.
[0023] Cache breakdown occurs when a data cache expires and a large number of concurrent requests simultaneously access the backend storage, causing a dramatic increase in backend storage load. For example, in an e-commerce system, inventory information for a popular product is cached. If the cache for this product expires or is cleared, and a large number of users simultaneously access this inventory information within a short period of time, all requests will directly query the database of the inventory provider, causing database performance degradation or even crashing.
[0024] In related technologies, in order to avoid large amounts of data directly accessing the data provider, causing the data provider's database performance to degrade or crash, the source data provided by the data provider is usually cached so that when the user requests the data, the data can be retrieved from the cache and returned to the user. However, the data in the cache is time-sensitive. If the data in the cache becomes invalid, it needs to be blocked using a synchronization lock. The cache will not release the synchronization lock until it retrieves the data from the data provider and updates the data in the cache. This process is time-consuming and prone to data breakdown and lock contention, affecting the overall performance of the system. For example, the Guava cache provides a stand-alone cache refresh mechanism. When querying data, it compares the last update time of the data. If it exceeds the specified time, it will load or refresh it. When the cache needs to be refreshed, Guava uses a synchronization lock to ensure that only one thread performs the refresh action, but the synchronization lock needs to wait until the data refresh is complete before it can be released. If the data refresh takes a long time, lock contention will frequently occur, reducing system performance.
[0025] To address the deficiencies in the related art, in an embodiment of the present specification, a first server among multiple application servers in a distributed system can obtain a data query request carrying a first data identifier through a first thread. After determining that cached data corresponding to the first data identifier and meeting a preset refresh condition exists in the cache server, the first data identifier is added to a queue of data identifiers to be updated, so that the first server obtains source data from a data provider through a second thread and updates the data in the cache server. The cached data in the cache server is then sent to the data query party through the first thread. Thus, if the cached data is valid, the first thread can respond to the data query party's data query request and return data while the second thread can be used to update the cached data in the cache server, thereby improving system performance.
[0026] The technical solutions provided by the embodiments of this specification are described in detail below with reference to the accompanying drawings.
[0027] Figure 1 A schematic diagram of the overall architecture of a data sending method provided in an embodiment of this specification.
[0028] like Figure 1As shown, the solution may include a user terminal 1, an application server 2, a cache server 3, and a data provider 4. A user can operate user terminal 1, and based on the user operation, user terminal 1 can send a data query request to application server 2. Application server 2 can receive data query requests from different user terminals via a first thread. Based on the data query request from user terminal 1, application server 2 can retrieve cached data corresponding to the first data identifier contained in the data query request from cache server 3 via the first thread, and send the retrieved unexpired cached data to user terminal 1, so that user terminal 1 can display the data query results to the user. If application server 2 determines that the data query request was received before the cached data in the cache server expired and the cached data refresh time has arrived, application server 2 can retrieve the latest source data from data provider 4 via a second thread based on the first data identifier contained in the data query request, and update the latest source data to the cache server. In actual applications, the cached data retrieved by the application server from the cache server can be either unupdated cached data or cached data updated via the second thread. The cached data returned to the user terminal can be designed based on user needs and is not specifically limited here.
[0029] In such Figure 1 In the application scenario shown, the application server 2 can be connected to one or more user terminals 1 via a local area network connection, a wide area network connection, an Internet connection, or other types of data networks. The cache server 3 can be connected to one or more application servers 2 via a local area network connection, a wide area network connection, an Internet connection, or other types of data networks. Figure 1 The application server may include but is not limited to any device, equipment, platform, equipment cluster, etc. with computing and processing capabilities. Figure 1 The user terminals in the present invention may include but are not limited to smart phones, tablet computers, laptops, PDAs, personal computers, smart home devices, car-mounted devices, etc.
[0030] In the present application, a data sending method is provided. The present application also relates to a data sending device and an application server, which are described in detail one by one in the following embodiments.
[0031] Figure 2 A flowchart of a data sending method provided in an embodiment of this specification.
[0032] From the program perspective, the execution body of the process can be a program installed on an application server or application terminal. It is understood that the method can be executed by any device, equipment, platform, or device cluster with computing and processing capabilities.
[0033] like Figure 2As shown, the process may include the following steps: Step 202: A first server among the multiple application servers receives a data query request including a first data identifier through a first thread.
[0034] In the embodiments of this specification, an application server may represent a backend server that provides terminal application services. A first server may represent a backend server for a terminal application. The backend servers corresponding to multiple terminal applications in a user terminal may be integrated into one application server. For example, the backend servers for terminal application 1 and terminal application 2 are both application server a. Alternatively, one terminal application may correspond to one application server. For example, the backend server for terminal application 3 is application server b, and the backend server for terminal application 4 is application server c. The application server may be developed based on a software development kit, such as an SDK, API, or IDE.
[0035] In the embodiments of this specification, the first data identifier is used to identify the data that the data querying party wants to query. The data query request may be a request generated by the data querying party based on the first data identifier. The data querying party may be a user terminal initiating the data query request, such as a data access terminal installed with a terminal application capable of querying cached data.
[0036] Step 204: If cache data corresponding to the first data identifier and meeting a preset refresh condition exists in the cache server, the first data identifier is added to a queue of data identifiers to be updated.
[0037] Among them, the preset refresh conditions may include that the current time has not reached the expiration time of the cached data and has reached the refresh time of the cached data; the queue of data identifiers to be updated is used for the first server to obtain the source data corresponding to the first data identifier from the data provider through the second thread according to the first data identifier, and update the source data to the cache server.
[0038] In the embodiments of this specification, the cache server is a server for caching data provided by a data provider. The cache server stores the correspondence between data and data identifiers. The cache server can match the first data identifier with the data identifiers in the stored correspondence, determine the same data identifiers, and determine the cached data corresponding to the first data identifier. The queue of data identifiers to be updated can represent the queue where the data identifiers to be updated corresponding to the first server are located. The queue of data identifiers to be updated can contain one or more data identifiers of cached data to be updated that need to be updated to the cache server. When the server cluster includes multiple application servers, each application server maintains its own corresponding queue of data identifiers to be updated.
[0039] In the embodiments of this specification, the current time can represent the time when the application server receives the data query request, or it can also be the time when the user terminal generates the data query request. The expiration time can represent the time when the data cached in the cache server becomes invalid. The refresh time can represent the time when the data cached in the cache server is refreshed. For example, if the valid duration of the data is 20s, the refresh duration is 10s, the current time is 15:32:26 on January 14, 2025, and the data cache time (i.e., the timestamp of the data) is 15:32:10 on January 14, 2025, then by calculating the current time - the data cache time = 16s, it can be determined that the expiration time has not been reached, but the refresh time has been reached, and the cached data can be updated asynchronously. In actual applications, the expiration time can also be calculated by the valid duration and the data cache time, and the refresh time can be calculated by the refresh duration and the data cache time. The current time can be compared with the expiration time and the refresh time respectively to determine whether the preset refresh conditions are met; or, other methods can be used to determine whether the current time has not reached the expiration time of the refresh data and has reached the refresh time of the cached data, which is not specifically limited here.
[0040] In the embodiments of this specification, the second thread may represent a worker thread within each application server responsible for maintaining cached data updates. It may continuously read data identifiers to be refreshed from a refresh queue and obtain the latest data from a data provider. The second thread may update the cache server with the source data, its new expiration time (or expiration duration), and the data cache time. The second thread may be distinct from the first thread, and both may asynchronously process data identifiers or data query requests. The data provider may be the source of cached data for the cache server.
[0041] Step 206: Send the cached data to the data query party.
[0042] In an embodiment of the present specification, the application server may send cached data corresponding to the first data identifier in the cache server to the data querying party before adding the first data identifier to the queue of data identifiers to be updated. Alternatively, the application server may send cached data corresponding to the first data identifier in the cache server to the data querying party after adding the first data identifier to the queue of data identifiers to be updated. The cached data sent to the data querying party may be unupdated cached data or updated cached data.
[0043] In the embodiments of this specification, the application server can send cached data to the data querying party via a first thread, thereby maintaining the asynchronous refresh process of a second thread acquiring the data source from the data provider and updating the data on the cache server. It should be understood that while the application server updates the cached data on the cache server via the second thread, it can still use the first thread to respond to data query requests from user terminals and return the retrieved cached data.
[0044] It should be understood that in the methods described in one or more embodiments of this specification, the order of some steps can be adjusted according to actual needs, or some steps can be omitted.
[0045] Figure 2 In the method, the first server among the multiple application servers included in the distributed system can receive a data query request containing a first data identifier through a first thread. If there is cache data corresponding to the first data identifier and meeting the preset refresh conditions in the cache server, the first data identifier can be added to the queue of data identifiers to be updated, so that when the expiration time of the cache data corresponding to the first data identifier has not been reached and the refresh time of the cache data has been reached, the first server obtains the source data corresponding to the first data identifier from the data provider through the second thread according to the first data identifier, and updates the source data to the cache server while also sending the cache data to the data query party. In this way, while continuing to respond to data query requests and return cached data through the first thread, the cached data can also be updated through the second thread, which improves system performance while avoiding problems such as a significant increase in data request time due to cache failure and causing lag to customers.
[0046] based on Figure 2 The present specification also provides some improved implementation methods of the method, which are described below.
[0047] In one or more embodiments of the present specification, in order to prevent multiple data acquisition requests from penetrating to the data provider, the queue of data identifiers to be updated may not contain duplicate data identifiers. Optionally, before adding the first data identifier to the queue of data identifiers to be updated, the method may further include: determining whether a second data identifier identical to the first data identifier exists in the queue of data identifiers to be updated, and obtaining a first determination result; and adding the first data identifier to the queue of data identifiers to be updated may specifically include: if the first determination result is negative, adding the first data identifier to the queue of data identifiers to be updated.
[0048] In the embodiments of this specification, the various data identifiers contained in the queue of data identifiers to be updated may be different. If the first judgment result indicates that there is a second data identifier that is the same as the first data identifier in the queue of data identifiers to be updated, the operation can be terminated and the first data identifier will not be added to the queue of data identifiers to be updated. This ensures that when there are multiple data identifiers with the same data identifier within the same refreshable time period, the source data can be obtained from the data provider only once based on the data identifier, avoiding repeated acquisition of the data source from the data provider based on the same data identifier, reducing the pressure on the data provider while improving the update efficiency of the data in the cache server. In actual applications, the first data identifier added to the queue of data identifiers to be updated can be composed of the data type and the data content. For example, the first data identifier is {"productId":123456}, productId can represent the type of data, and 123456 can represent the content of the data. If the first judgment result is no, {"productId":123456} can be added to the queue of data identifiers to be updated.
[0049] In one or more embodiments of the present specification, a hash algorithm can be used to determine whether a second data identifier identical to a first data identifier exists in a queue of data identifiers to be updated. Optionally, determining whether a second data identifier identical to the first data identifier exists in a queue of data identifiers to be updated may include: calculating a first hash value of the first data identifier; determining whether a second data identifier exists in the queue of data identifiers to be updated, and obtaining a second determination result; the second hash value of the second data identifier is identical to the first hash value of the first data identifier; and if the first determination result is no, adding the first data identifier to the queue of data identifiers to be updated may include: if the second determination result is no, adding the first data identifier to the queue of data identifiers to be updated.
[0050] In an embodiment of the present specification, the first hash value may be obtained by calculating the first data identifier based on a hash algorithm, such as at least one of the hash algorithms such as MD5, SHA series, GOST, and SM3. The hash algorithm used to calculate the first hash value of the first data identifier is the same as the hash algorithm used to calculate the second hash value of the second data identifier in the queue of data identifiers to be updated. In an embodiment of the present specification, it is determined whether the second data identifier exists in the queue of identifiers to be updated. Specifically, it may be determined whether the second hash value of the second data identifier in the queue of data identifiers to be updated is the same as the first hash value of the first data identifier. If the second hash value of the second data identifier in the queue of data identifiers to be updated is different from the first hash value of the first data identifier, it may indicate that there is no second data identifier identical to the first data identifier in the queue of data identifiers to be updated, and the first data identifier may be added to the queue of data identifiers to be updated.
[0051] In an embodiment of the present specification, if there is a second data identifier in the data identifier queue to be updated, it may indicate that the second hash value of the second data identifier in the data identifier queue to be updated is the same as the first hash value of the first data identifier, and it is further determined that there is a second data identifier identical to the first data identifier in the data identifier queue to be updated. In order to avoid repeatedly obtaining the source data corresponding to the same data identifier from the data provider, the first data identifier may not be added to the data identifier queue to be updated.
[0052] In actual applications, if the first data identifier includes data content and data type, it is necessary to perform a hash calculation on the whole. Continuing with the above example, the hash value of the first data identifier can be calculated by hash{"productId":123456}. Alternatively, in order to improve the accuracy of the second judgment result, each data identifier can be converted into a data identifier in a unified format. Specifically, the first data identifier can be converted to obtain a converted first data identifier, and the converted first data identifier can be used to perform a hash calculation to obtain a corresponding hash value; the second judgment result is determined based on the hash value corresponding to the converted first data identifier. In the embodiment of this specification, the hash value can be calculated to determine whether there is a second data identifier that is the same as the first data identifier in the data identifier to be updated, thereby improving the accuracy of the judgment result while also avoiding missing updates to cached data corresponding to a certain data identifier.
[0053] In one or more embodiments of the present specification, in order to avoid data errors caused by performing data processing operations on the same queue of data identifiers to be updated in response to multiple data query requests, a synchronization lock technology can be used. Optionally, before adding the first data identifier to the queue of data identifiers to be updated, the method may further include: adding a synchronization lock to the queue of data identifiers to be updated; and after adding the first data identifier to the queue of data identifiers to be updated, the method may further include: releasing the synchronization lock.
[0054] In the embodiments of this specification, a synchronization lock can be used to block the queue of data identifiers to be updated, allowing only one thread to add a data identifier to the queue of data identifiers to be updated. After the thread adds the data identifier to the queue of data identifiers to be updated, the synchronization lock can be released. This allows only one thread to operate on the queue of data identifiers to be updated during the process of adding data identifiers. Furthermore, the synchronization lock can be used to ensure that only one thread can access the locked queue of data identifiers to be updated at a certain moment, so that when it is determined that the first data identifier is not in the queue of data identifiers to be updated, a synchronization lock can be added to the queue of data identifiers to be updated to avoid triggering concurrent modifications by other threads and repeatedly adding the first data identifier to the queue of data identifiers to be updated.
[0055] In the embodiment of this specification, in the process of updating the cached data in the cache server, an asynchronous queue mechanism can be used. The first thread that receives the data acquisition request adds the data identifier of the cached data that needs to be updated to the asynchronous queue of the data identifier to be updated queue, and uses the second thread of the application server to asynchronously obtain the data identifier from the data identifier queue to be updated, and then obtain the data from the data provider. Based on the solution of the embodiment of this specification, it is only necessary to add a synchronization lock to the queue during the process of updating the data identifier queue to be updated. The lock occupancy time is long. Compared with the solution in the related art that needs to obtain data from the data provider and perform the update during the locking period, the lock occupancy time is greatly shortened, and the lock contention caused by long waiting times is effectively alleviated, thereby improving the data query request processing efficiency and throughput.
[0056] In one or more embodiments of this specification, the acquired source data can be updated to a cache server to improve the efficiency and performance of request processing in the distributed system. Optionally, after adding the first data identifier to the queue of data identifiers to be updated, the method may further include: the first server obtaining the first data identifier from the queue of data identifiers to be updated via a second thread; obtaining the source data corresponding to the first data identifier from the data provider based on the first data identifier; and updating the source data to the cache server.
[0057] In an embodiment of the present specification, the queue of data identifiers to be updated may contain one or more data identifiers of cached data to be updated. The first server may obtain the first data identifier from the queue of data identifiers to be updated through a second thread in the thread pool. The thread pool may have a preset number of second threads, and the data identifiers of the cached data to be updated in the queue of data identifiers to be updated may be updated through the preset number of second threads. It is understandable that after a second thread updates the source data to the cache server, it may continue to obtain the data identifier of the cached data to be updated from the queue of data identifiers to be updated, and obtain the corresponding source data from the data provider based on the data identifier, and update the source data corresponding to the data identifier to the cache server. The old data (original cached data) corresponding to the data identifier in the cache server may be overwritten by the source data corresponding to the data identifier. Thus, the cached data can be updated by using the second thread without affecting the response and processing of data query requests by the first thread.
[0058] In order to more clearly explain the means by which the first server updates the cache data in the cache server through the second thread. Figure 3 This is a schematic diagram of an embodiment of this specification providing a method of updating cached data by obtaining a data identifier from a data identifier to be updated through a second thread.
[0059] like Figure 3 As shown, after the application server receives a query request 1 for performing a data query, it can check and queue based on the data identifier in the data query request 1, so that if the data identifier in the query request 1 does not exist in the data identifier queue to be updated, a synchronization lock is added to the data identifier queue to be updated, and the data identifier in the query request 1 is added to the data identifier queue to be updated, and then the synchronization lock is released. The data identifier queue to be updated can contain data identifiers such as identifier 1, identifier 2, identifier 3 and identifier 4 for data to be cached and updated. Query request N can wait for the lock to be released before checking and queueing. The application server can use the second thread in the thread pool to obtain the data identifier from the data identifier queue to be updated, perform data query from the data provider based on the data identifier, obtain the source data, and update the source data to the cache server. The data provider can include one or more, such as data provider 1 and data provider N.
[0060] It is understandable that Figure 3 This is merely an example to illustrate the process of the application server obtaining the data identifier from the to-be-updated data identifier through the second thread to update the cached data, and cannot be used as a specific limitation of the embodiments of this specification.
[0061] In one or more embodiments of this specification, a specified number of second threads can be used to process data identifiers in a queue of data identifiers to be updated, thereby improving data processing efficiency. By controlling the number of second threads, the number of concurrent data requests to downstream data providers can be controlled, thereby reducing the data processing pressure on downstream data providers and improving the stability of downstream systems.
[0062] Optionally, the second thread is a thread in the preset thread pool of the first server; the preset thread pool contains a specified number of threads; the threads in the preset thread pool are used to poll the data identifiers in the data identifier queue to be updated, and based on the polled target data identifier, obtain the data corresponding to the target data identifier from the data provider, and update the data corresponding to the target data identifier to the cache server.
[0063] In the embodiments of this specification, the preset thread pool can be a pre-created thread collection with multiple threads. The threads in the thread pool can be reused to perform multiple tasks. For example, after updating the cached data corresponding to data identifier 1, thread 1 in the thread pool can obtain data identifier 2 from the data identifier queue to be updated, obtain the source data corresponding to data identifier 2 from the data provider based on data identifier 2, and update the source data corresponding to data identifier 2 to the cache server. Thread 1 can also update the valid duration of the source data corresponding to data identifier 2 to the cache server, so that the cache server can determine the validity period of the data and avoid sending invalid data to the data requester.
[0064] In the embodiments of this specification, the specified number can be set based on the pressure-bearing capacity of the data provider and the length of the queue of data identifiers to be updated, for example, it can be set to values such as 10, 50, 30, etc. Alternatively, the specified number can also be determined based on expert experience. Polling can mean using threads in a thread pool to repeatedly obtain each data identifier from the queue of data identifiers to be updated. In the embodiments of this specification, a specified number of threads in a thread pool can be used to obtain data identifiers from the queue of data identifiers to be updated, and source data can be obtained from the data provider based on the data identifiers and updated, so that a server can effectively respond to high-concurrency requests, achieve peak shaving and valley filling, and improve the stability, reliability and processing efficiency of the entire system under high load conditions. When the cached data in the cache server needs to be refreshed, it will not cause a traffic peak to the downstream, thereby improving the stability of the downstream system.
[0065] In one or more embodiments of the present specification, optionally, adding the first data identifier to the queue of data identifiers to be updated may specifically include: in response to the data query request, determining whether cached data corresponding to the first data identifier exists in the cache server and the current moment has not reached the expiration moment of the cached data, and obtaining a third judgment result; if the third judgment result is yes, determining whether the current moment has reached the refresh moment of the cached data, and obtaining a fourth judgment result; the refresh moment is earlier than the expiration moment; if the fourth judgment result is yes, adding the first data identifier to the queue of data identifiers to be updated.
[0066] In the embodiments of the present specification, a data query request can be used to request an application server to query and return data corresponding to a data identifier included in the data query request. The cache server may include information such as the cache time and the effective duration corresponding to the cached data. The expiration time can be determined by calculating the sum of the cache time and the effective duration. In the judgment process of obtaining the third judgment result, specifically, the absolute value of the difference between the current time and the cache time can be calculated. If the absolute value of the difference is less than the effective duration, it can be determined that the current time has not reached the expiration time of the cached data; or, the expiration time can be calculated based on the cache time and the effective duration. If the current time is earlier than the expiration time, it can be determined that the current time has not reached the expiration time of the cached data.
[0067] In the embodiments of this specification, the refresh time can be determined based on the cache time and the refresh duration. The refresh duration is less than the effective duration. The fourth judgment result is yes, which can indicate that the current moment has reached the refresh time of the cached data. The process of obtaining the fourth judgment result can specifically calculate the sum of the cache time and the refresh duration to obtain the refresh time. If the current moment is greater than or equal to the refresh time, it can be determined that the current moment has reached the refresh time of the cached data. Alternatively, the refresh time is subtracted from the current moment to obtain the difference. If the difference is greater than or equal to zero, it can be determined that the current moment has reached the refresh time of the cached data. Therefore, when it is determined that cached data with the first data identifier exists in the cache server, and the cached data has not expired and has reached the refresh time, the first data identifier can be added to the queue of data identifiers to be updated, so that the second thread can obtain the first data identifier from the queue of data identifiers to be updated to update the cached data, thereby improving the efficiency of data updates and the efficiency of responding to data query requests.
[0068] In one or more embodiments of the present specification, optionally, after obtaining the third judgment result, the method may further include: if the third judgment result is negative, obtaining source data corresponding to the first data identifier from a data provider; and updating the source data to the cache server.
[0069] In the embodiments of this specification, the third judgment result of no may indicate that the cached data corresponding to the first data identifier does not exist in the cache server; or, it may indicate that the cached data corresponding to the first data identifier exists in the cache server, but the expiration time of the cached data has been reached at the current moment. Obtaining the source data corresponding to the first data identifier from the data provider may indicate that the data corresponding to the first data identifier is directly obtained from the data provider based on the first data identifier using the first thread and returned to the data query party. For example, the first server obtains the data query request containing the first data identifier at 10:11:40 on January 14, 2025, and the cache time of the cached data corresponding to the first data identifier is 10:11:01 on January 14, 2025, with an effective duration of 20s. It can be determined that the cached data corresponding to the first data identifier has expired. Furthermore, the source data corresponding to the first data identifier can be obtained from the data provider and returned to the data query party. At the same time, the obtained source data can be used to overwrite the expired cached data in the cache server, and the effective duration and cache time or expiration time can be set. In this way, the source data can be obtained in a timely manner when the cached data corresponding to the data identifier cannot be obtained from the cache server.
[0070] In one or more embodiments of the present specification, optionally, after obtaining the fourth judgment result, the method may further include: if the fourth judgment result is no, sending the cached data to a data querying party.
[0071] In the embodiments of this specification, the fourth judgment result of no may indicate that the current moment has not reached the refresh time of the cached data, which may indicate that there is no need to update the cached data corresponding to the first data identifier in the cache server, and there is no need to add the first data identifier to the queue of data identifiers to be updated. The first thread can be used to directly obtain the cached data corresponding to the first data identifier from the cache server and return it to the data query party. For example, the cache duration of the cached data is 20s, the refresh duration of the cached data is 10s, the cache time is 13:20:15 on January 14, 2025, the current time of obtaining the data query request is 13:20:20 on January 14, 2025, the current time - the cache time of the cached data = 5s, then it can be determined that the current moment has not reached the refresh time of the cached data, and there is no need to update, and only the current cached data needs to be returned. In the above manner, the refresh frequency of the cached data can be reduced, and the refresh cost is reduced.
[0072] In actual applications, a cache server may be connected to multiple different application servers. To respond to query requests from different application servers, the cached data and data identifiers in the cache server can have a unified format. Continuing with the example above where the first identifier data is {"productId":123456}, the application server can convert {"productId":123456} to "PROD_123456" before querying the data from the cache server. This allows the application server to query the corresponding cached data from the cache server based on "PROD_123456".
[0073] In one or more embodiments of the present specification, optionally, the determining whether cache data corresponding to the first data identifier exists in the cache server and the current moment has not reached the expiration time of the cache data may also include: determining whether the cache function has been enabled to obtain a fifth determination result; the determining whether cache data corresponding to the first data identifier exists in the cache server and the current moment has not reached the expiration time of the cache data may specifically include: if the fifth determination result is yes, determining whether cache data corresponding to the first data identifier exists in the cache server and the current moment has not reached the expiration time of the cache data.
[0074] In the embodiments of this specification, a yes result in the fifth judgment may indicate that the cache function has been enabled. Enabling the cache function may indicate that the data requested by the data query request, that is, the data corresponding to the data identifier in the data query request, can be obtained from the cache server. In the embodiments of this specification, if the application server has the cache function enabled, cached data needs to be retrieved from the cache server. The cached data in the cache server has an expiration date and a refresh period. The above judgment can be used to determine whether the cached data in the cache server needs to be updated, thereby enabling more comprehensive processing of the data query request and improving the processing efficiency of the data query request.
[0075] In one or more embodiments of the present specification, optionally, after obtaining the fifth judgment result, the method may further include: if the fifth judgment result is negative, obtaining data corresponding to the first data identifier from a data provider.
[0076] In the embodiments of this specification, if the result of the fifth determination is negative, it may indicate that the cache function is not enabled. Disabling the cache function may mean that after receiving a data query request, the application server may obtain data from the data provider based on the data identifier in the data query request and feed it back to the data querying party, without interacting with the cache server.
[0077] In real-world applications, a cluster may contain thousands of server instances. Single-server concurrency control alone cannot address traffic spikes within the cluster. If every server instance needs to be refreshed, N (N is the size of the single-server asynchronous refresh thread pool) data refresh query requests may be initiated for the same service, causing traffic spikes. This situation increases the likelihood of multiple servers competing for synchronization locks, increasing the probability of failure and operational complexity. To address this issue, related technologies typically introduce distributed synchronization locks, such as Redis and ZooKeeper. These locks are then preempted by each application server instance, ensuring that only one instance can obtain the lock and initiate downstream query requests. However, in high-concurrency, high-performance scenarios, this introduces new middleware dependencies, increasing the probability of failure and operational complexity. Furthermore, if centralized Redis and ZooKeeper fail, the traffic spike problem persists.
[0078] To solve this problem, different refresh times can be set for multiple different servers. Optionally, in an embodiment of this specification, before adding the first data identifier to the queue of data identifiers to be updated, the following steps may also be performed: obtaining a preset refresh duration; obtaining a preset offset duration; using a random number generation algorithm to generate a random refresh duration based on the preset refresh duration and the preset offset duration; the difference between the random refresh duration and the preset refresh duration is less than or equal to the preset offset duration; and the random refresh duration is used to determine the refresh time.
[0079] In the embodiments of this specification, the preset offset duration can be set based on expert experience. The preset offset duration can also be determined based on the data type. The preset offset duration can also be set based on the number of application servers corresponding to the cache server. The value of the preset offset duration can be positively correlated with the number of application servers providing distributed services contained in the cluster to which the application server belongs. The preset offset durations of each application server corresponding to the cache server can be different, or a small number of application servers with the same preset offset duration can exist among the application servers corresponding to the cache server, thereby avoiding the existence of too many application servers with the same preset offset duration, avoiding traffic peaks, reducing the probability of multiple application servers grabbing synchronization locks, and further reducing the probability of failure and the complexity of operation and maintenance.
[0080] In an embodiment of the present specification, each time an application server receives a data query request, it can read the preset refresh duration from the unified configuration center. Alternatively, the unified configuration center assigns the preset refresh duration to the cache server, so that the cache server can store the corresponding relationship between each preset refresh duration and each cached data. The unified configuration center is used to provide configuration information for the distributed system, such as configuring a preset refresh duration for each cached data in the cache server in the distributed system. The preset refresh durations read from the unified configuration center by different servers for the same cached data can be the same, thereby avoiding frequent refreshes of the same cached data, which may cause system instability or waste of resources.
[0081] In an embodiment of this specification, when each application server starts up, it can read a preset offset duration from the configuration of the distributed system. This preset offset duration can be dynamically generated by a unified configuration center and distributed to the distributed system. Alternatively, when each server starts up, it can retrieve the preset offset duration dynamically generated by the unified configuration center from the unified configuration center. The unified configuration center can dynamically generate the preset offset duration so that it can be adjusted based on the number of application servers, preventing a large number of servers from obtaining the same offset duration, thereby reducing the number of application servers that simultaneously initiate refresh query requests to the cache server.
[0082] In the embodiment of this specification, the time difference between the random refresh duration and the preset refresh duration is less than or equal to the preset offset duration, which may indicate that the absolute value of the time difference between the random refresh duration and the preset refresh duration is less than the preset offset duration.
[0083] In the embodiments of the present specification, the random refresh duration can be obtained by summing the refresh duration and the random offset duration corresponding to the application server. The random offset duration can be generated based on the preset offset duration using a random number generation algorithm. For example, each application server reads a preset offset duration of 2s from the unified configuration center, and each application server calculates the corresponding random offset duration using a random number generation algorithm based on the preset offset duration. Application server a randomly calculates a random offset duration of -2s based on the preset offset duration of 2s, application server b randomly calculates a random offset duration of 1s based on the preset offset duration of 2s, and application server c randomly calculates a random offset duration of 2s based on the preset offset duration of 2s. Assuming that the preset refresh duration is 10s, it can be determined that the random refresh duration of application server a is 10s+(-2s)=8s, the random refresh duration of application server b is 10s+1s=11s, and the random refresh duration of application server c is 10s+2s=12s.
[0084] In practical applications, if the refresh times of cached data obtained by each application server are randomly offset, multiple application servers can obtain different refresh times for the same cached data in the cache server, thus preventing multiple application servers in the same cluster from simultaneously determining that the same data cache needs to be refreshed. This solves the problem of cluster traffic peaks at distributed cache data refresh times without introducing new middleware, improving system stability.
[0085] As another embodiment, the random refresh duration can also be determined based on a preset offset coefficient. Optionally, in the embodiment of this specification, before adding the first data identifier to the queue of data identifiers to be updated, the following steps may also be included: obtaining a preset refresh duration; obtaining a preset offset coefficient; using a random number generation algorithm to generate a random refresh duration based on the preset refresh duration and the preset offset coefficient; the deviation of the random refresh duration compared to the preset refresh duration is less than or equal to the preset offset coefficient; the deviation represents the ratio of the time difference between the random refresh duration and the preset refresh duration to the preset refresh duration; the random refresh duration is used to determine the refresh moment.
[0086] In the embodiments of this specification, the preset offset coefficient can be set based on expert experience or the number of application servers belonging to the same service cluster. The random refresh duration can be calculated by, specifically, utilizing a random number generation algorithm to generate a random offset coefficient based on the preset offset coefficient, calculating a random offset value based on the random offset coefficient and the preset refresh duration, and determining the random refresh duration based on the random offset value and the preset refresh duration. For example, the preset offset coefficient is 0.3, and the preset refresh duration is 10s. Based on the preset offset coefficient 0.3, the random offset coefficient calculated by application server d is 0.1, the random offset coefficient calculated by application server e is 0.05, and the random offset coefficient calculated by application server f is -0.2. The random offset value of application server d can be determined to be 10s×0.1=1s, the random offset value of application server e is determined to be 10s×0.05=0.5s, and the random offset value of application server f is determined to be 10s×(-0.2)=-2s. Further, the random refresh duration of application server d can be determined to be 10s+1s=11s, the random refresh duration of application server e is determined to be 10s+0.5s=10.5s, and the random refresh duration of application server f is determined to be 10s+(-2s)=8s.
[0087] In the embodiments of this specification, the deviation may represent the ratio of the absolute value of the difference between the random refresh duration and the preset refresh duration to the preset refresh duration. This allows the first server to determine whether to update the cached data corresponding to the first data identifier based on the random refresh duration that satisfies the condition that the deviation is less than or equal to the preset offset coefficient.
[0088] In actual applications, any of the above methods of determining the random refresh time can enable multiple servers to have different refresh times for the same cached data, thereby avoiding a large number of servers updating the same cached data, thereby solving the problem of cluster traffic peaks at the time of distributed cache data refresh and improving system stability.
[0089] As an implementation mode, optionally, in the embodiments of this specification, the use of a random number generation algorithm to generate a random refresh duration based on the preset refresh duration and the preset offset coefficient may specifically include: using a random number generation algorithm to generate a random offset coefficient whose absolute value is smaller than the preset offset coefficient based on the preset offset coefficient; calculating a random offset duration based on the preset refresh duration and the random offset coefficient; and generating a random refresh duration based on the preset refresh duration and the random offset duration.
[0090] In the embodiments of this specification, the random number generation algorithm may be at least one of the Xorshift algorithm, the PCG series, and a cryptographically secure PRNG. The random number generation algorithm may be used as a time scheduling algorithm based on random hash distribution to determine the specific refresh time of each application server for a cached data. The random offset duration may represent the product of the preset refresh duration and the random offset coefficient. The random refresh duration may represent the sum of the preset refresh duration and the random offset duration. Specifically, the random refresh duration may be calculated by calculating the sum of the random offset coefficient and the value one, and then calculating the product of the sum and the preset refresh duration. For example, if the random offset coefficient is 0.1 and the preset refresh duration is 10s, the random refresh duration may be 11s as calculated by (1+0.1)*10.
[0091] In the embodiments of this specification, a preset offset coefficient can be used to enable the random offset duration to change based on the change of the preset refresh duration, thereby avoiding the situation where the refresh frequency of cached data with lower freshness is higher, which wastes resources, and also avoiding the situation where the refresh frequency of cached data with higher freshness is lower, which makes it impossible to provide users with accurate query data.
[0092] Regarding the value of the preset offset coefficient, optionally, the value of the preset offset coefficient is positively correlated with the number of servers providing distributed services included in the cluster to which the first server belongs.
[0093] In the embodiment of this specification, the more application servers providing distributed services are included in the cluster to which the first server belongs, the larger the value of the preset offset coefficient can be. The unified configuration center can set a reasonable preset offset coefficient based on the number of application servers providing distributed services in the cluster, and send the preset offset coefficient to the application server when the application server starts, so that the application server can determine the random offset coefficient based on the preset offset coefficient, so that multiple different application servers can obtain different refresh times for the same cache data based on the random offset coefficient. In addition, the preset offset coefficient can adapt to various refresh times, and can avoid the problem that directly using the preset offset duration may result in large errors and unreasonable refresh times for each server.
[0094] In order to more clearly illustrate the random refresh duration of each application server, Figure 4 This is a schematic diagram of different application servers updating the same cache data provided by the embodiment of this specification. Figure 4 As shown, a user can operate in APP1, and application server 1 can receive a data query request generated by the user after the operation in APP1, determine the cache data a corresponding to the data identifier A in the data query request, and then obtain the preset cache duration and preset offset coefficient of cache data a from the unified configuration center. The random offset duration is determined to be -2s through the refresh time calculation module. The refresh time of cache data a is determined based on the random offset duration and the preset cache duration. If the current time reaches the refresh time, application server 1 can use the second thread to perform asynchronous refresh processing. Correspondingly, application server 2 can also receive a data query request sent by APP2. The data identifier contained in the data query request can also be the data identifier A used to identify cache data a. Application server 2 can also obtain the preset cache duration and preset offset coefficient of cache data a from the unified configuration center. The random offset duration is determined to be +2s through the refresh time calculation module. The refresh time of cache data a is determined based on the random offset duration and the preset cache duration. If the current time does not reach the refresh time, application server 2 ends the refresh process, does not update cache data a, and only returns the query result to APP2. Correspondingly, the application server 3 can also receive the data query request sent by APP3. The data identifier contained in the data query request can also be the data identifier A used to identify the cached data a. The application server 3 can also obtain the preset cache duration and preset offset coefficient of the cached data a from the unified configuration center, and determine the random offset duration as +1s through the refresh time calculation module. The refresh time of the cached data a is determined based on the random offset duration and the preset cache duration. If the refresh time has not been reached at the current time, the application server 3 ends the processing of the refresh process, does not update the cached data a, and only returns the query result to APP3.
[0095] It is understandable that Figure 4 This is merely an example to illustrate the specific execution process of updating the same cache data by different application servers, and is not intended to be a specific limitation of the embodiments of this specification.
[0096] The various technical features in the above embodiments can be arbitrarily combined as long as there is no conflict or contradiction between the combinations of features. However, due to space limitations, they are not described one by one. Therefore, the arbitrary combination of the various technical features in the above embodiments also falls within the scope of disclosure of this specification.
[0097] According to the above description, in order to clearly illustrate the embodiments of the present application and the corresponding means, Figure 5 This is a flow chart of a data transmission method provided by an embodiment of this specification. The execution subject of the flow may be the first server among multiple application servers included in the distributed system.
[0098] like Figure 5 As shown, step 502: the first server receives a data query request including a first data identifier through a first thread.
[0099] In the embodiments of this specification, a data query request may be a request generated by a user terminal based on a user operation to obtain data. The data query request may also include a user terminal identifier to facilitate determining the terminal receiving the query data based on the user terminal identifier. The user terminal identifier may be used to uniquely identify the user terminal.
[0100] Step 504: Query the activation status of the cache function.
[0101] In the embodiment of the present specification, the first server may query the activation status of the cache function in the distributed system after receiving the query request.
[0102] Step 506: Determine whether the cache function is enabled.
[0103] In an embodiment of this specification, the first server may determine whether the cache function is enabled based on the activation state of the cache function. The activation state may include an on state and an off state. If the activation state is off, it can be determined that the cache function is not enabled, and step 508 may be executed: obtaining source data corresponding to the first data identifier from the data provider.
[0104] In the embodiments of this specification, the cache function is used to cache the data of the data provider to the cache server, so that each application server in the distributed system can obtain the cached data from the cache server, reducing the probability of the data provider receiving a large number of data query requests at the same time and thus crashing.
[0105] If the startup state is on, it can be determined that the cache function is enabled, and then step 510 can be executed: determining whether there is cache data corresponding to the first data identifier in the cache server and the current time has not reached the expiration time of the cache data.
[0106] In an embodiment of the present specification, the cache server may store a first correspondence between a data identifier and cached data, and may also store a second correspondence between cached data and cache time and validity period; or, may store the first correspondence and a third correspondence between cached data and expiration time.
[0107] If there is no cache data corresponding to the first data identifier in the cache server, or if there is cache data corresponding to the first data identifier in the cache server but the cache data has expired at the current moment, step 512 can be executed: blocking the first thread and obtaining the source data corresponding to the first data identifier from the data provider.
[0108] In the embodiment of this specification, blocking the first thread may mean temporarily stopping the process of the first thread obtaining cache data from the cache server and executing the process of obtaining source data from the data provider.
[0109] If the cache server has cache data corresponding to the first data identifier and the current time has not reached the expiration time of the cache data, step 514 may be executed: determining whether the current time has reached the refresh time of the cache data.
[0110] If the current time has not reached the refresh time of the cached data, step 516 may be executed: obtaining the cached data corresponding to the first data identifier and returning it to the data query party.
[0111] If the current time reaches the refresh time of the cached data, step 518 is executed: determining whether there is a second data identifier that is the same as the first data identifier in the queue of data identifiers to be updated.
[0112] If there is a second data identifier identical to the first data identifier in the queue of data identifiers to be updated, step 516 may be executed: obtaining cached data corresponding to the first data identifier and returning the data to the data query party.
[0113] The above-mentioned method can avoid the existence of multiple identical data identifiers in the queue of data identifiers to be updated, reduce the frequency of updating the cache data corresponding to the data identifier, and improve the stability of the data.
[0114] If the queue of data identifiers to be updated does not contain the second data identifier that is identical to the first data identifier, step 520 may be executed: adding a synchronization lock to the queue of data identifiers to be updated.
[0115] Step 522: Add the first data identifier to the queue of data identifiers to be updated.
[0116] Step 524: Release the synchronization lock.
[0117] In an embodiment of the present specification, in order to avoid the situation where multiple application servers simultaneously add the same data identifier to the data identifier to be updated, the first server can add a synchronization lock to the data identifier to be updated queue to prevent other application servers from operating the data identifier to be updated queue. After the first server adds the first data identifier, the synchronization lock can be released to allow other application servers to operate the data identifier queue to be updated, so that the data identifiers in the data identifier to be updated queue are all different.
[0118] Step 526: The first server obtains the first data identifier from the data identifiers to be updated through the second thread.
[0119] Step 528: According to the first data identifier, obtain source data corresponding to the first data identifier from the data provider.
[0120] Step 530: Update the source data to the cache server.
[0121] In an embodiment of this specification, the first server can perform the aforementioned operations via a second thread to complete data retransmission. The second thread can be a thread in a thread pool. The first server can also complete the update of cached data before the cached data expires, thereby avoiding the problem of cache failure caused by a large number of data query requests directly accessing the data provider after the cached data expires. The first thread and the second thread of the first server can be executed concurrently and asynchronously.
[0122] The embodiments of this specification have the same or similar features as one or more of the above embodiments, which will not be described in detail here. You can refer to one or more embodiments corresponding to the above data sending method.
[0123] Through the above method, on the first hand, in the embodiments of this specification, the application server can use the asynchronous refresh mechanism to use the first thread to execute the process corresponding to the data query request when the refresh time is met, and use the second thread to execute the process of updating the cache data in the cache server. It can be determined that the processing flow of real-time requests will not be interfered with when executing the cache refresh operation, and can effectively solve the common thread blocking problem in traditional synchronous refresh methods, avoid the phenomenon of extended response time due to waiting for the refresh to be completed, and can significantly reduce the situation where users may encounter server freezes, thereby improving user experience.
[0124] Secondly, in the embodiments of this specification, the application server can use the mechanism of the identification queue to implement updates. Specifically, a synchronization lock is added to the data identification queue to be updated before adding the data identification, and the synchronization lock is released after the data identification is added. Therefore, there is no need to wait for the data update to be completed before releasing the lock, which greatly shortens the duration of the locked state, reduces the probability of lock contention in a multi-application server or multi-threaded environment, and improves the overall performance and throughput of the system.
[0125] Thirdly, in the embodiments of this specification, a random number generation algorithm can be used to determine the specific refresh time of the cache data corresponding to each application server, thereby dispersing the pressure of different application servers initiating refresh requests at the same time. After any server instance completes the cache refresh and validity period setting, other application server instances can automatically skip unnecessary repeated refresh steps, so that the service request load provided by the entire system to the outside world is always maintained at a stable and controllable level.
[0126] Based on the same idea, the embodiments of this specification also provide a device corresponding to the above method. Figure 6 The embodiments of this specification provide corresponding Figure 2 A structural diagram of a data sending device. Figure 6 As shown, the device may include: A request receiving module 602 is configured to receive, through a first thread, a data query request including a first data identifier; The to-be-updated data identifier queue updating module 604 is configured to add the first data identifier to a to-be-updated data identifier queue if cached data corresponding to the first data identifier exists in the cache server and satisfies a preset refresh condition. The preset refresh condition includes that the cached data has not yet reached its expiration time and has reached its refresh time. The to-be-updated data identifier queue is used by the application server, through a second thread, to obtain source data corresponding to the first data identifier from a data provider based on the first data identifier and to update the source data to the cache server. The data sending module 606 is configured to send the cached data to a data querying party.
[0127] based on Figure 6 The present specification also provides some specific implementation plans of the method, which are described below.
[0128] Optionally, the device may further include a first judgment module, which may be specifically used to: determine whether there is a second data identifier that is identical to the first data identifier in the data identifier queue to be updated, and obtain a first judgment result; and add the first data identifier to the data identifier queue to be updated, specifically including: if the first judgment result is no, adding the first data identifier to the data identifier queue to be updated.
[0129] Optionally, the first judgment module can be specifically used to: calculate the first hash value of the first data identifier; judge whether there is a second data identifier in the data identifier queue to be updated, and obtain a second judgment result; the second hash value of the second data identifier is the same as the first hash value of the first data identifier; if the first judgment result is no, then add the first data identifier to the data identifier queue to be updated, specifically including: if the second judgment result is no, then add the first data identifier to the data identifier queue to be updated.
[0130] Optionally, the first judgment module may be specifically configured to: add a synchronization lock to the queue of data identifiers to be updated; and after adding the first data identifier to the queue of data identifiers to be updated, further comprising: releasing the synchronization lock.
[0131] Optionally, the device may also include a source data update module, which can be specifically used to: the first server obtains the first data identifier from the data identifier queue to be updated through the second thread; based on the first data identifier, obtains the source data corresponding to the first data identifier from the data provider; and updates the source data to the cache server.
[0132] Optionally, the second thread is a thread in the preset thread pool of the first server; the preset thread pool contains a specified number of threads; the threads in the preset thread pool are used to poll the data identifiers in the data identifier queue to be updated, and based on the polled target data identifier, obtain the data corresponding to the target data identifier from the data provider, and update the data corresponding to the target data identifier to the cache server.
[0133] Optionally, the data identifier queue update module to be updated can be specifically used to: respond to the data query request, determine whether there is cache data corresponding to the first data identifier in the cache server and the current time has not reached the expiration time of the cache data, and obtain a third judgment result; if the third judgment result is yes, determine whether the current time has reached the refresh time of the cache data, and obtain a fourth judgment result; the refresh time is earlier than the expiration time; if the fourth judgment result is yes, add the first data identifier to the data identifier queue to be updated.
[0134] Optionally, the to-be-updated data identifier queue update module may be specifically configured to: if the third judgment result is no, obtain source data corresponding to the first data identifier from a data provider; and update the source data to the cache server.
[0135] Optionally, the to-be-updated data identification queue updating module may be specifically configured to: if the fourth judgment result is no, send the cached data to the data querying party.
[0136] Optionally, the data identifier queue update module to be updated can be specifically used to: determine whether the cache function has been enabled to obtain a fifth judgment result; the determination of whether cache data corresponding to the first data identifier exists in the cache server and the expiration time of the cache data has not been reached at the current moment specifically includes: if the fifth judgment result is yes, determining whether cache data corresponding to the first data identifier exists in the cache server and the expiration time of the cache data has not been reached at the current moment.
[0137] Optionally, the to-be-updated data identifier queue updating module may be specifically configured to: if the fifth judgment result is no, obtain source data corresponding to the first data identifier from a data provider.
[0138] Optionally, the device may also include a first random refresh duration generation module, which can be specifically used to: obtain a preset refresh duration; obtain a preset offset duration; use a random number generation algorithm to generate a random refresh duration based on the preset refresh duration and the preset offset duration; the difference between the random refresh duration and the preset refresh duration is less than or equal to the preset offset duration; the random refresh duration is used to determine the refresh time.
[0139] Optionally, the device may also include a second random refresh duration generation module, which can be specifically used to: obtain a preset refresh duration; obtain a preset offset coefficient; use a random number generation algorithm to generate a random refresh duration based on the preset refresh duration and the preset offset coefficient; the deviation of the random refresh duration compared to the preset refresh duration is less than or equal to the preset offset coefficient; the deviation represents the ratio of the time difference between the random refresh duration and the preset refresh duration to the preset refresh duration; the random refresh duration is used to determine the refresh time.
[0140] Optionally, the second random refresh duration generation module can be specifically used to: adopt a random number generation algorithm to generate a random offset coefficient whose absolute value is smaller than the preset offset coefficient based on the preset offset coefficient; calculate the random offset duration based on the preset refresh duration and the random offset coefficient; and generate a random refresh duration based on the preset refresh duration and the random offset duration.
[0141] Optionally, the value of the preset offset coefficient is positively correlated with the number of servers providing distributed services included in the cluster to which the server belongs.
[0142] It is understood that the above modules refer to computer programs or program segments for performing one or more specific functions. In addition, the distinction between the above modules does not mean that the actual program codes must also be separated.
[0143] The above is a schematic scheme of a data sending device of this embodiment. It should be noted that the technical scheme of the data sending device and the technical scheme of the above-mentioned data sending method are of the same concept. For details not described in detail in the technical scheme of the data sending device, please refer to the description of the technical scheme of the above-mentioned data sending method.
[0144] Based on the same idea, the embodiments of this specification also provide devices corresponding to the above methods.
[0145] Figure 7 The embodiments of this specification provide corresponding Figure 2 A structural diagram of a data sending device. Figure 7 As shown, the device 700 may include: at least one processor 710; and a memory 730 communicatively connected to the at least one processor; wherein the memory 730 stores instructions 720 executable by the at least one processor 710, and the instructions are executed by the at least one processor 710 to enable the at least one processor 710 to: receive a data query request containing a first data identifier through a first thread; if there is cached data corresponding to the first data identifier and meeting a preset refresh condition in the cache server, the first data identifier is added to a queue of data identifiers to be updated; the preset refresh condition includes that the current moment has not reached the expiration moment of the cached data and has reached the refresh moment of the cached data; the queue of data identifiers to be updated is used for the application server to obtain the source data corresponding to the first data identifier from the data provider through the second thread according to the first data identifier, and update the source data to the cache server; and send the cached data to the data query party.
[0146] The above is a schematic solution of a computing device of this embodiment. It should be noted that the technical solution of the computing device and the technical solution of the above-mentioned data transmission method are of the same concept. For details not described in detail in the technical solution of the computing device, please refer to the description of the technical solution of the above-mentioned data transmission method.
[0147] An embodiment of the present application further provides a computer-readable storage medium storing computer instructions, which, when executed by a processor, implement the steps of the data sending method as described above.
[0148] The above is a schematic solution of a computer-readable storage medium of this embodiment. It should be noted that the technical solution of the storage medium and the technical solution of the above-mentioned data transmission method are of the same concept. For details not described in detail in the technical solution of the storage medium, please refer to the description of the technical solution of the above-mentioned data transmission method.
[0149] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other. Each embodiment focuses on the differences from other embodiments. In particular, for the device, equipment and medium embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments. The devices, equipment and media provided in the embodiments of this specification correspond to the methods, so the devices, equipment and media also have beneficial technical effects similar to the corresponding methods. Since the beneficial technical effects of the methods have been described in detail above, the beneficial technical effects of the corresponding devices, equipment and media will not be repeated here.
[0150] The foregoing description describes specific embodiments of the present application. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in an order different from that described in the embodiments and still achieve the desired results. Furthermore, the processes depicted in the accompanying drawings do not necessarily require the specific order shown or the sequential order to achieve the desired results. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0151] In the 1990s, technological improvements could be clearly distinguished as either hardware improvements (for example, improvements to circuit structures like diodes, transistors, and switches) or software improvements (improvements to process flows). However, with the advancement of technology, many process flow improvements today can now be considered direct improvements to hardware circuit structures. Designers almost always create the corresponding hardware circuit structure by programming the improved process flow into the hardware circuit. Therefore, it cannot be said that a process flow improvement cannot be implemented using physical hardware modules. For example, a programmable logic device (PLD), such as a field programmable gate array (FPGA), is an integrated circuit whose logical function is determined by user programming. Designers can "integrate" a digital system onto a PLD by programming it themselves, without having to hire a chip manufacturer to design and manufacture a dedicated integrated circuit chip. Moreover, nowadays, instead of manually fabricating integrated circuit chips, this programming is mostly performed using software called a "logic compiler." This is similar to the software compilers used during program development. Before compilation, the original code must be written in a specific programming language, called a Hardware Description Language (HDL). There are many types of HDL, including ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, and RHDL (Ruby Hardware Description Language). Currently, the most commonly used are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art will also understand that simply by programming a method flow in one of these hardware description languages and then programming it into an integrated circuit, a hardware circuit that implements the logic method flow can be easily obtained.
[0152] The controller can be implemented in any suitable manner. For example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, an application-specific integrated circuit (ASIC), a programmable logic controller, and an embedded microcontroller. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. The memory controller can also be implemented as part of the memory control logic. Those skilled in the art will also appreciate that, in addition to implementing the controller purely in computer-readable program code, the controller can also be implemented in the form of logic gates, switches, an application-specific integrated circuit, a programmable logic controller, an embedded microcontroller, etc. by logically programming the method steps. Therefore, such a controller can be considered a hardware component, and the means for implementing the various functions included therein can also be considered as structures within the hardware component. Alternatively, the means for implementing the various functions can be considered both a software module implementing the method and a structure within the hardware component.
[0153] The systems, devices, modules or units described in the above embodiments can be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, the computer can be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices. For the convenience of description, the above devices are described separately by function into various units. Of course, when implementing this application, the functions of each unit can be implemented in the same or multiple software and / or hardware.
[0154] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code. The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of processes and / or boxes in the flowchart and / or block diagram, may be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, such that instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the functions described in the processes. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0155] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0156] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory. Memory may include non-volatile memory in the form of computer-readable media, random access memory (RAM), and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media. Computer-readable media, including both permanent and non-permanent, removable and non-removable media, may be implemented using any method or technology for information storage. Information may be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change RAM (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape storage or other magnetic storage devices, or any other non-transmission media that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transitory media such as modulated data signals and carrier waves.
[0157] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.
[0158] The present application may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communications network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.
[0159] The foregoing is merely an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principles of the present application should be included within the scope of the claims of the present application.
Claims
1. A data transmission method, applied to a distributed system, wherein the distributed system includes a cache server and multiple application servers, the method comprising: A first server among the multiple application servers receives a data query request including a first data identifier through a first thread; If cached data corresponding to the first data identifier exists in the cache server and meets a preset refresh condition, the first data identifier is added to a queue of data identifiers to be updated; the preset refresh condition includes that the expiration time of the cached data has not yet been reached and the refresh time of the cached data has been reached; the queue of data identifiers to be updated is used for the first server to obtain source data corresponding to the first data identifier from a data provider through a second thread according to the first data identifier, and update the source data to the cache server; The cached data is sent to the data query party.
2. The method according to claim 1, before adding the first data identifier to the queue of data identifiers to be updated, further comprising: Determine whether there is a second data identifier identical to the first data identifier in the queue of data identifiers to be updated, and obtain a first determination result; The adding the first data identifier to the queue of data identifiers to be updated specifically includes: If the first judgment result is no, the first data identifier is added to the queue of data identifiers to be updated.
3. The method according to claim 2, wherein determining whether there is a second data identifier identical to the first data identifier in the queue of data identifiers to be updated comprises: Calculating a first hash value of the first data identifier; Determine whether there is a second data identifier in the queue of data identifiers to be updated, and obtain a second determination result; The second hash value of the second data identifier is the same as the first hash value of the first data identifier; If the first judgment result is no, adding the first data identifier to a queue of data identifiers to be updated specifically includes: If the second judgment result is no, the first data identifier is added to the queue of data identifiers to be updated.
4. The method according to claim 2, before adding the first data identifier to the queue of data identifiers to be updated, further comprising: Adding a synchronization lock to the queue of data identifiers to be updated; After adding the first data identifier to the queue of data identifiers to be updated, the method further includes: The synchronization lock is released.
5. The method according to claim 1, further comprising, after adding the first data identifier to a queue of data identifiers to be updated: The first server obtains the first data identifier from the to-be-updated data identifier queue through a second thread; According to the first data identifier, obtaining source data corresponding to the first data identifier from the data provider; The source data is updated to the cache server.
6. The method according to claim 5, wherein: The second thread is a thread in the preset thread pool of the first server; the preset thread pool contains a specified number of threads; the threads in the preset thread pool are used to poll the data identifiers in the data identifier queue to be updated, and based on the polled target data identifier, obtain the data corresponding to the target data identifier from the data provider, and update the data corresponding to the target data identifier to the cache server.
7. The method according to claim 1, wherein adding the first data identifier to a queue of data identifiers to be updated comprises: In response to the data query request, determining whether cache data corresponding to the first data identifier exists in the cache server and whether the current time has not reached the expiration time of the cache data, to obtain a third determination result; If the third judgment result is yes, then judging whether the current time reaches the refresh time of the cached data, and obtaining a fourth judgment result; the refresh time is earlier than the expiration time; If the fourth judgment result is yes, the first data identifier is added to the queue of data identifiers to be updated.
8. The method according to claim 7, further comprising: after obtaining the third judgment result: If the third judgment result is no, obtaining the source data corresponding to the first data identifier from the data provider; The source data is updated to the cache server.
9. The method according to claim 7, further comprising: after obtaining the fourth judgment result: If the fourth judgment result is no, the cached data is sent to the data query party.
10. The method according to claim 7, wherein the determining whether cache data corresponding to the first data identifier exists in the cache server and the current time is before the expiration time of the cache data further comprises: Determine whether the cache function is enabled, and obtain a fifth determination result; The determining whether cache data corresponding to the first data identifier exists in the cache server and the current time has not reached the expiration time of the cache data specifically includes: If the fifth judgment result is yes, it is determined whether cache data corresponding to the first data identifier exists in the cache server and the current time has not reached the expiration time of the cache data.
11. The method according to claim 10, further comprising: after obtaining the fifth judgment result: If the fifth judgment result is no, the source data corresponding to the first data identifier is obtained from the data provider.
12. The method according to claim 1, before adding the first data identifier to the queue of data identifiers to be updated, further comprising: Get the preset refresh time; Get the preset offset duration; Using a random number generation algorithm, based on the preset refresh duration and the preset offset duration, a random refresh duration is generated; The difference between the random refresh duration and the preset refresh duration is less than or equal to the preset offset duration; the random refresh duration is used to determine the refresh time.
13. The method according to claim 1, before adding the first data identifier to the queue of data identifiers to be updated, further comprising: Get the preset refresh time; Get the preset offset coefficient; Using a random number generation algorithm, based on the preset refresh duration and the preset offset coefficient, to generate a random refresh duration; The deviation of the random refresh duration compared to the preset refresh duration is less than or equal to the preset offset coefficient; the deviation represents the ratio of the difference between the random refresh duration and the preset refresh duration to the preset refresh duration; the random refresh duration is used to determine the refresh time.
14. The method according to claim 13, wherein the random number generation algorithm is used to generate the random refresh duration based on the preset refresh duration and the preset offset coefficient, specifically comprising: Using a random number generation algorithm, based on the preset offset coefficient, a random offset coefficient is generated, the absolute value of which is smaller than the preset offset coefficient; Calculating a random offset duration based on the preset refresh duration and the random offset coefficient; A random refresh duration is generated based on the preset refresh duration and the random offset duration.
15. The method of claim 13, wherein: The value of the preset offset coefficient is positively correlated with the number of servers providing distributed services included in the cluster to which the server belongs.
16. A data sending device, applied to an application server, wherein the distributed system includes a cache server and a plurality of the application servers, the data sending device comprising: A request receiving module, configured to receive, through a first thread, a data query request including a first data identifier; a queue update module for data identifiers to be updated, configured to add the first data identifier to a queue of data identifiers to be updated if cache data corresponding to the first data identifier exists in the cache server and satisfies a preset refresh condition; the preset refresh condition includes that the expiration time of the cache data has not yet been reached and the refresh time of the cache data has been reached; the queue of data identifiers to be updated is used by the application server to obtain source data corresponding to the first data identifier from a data provider through a second thread based on the first data identifier, and to update the source data to the cache server; The data sending module is used to send the cached data to the data query party.
17. An application server, wherein a distributed system comprises a cache server and a plurality of the application servers, wherein the application server comprises: at least one processor; as well as, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to: receiving, through a first thread, a data query request including a first data identifier; If cached data corresponding to the first data identifier exists in the cache server and meets a preset refresh condition, the first data identifier is added to a queue of data identifiers to be updated; the preset refresh condition includes that the current time has not reached the expiration time of the cached data and the refresh time of the cached data has reached; the queue of data identifiers to be updated is used for the application server to obtain source data corresponding to the first data identifier from a data provider through a second thread according to the first data identifier, and update the source data to the cache server; The cached data is sent to the data query party.