Data reporting method, device, system, equipment and storage medium

By actively reporting data and managing invalid instances, the problem of data effectiveness in server polling is solved, and effective updates and timeliness of data are improved.

CN114840540BActive Publication Date: 2025-06-20BEIJING QIYI CENTURY SCI & TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210431674.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-22
Publication Date
2025-06-20
Estimated Expiration
2042-04-22

AI Technical Summary

Technical Problem

In the prior art, when the server polls target data of each container instance, the effectiveness cannot be guaranteed, especially when the IP address and port of the container instance change frequently.

Method used

The container instance actively reports the target data and the current timestamp, and obtains the collection of historical container instances in the server when reporting, predicts invalid historical container instances and sends a delete instruction to the server to realize effective data updates.

Benefits of technology

By actively reporting data and managing invalid instances by container instances, the effectiveness of data in the server is ensured, the processing burden on the server is reduced, and the timeliness of data is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114840540B_ABST
    Figure CN114840540B_ABST
Patent Text Reader

Abstract

The present application relates to a method, device, system, equipment and storage medium for reporting data; wherein, the method includes: obtaining target data locally stored in a container instance and a current timestamp, and reporting the target data and the current timestamp to a server; when reporting the target data and the current timestamp to the server, obtaining a set of historical container instances stored in the server from the server; wherein, the set of historical container instances includes at least one historical container instance; obtaining the predicted timestamp of each historical container instance when reporting data next time, and taking the historical container instances with predicted timestamps earlier than the current timestamp as invalid historical container instances; sending an instruction to the server to delete the invalid container instances; wherein, the server deletes the invalid container instances according to the instruction. The present application is used to solve the problem that the validity cannot be guaranteed when the server polls the target data of each container instance in the prior art.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of data update, and in particular, to a method, device, system, equipment and storage medium for reporting data. Background Art

[0002] When the Internet server faces typical scenarios of high concurrency and massive data, the local cache can significantly improve performance. The local cache uses the size space of the process to cache hot data without the consumption brought by network transmission. In practical applications, the memory space of a single container instance is limited, and it is necessary to carefully control the size of the memory space used for the local cache to avoid affecting the service itself. On the other hand, it is necessary to always pay attention to the target data in the current local cache space, such as: the memory space size of the local cache space, and relevant statistical data, such as: hit rate, number of loaded objects, loading time, etc., to provide data support and direction for the monitoring of the cache status and the optimization of the cache policy.

[0003] For high availability, microservices are usually deployed in multiple different data centers, and dozens or even hundreds of container instances of the service will run in each data center. The instance set may change at any time, for example: the expansion of container instances, the elimination or restart of a single abnormal container instance.

[0004] In the prior art, the server actively polls all container instances to extract the statistical data of the storage space. However, since the container instances are stateless, the IP addresses and exposed ports after the container starts or restarts are not fixed. The microservice provides the server externally through the service registration and discovery method. Coupled with the large number of instance sets and the fact that they change at any time, the validity of the target data of the container instances polled by the server cannot be guaranteed. Summary of the Invention

[0005] This application provides a method, device, system, equipment and storage medium for reporting data to solve the problem that the validity of the target data polled by the server from each container instance cannot be guaranteed in the prior art.

[0006] In a first aspect, this application provides a method for reporting data, which is applied to a container instance. The method includes:

[0007] Obtain the target data locally stored in the container instance and the current timestamp, and report the target data and the current timestamp to the server;

[0008] When reporting the target data and the current timestamp to the server, obtain the historical container instance set stored in the server from the server; where the historical container instance set includes at least one historical container instance;

[0009] Obtain the predicted timestamps of each of the historical container instances when they report data next time, and use the historical container instances whose predicted timestamps are earlier than the current timestamp as invalid historical container instances;

[0010] Send an instruction to the server to delete the invalid container instances; wherein, the server deletes the invalid container instances according to the instruction.

[0011] Optionally, the obtaining the predicted timestamps of each of the historical container instances when they report data next time includes:

[0012] For each of the historical container instances, obtain the historical reporting timestamp and the reporting period of the historical container instance;

[0013] Based on the historical reporting timestamp and the reporting period, determine the predicted timestamp of the historical container instance when it reports data next time.

[0014] Optionally, the determining the predicted timestamp of the historical container instance when it reports data next time based on the historical reporting timestamp and the reporting period includes:

[0015] On the basis of the historical reporting timestamp, add the reporting period to obtain the predicted timestamp of the historical container instance when it reports data next time.

[0016] Optionally, the determining the predicted timestamp of the historical container instance when it reports data next time based on the historical reporting timestamp and the reporting period includes:

[0017] Obtain the pre-configured delay duration;

[0018] On the basis of the historical reporting timestamp, add the reporting period and the delay duration to obtain the predicted timestamp of the historical container instance when it reports data next time.

[0019] Optionally, the obtaining the target data locally stored by the container instance and the current timestamp includes:

[0020] Obtain the preset reporting period for the container instance to report the target data to the server;

[0021] Periodically obtain the target data and the current timestamp of the container instance according to the preset reporting period.

[0022] Optionally, the obtaining the preset reporting period for the container instance to report the target data to the server includes:

[0023] Obtain the preset cache expiration duration of the container instance;

[0024] Divide the preset cache expiration duration by a preset coefficient to obtain a first reporting period; wherein, the preset coefficient is a positive number greater than or equal to 1;

[0025] Obtain a preconfigured second reporting period;

[0026] Select the smaller value from the first reporting period and the second reporting period as the preset reporting period.

[0027] Optionally, the historical container instance set is stored in a target cache of the server, and obtaining the historical container instance set stored in the server from the server includes:

[0028] Send an instruction to request the historical container instance set to the server; wherein, the server responds to the instruction to request the historical container instance set and sends the historical container instance set to the container instance;

[0029] Receive the historical container instance set sent by the server.

[0030] Optionally, the target cache includes: a Redis cache, the current timestamp corresponding to the container instance is stored in an ordered set of the Redis cache, and the target data corresponding to the container instance is stored in a hash table in the Redis cache.

[0031] In a second aspect, the present application provides a method for reporting data, which is applied to a server, and the method includes:

[0032] Receive and store the target data and the current timestamp reported by each container instance respectively;

[0033] Receive the instruction sent by each container instance to delete invalid container instances; wherein, when each container instance reports the target data and the current timestamp stored locally in the container instance to the server, obtain the historical container instance set stored in the server; wherein, the historical container instance set includes at least one historical container instance; obtain the predicted timestamp of each historical container instance when reporting data next time; regard the historical container instance whose predicted timestamp is earlier than the current timestamp as an invalid historical container instance; send an instruction to the server to delete the invalid container instance;

[0034] Respond to the instruction and delete the invalid container instance and the historical reporting timestamp and historical target data corresponding to the invalid container instance.

[0035] Optionally, the current timestamp corresponding to each container instance is stored in the sorted set of the Redis cache, and the target data corresponding to each container instance is stored in the hash table in the Redis cache.

[0036] In a third aspect, the present application provides a data reporting system, including: a server and at least one container instance; each of the container instances is communicatively connected to the server;

[0037] Each of the container instances is configured to obtain the target data and the current timestamp stored locally in the container instance, and report the target data and the current timestamp to the server; when reporting the target data and the current timestamp to the server, obtain the set of historical container instances stored in the server from the server; wherein, the set of historical container instances includes at least one historical container instance; obtain the predicted timestamp for each of the historical container instances when reporting data next time, and use the historical container instances with the predicted timestamp earlier than the current timestamp as invalid historical container instances; send an instruction to the server to delete the invalid container instances; wherein, the server deletes the invalid container instances according to the instruction.

[0038] The server is configured to receive and store the target data and the current timestamp reported by each container instance; receive the instruction sent by each container instance to delete the invalid container instances; and in response to the instruction, delete the invalid container instances and the historical reporting timestamps and historical target data corresponding to the invalid container instances.

[0039] In a fourth aspect, the present application provides a data reporting device, which is applied to a container instance, and the device includes:

[0040] A reporting module, configured to obtain the target data and the current timestamp stored locally in the container instance, and report the target data and the current timestamp to the server;

[0041] An obtaining module, configured to obtain the set of historical container instances stored in the server from the server when reporting the target data and the current timestamp to the server; wherein, the set of historical container instances includes at least one historical container instance;

[0042] A prediction module, configured to obtain the predicted timestamp for each of the historical container instances when reporting data next time, and use the historical container instances with the predicted timestamp earlier than the current timestamp as invalid historical container instances;

[0043] A sending module, configured to send an instruction to the server to delete the invalid container instances; wherein, the server deletes the invalid container instances according to the instruction.

[0044] In a fifth aspect, the present application provides a data reporting device applied to a server. The device includes:

[0045] A first receiving module, configured to receive and store the target data and the current timestamp reported by each container instance respectively;

[0046] A second receiving module, configured to receive the instruction for deleting invalid container instances sent by each of the container instances; wherein, when each container instance reports the target data and the current timestamp stored locally in the container instance to the server, it obtains the set of historical container instances stored in the server; wherein, the set of historical container instances includes at least one historical container instance; obtains the predicted timestamp of each of the historical container instances when reporting data next time; takes the historical container instances whose predicted timestamp is earlier than the current timestamp as invalid historical container instances; and sends an instruction for deleting the invalid container instances to the server;

[0047] A deleting module, configured to respond to the instruction and delete the invalid container instances, as well as the historical reporting timestamps and historical target data corresponding to the invalid container instances.

[0048] In a sixth aspect, the present application provides an electronic device, including: a processor, a communication interface, a memory, and a communication bus. Among them, the processor, the communication interface, and the memory complete communication with each other through the communication bus; the memory is used to store a computer program; the processor is configured to execute the program stored in the memory to implement the data reporting method described in the first aspect or the data reporting method described in the second aspect.

[0049] In a seventh aspect, the present application provides a computer-readable storage medium storing a computer program, and when the computer program is executed by a processor, it implements the data reporting method described in the first aspect or the data reporting method described in the second aspect.

[0050] The above technical solutions provided in the embodiments of the present application have the following advantages compared with the prior art: In the method provided in the embodiments of the present application, the container instance actively reports the target data and the current timestamp. There is no need for the server to actively poll all container instances. While the container instance reports its own data, it is also responsible for determining the invalid container instances in the server and instructing the server to delete the invalid container instances, realizing the update of the valid data in the server, ensuring the validity of the data, and freeing the server from the work of data validity and handing it over to each container instance for reporting services. Moreover, the server only needs to wait to receive the target data and the current timestamp reported by the container instance, without actively polling all container instances, which also reduces the burden on the server for processing data and interacting with the container instances. Description of the Drawings

[0051] The accompanying drawings here are incorporated into the specification and form a part of this specification, showing embodiments in accordance with the present invention, and are used together with the specification to explain the principles of the present invention.

[0052] Figure 1 A schematic diagram of a system architecture to which a method for reporting data provided by an embodiment of this application is applied;

[0053] Figure 2 A schematic flowchart of a method for reporting data applied to a container instance provided by an embodiment of this application;

[0054] Figure 3 A schematic flowchart of a method for obtaining a preset reporting period of a container instance provided by an embodiment of this application;

[0055] Figure 4 A schematic flowchart of a method for reporting data applied to a server provided by an embodiment of this application;

[0056] Figure 5 A schematic flowchart of a process for deleting historical reporting timestamps and historical target data of invalid historical container instances provided by an embodiment of this application;

[0057] Figure 6 A schematic diagram of the structure of a data reporting device applicable to a container instance provided by an embodiment of this application;

[0058] Figure 7 A schematic diagram of the structure of a data reporting device applicable to a server provided by an embodiment of this application;

[0059] Figure 8 A schematic diagram of the structure of an electronic device provided by an embodiment of this application. Detailed implementation manners

[0060] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of this application.

[0061] In the prior art, the server uses an active polling method to obtain target data from all container instances. On the one hand, the total number of container instances is relatively large, and the time cost of one active poll is high, and it is impossible to guarantee the validity and timeliness of the target data (for example, relevant statistical data of the cache space) of the polled container instances. Moreover, since the container running instance is stateless, the IP address and exposed port after each restart are not fixed. For the server to poll each container instance, it needs to obtain the currently alive container instances through the method of registration and discovery, which is a relatively large burden for the server.

[0062] Based on the above technical problems, an embodiment of the present application provides a method for reporting data to solve the technical problem that the effectiveness cannot be guaranteed when the server polls each container instance to obtain target data in the prior art.

[0063] Before introducing a method for reporting data provided by an embodiment of the present application, first introduce the system architecture applied by the method for reporting data provided by the embodiment of the present application, as Figure 1 shown, the system architecture applied by the method for reporting data provided by the embodiment of the present application includes: a server 101 and at least one container instance 102; each container instance 102 is communicatively connected to the server 101; in specific implementation, a communication connection is established between each container instance 102 and the server 101 through a network, specifically it can be a wireless network. Different container instances 102 can be deployed in different data centers.

[0064] Among them, each container instance 102 is used to obtain the target data stored locally in the container instance and the current timestamp, and report the target data and the current timestamp to the server; when reporting the target data and the current timestamp to the server, obtain the set of historical container instances stored in the server from the server; where the set of historical container instances includes at least one historical container instance; obtain the respective predicted timestamps when each historical container instance reports data next time, and use the historical container instances whose predicted timestamps are earlier than the current timestamp as invalid historical container instances; send an instruction to the server to delete the invalid container instances; where the server deletes the invalid container instances according to the instruction;

[0065] The server 101 is used to receive and store the target data and the current timestamp reported by each container instance; receive the instructions sent by each container instance to delete the invalid container instances; and in response to the instructions, delete the invalid container instances and the historical reporting timestamps and historical target data corresponding to the invalid container instances.

[0066] In the embodiment of the present application, an independent reporting service is integrated inside the container instance to report the data of the container instance itself to the server. While reporting its own data, it is also responsible for determining the invalid container instances in the server and instructing the server to delete the invalid container instances, realizing the update of the valid data in the server, and freeing the server from the work of data validity and handing it over to the reporting services of each container instance.

[0067] Based on the above system architecture, an embodiment of the present application provides a method for reporting data, which is applied to a container instance, as Figure 2 shown, the method includes:

[0068] Step 201, obtain the target data stored locally in the container instance and the current timestamp, and report the target data and the current timestamp to the server;

[0069] In specific implementation, for high availability, microservices are usually deployed in multiple different data centers, and dozens or even hundreds of container instances (CI for short) of the service will run in each data center.

[0070] The target data for each container instance can be at least one of the cached data in each container instance, the size of the cache space, and the relevant statistical data of the cache space; among them, the relevant statistical data includes: cache hit rate, number of loaded objects, loading time, etc.

[0071] The current timestamp refers to the reporting timestamp when the container instance reports the target data, and is used to determine whether the target data of the container instance is valid based on the reporting timestamp when reporting the target data subsequently.

[0072] In specific implementation, the server can be a statistics center for storing the relevant statistical data of the cache space, such as: cache hit rate, number of loaded objects, loading time, etc.

[0073] Step 202, when reporting the target data and the current timestamp to the server, obtain the set of historical container instances stored in the server from the server; where the set of historical container instances includes at least one historical container instance.

[0074] In specific implementation, the container instance sends an instruction to request the set of historical container instances to the server; where the server responds to the instruction to request the set of historical container instances and sends the set of historical container instances to the container instance; the container instance receives the set of historical container instances sent by the server.

[0075] In specific implementation, each container instance has a globally unique instance name or identifier (ID), and the globally unique instance name or identifier of each historical container instance can be stored in the set of historical container instances to mark each container instance. In addition, each historical container instance stores the reporting period and the historical reporting timestamp correspondingly.

[0076] Step 203, obtain the predicted timestamp for each historical container instance when reporting data next time, and use the historical container instances with the predicted timestamp earlier than the current timestamp as invalid historical container instances.

[0077] Among them, in order to ensure the validity of the data stored in the server, when each container instance reports the target data, it will try to filter out the invalid historical container instances in the server. In specific implementation, when reporting the target data, a request to obtain the set of historical container instances is sent to the server at the same time; from the server, the historical reporting timestamp and reporting period of each historical container instance in the set of historical container instances are obtained; according to the historical reporting timestamp and reporting period, the predicted timestamp when the historical container instance reports data next time is determined. If the predicted timestamp is earlier than the current timestamp, the historical container instance is regarded as an invalid historical container instance. After determining the invalid historical container instances, a deletion instruction to delete the invalid historical container instances is sent to the server; among them, the server deletes the invalid historical container instances according to the deletion instruction.

[0078] Among them, for determining the respective predicted timestamps when each historical container instance reports data next time, the following two methods can be adopted:

[0079] First, without considering delay, the method for obtaining the respective predicted timestamps when the historical container instances report data next time is: obtain the historical reporting timestamp and reporting period of each historical container instance; for each historical container, on the basis of the historical reporting timestamp, add the reporting period to obtain the predicted timestamp for the next report. If it is determined that the predicted timestamp is earlier than the current timestamp, the historical container instance is determined to be an invalid historical container instance.

[0080] Among them, the historical reporting timestamp refers to the reporting timestamp when the historical container instance reports the target data. Adding the reporting period to the historical reporting timestamp, that is, obtaining the predicted timestamp for the next report of the historical container instance; if after adding a reporting period to the historical reporting timestamp of the historical container instance, the obtained predicted timestamp is still earlier than the current timestamp, it means that the stored historical container instance has expired and is an invalid historical container instance.

[0081] Specifically, in order to further understand the method for confirming invalid historical container instances without considering delay, a specific example is used for further explanation:

[0082] Suppose the historical reporting timestamp of the historical container instance is 15:15:20 on September 7, 2021, the reporting period of this historical container instance is 15 seconds, and the current timestamp is 15:55:20 on September 7, 2021; among them, for the method of confirming the reporting period of the historical container instance, the method for determining the preset reporting period can be referred to, or other methods can be adopted, which will not be elaborated here.

[0083] Adding the reporting period of 15 seconds of the historical container instance to the historical reporting timestamp of 15:15:20 on September 7, 2021, the predicted timestamp obtained is 15:15:35 on September 7, 2021. The time of this predicted timestamp is much earlier than the current timestamp, indicating that this historical container instance has expired and is an invalid historical container instance.

[0084] Second, in the case of considering latency:

[0085] In practical applications, due to network performance and server loading delays, there may be a certain latency. To more accurately determine the predicted timestamps for each historical container instance when reporting data next time, the latency duration also needs to be considered. Among them, the latency duration is determined according to experience and is a preset value.

[0086] Specifically, the method for determining the predicted timestamp for each historical container instance when reporting data next time is as follows: Obtain the historical reporting timestamp and reporting period of each historical container instance; obtain the pre-configured latency duration; for each historical container, add the reporting period and the latency duration to the historical reporting timestamp to obtain the predicted timestamp for the next report. If it is determined that the predicted timestamp is earlier than the current timestamp, then determine that the historical container instance is an invalid historical container instance.

[0087] Adding the reporting period and the latency duration to the historical reporting timestamp, we get the predicted timestamp for the historical container instance when reporting next time; if the predicted timestamp obtained by adding a reporting period and the latency duration to the historical reporting timestamp of the historical container instance is still earlier than the current timestamp, it indicates that the stored historical container instance has expired and is an invalid historical container instance.

[0088] Specifically, to further understand the method for confirming an invalid historical container instance in the case of considering latency, a specific example is used for further explanation:

[0089] Suppose the historical reporting timestamp of the historical container instance is 15:15:20 on September 7, 2021, the reporting period of this historical container instance is 15 seconds, the current timestamp is 15:55:20 on September 7, 2021; and the latency duration is 2 seconds.

[0090] Adding the reporting period of 15 seconds of the historical container instance to the historical reporting timestamp of 15:15:20 on September 7, 2021, and then adding the latency duration of 2 seconds, the predicted timestamp obtained is 15:15:37 on September 7, 2021. The time of this predicted timestamp is much earlier than the current timestamp, indicating that this historical container instance has expired and is an invalid historical container instance.

[0091] The embodiments of the present application provide two methods for determining invalid historical container instances, and in practical applications, either of the above two methods can be adopted according to needs.

[0092] Step 204: Send an instruction to the server to delete the invalid container instance; wherein, the server deletes the invalid container instance according to the instruction.

[0093] After obtaining the invalid historical container instance, when sending a deletion instruction to the server, the instance name of each invalid historical container instance can be carried in the deletion instruction. The instance name is globally unique in the server. The server locates the historical container instance corresponding to the instance name based on the instance name carried in the deletion instruction and deletes it.

[0094] In the embodiments of the present application, the container instance actively reports the target data and the current timestamp, without the server actively polling all container instances. While the container instance reports its own data, it is also responsible for determining the invalid container instances in the server and instructing the server to delete the invalid container instances, realizing the update of the valid data in the server, ensuring the validity of the data, and freeing the server from the work of data validity and handing it over to each container instance reporting service.

[0095] Moreover, the server only needs to wait to receive the target data and the current timestamp reported by the container instance, without actively polling all container instances, which also reduces the burden on the server to process data and interact with the container instances.

[0096] In a specific embodiment, in step 201, for the container instance, when reporting the target data and the current timestamp, the obtained target data and the current timestamp can be reported to the server according to a preset reporting period. Specifically, obtain the preset reporting period for the container instance to report the target data to the server; according to the preset reporting period, periodically obtain the target data and the current timestamp of the container instance and report them.

[0097] Among them, the preset reporting period can be set in advance according to the situation of the container instance itself. It can also be obtained by the method as Figure 3 shown. The embodiments of the present application provide a method for obtaining the preset reporting period of the container instance. The method includes: Figure 3 As shown, the embodiments of the present application provide a method for obtaining the preset reporting period of the container instance. The method includes:

[0098] Step 301: Obtain the preset cache expiration duration of the container instance;

[0099] Among them, the preset cache expiration duration refers to the maximum duration for which data stored in the cache space is stored in the cache space of each container instance. If the preset cache expiration duration is exceeded, the data is deleted from the cache space of the container instance. For ease of understanding, an example is given. The preset cache expiration duration is 30 seconds. Starting from the time when data A is cached in the cache space, if data A has been stored in the cache space for more than 30 seconds, then data A is deleted from the cache space of the container instance.

[0100] Step 302: Divide the preset cache expiration duration by the preset coefficient to obtain the first reporting period.

[0101] Among them, the preset coefficient can be set as needed. The preset coefficient is a positive number greater than or equal to 1. Preferably, the preset coefficient is a positive number greater than or equal to 2. For example, the preset coefficient is set to 2, 3, or 4. Of course, it can also be set to other values according to needs, and this is not limited here.

[0102] Step 303: Obtain the pre-configured second reporting period.

[0103] Specifically, the pre-configured second reporting period can be obtained from the configuration center. In a specific implementation, the user can set the second reporting period from the configuration center. For example, the second reporting period is set to 60 seconds.

[0104] Step 304: Select the smaller value from the first reporting period and the second reporting period as the preset reporting period.

[0105] Compare the magnitudes of the first reporting period and the second reporting period, and use the smaller value as the preset reporting period.

[0106] For ease of understanding the method for obtaining the preset reporting period, the embodiments of the present application are further elaborated by way of examples.

[0107] Suppose the preset cache expiration duration of the container instance is 30 seconds and the preset coefficient is 2. Then, divide the preset cache expiration duration of 30 seconds by the preset coefficient of 2 to obtain the first reporting period of 15 seconds. And the second reporting period set by the user from the configuration center is 60 seconds. Then, for the first reporting period of 15 seconds and the second reporting period of 60 seconds, the smaller value is 15 seconds, so the preset reporting period is determined to be 15 seconds.

[0108] In the embodiments of the present application, dividing the preset cache expiration duration by the preset coefficient to obtain the first reporting period and selecting the smaller value from the first reporting period and the second reporting period as the preset reporting period can ensure that the target data is reported at least once within a life cycle of the cached data, and can ensure the timeliness of the target data reported to the server.

[0109] In a specific embodiment, a cache REDIS can be used to store the target data corresponding to each instance name. Among them, Redis (Remote Dictionary Server), that is, the remote dictionary service, is an open-source log-type, Key-Value database written in ANSI C language, supporting networks, and can be based on memory or persistent, and provides APIs in multiple languages.

[0110] Specifically, in the cache REDIS, sorted sets are used to store each container instance, and hash tables are used to store the target data of each container instance. For example: relevant statistical data of the cache space of the container instance: cache hit rate, number of loaded objects, loading time, etc.

[0111] Among them, duplicate members (container instances) are not allowed in the sorted set of REDIS, and each member has a member score, which is the basis for sorting the members of the sorted set. The member value of each member in the sorted set is the globally unique instance name of the container instance, and the member score is the reported timestamp (ReportTimeStamp). For the hash table, duplicate keys are also not allowed, and its key is also the instance name, and the value is the target data corresponding to the instance name.

[0112] Based on the data structure of REDIS to implement storage, the time complexity of determining invalid instances from the sorted set is only O(log(N)+M), where N is the number of historical container instances in the sorted set, and M is the number of invalid historical container instances. The time complexity of updating the reported timestamp of the container instance in the sorted set and updating the target data in the hash table is both O(1).

[0113] In the embodiment of the present application, the data structure of REDIS is used to implement storage, ensuring that the reporting service is lightweight and fast, has little impact on the microservice itself, has a low time complexity, and uses the atomicity of REDIS transactions to avoid data disorder problems when concurrently eliminating invalid historical container instances.

[0114] In addition, based on the same technical concept, the embodiment of the present application also provides a method for reporting data, which is applied to a server, as Figure 4 shown, and the method includes:

[0115] Step 401, receive and store the target data reported by each container instance and the current timestamp;

[0116] In specific implementation, for high availability, microservices are usually deployed in multiple different data centers, and dozens or even hundreds of container instances (Container Instance, abbreviated as CI) of the service will run in each data center.

[0117] The target data for each container instance can be at least one of the cached data in each container instance, the size of the cache space, and the relevant statistical data of the cache space; among them, the relevant statistical data includes: cache hit rate, number of loaded objects, loading time, etc.

[0118] The current timestamp refers to the reporting timestamp when the container instance reports the target data, and is used to determine whether the target data of the container instance is valid based on the reporting timestamp when reporting the target data subsequently.

[0119] Step 402, receive the instructions sent by each container instance to delete invalid container instances; among them, when each container instance reports the target data and the current timestamp stored locally in the container instance to the server, obtain the set of historical container instances stored in the server; among them, the set of historical container instances includes at least one historical container instance; obtain the predicted timestamp for each historical container instance when reporting data next time; regard the historical container instances with predicted timestamps earlier than the current timestamp as invalid historical container instances; send instructions to the server to delete invalid container instances;

[0120] Step 403, respond to the instruction, and delete the invalid container instances and the corresponding historical reporting timestamps and historical target data of the invalid container instances.

[0121] For the understanding of steps 401 to 403, reference can be made to steps 201 to 204, and the repeated parts will not be described in detail.

[0122] In the embodiments of the present application, in order to ensure the validity of the data stored in the server, when each container instance reports the target data, it will usually screen out the invalid historical container instances in the server and send a deletion instruction to delete the invalid historical container instances to the server. Based on this deletion instruction, the server deletes the invalid historical container instances in the historical data and the corresponding historical reporting timestamps and historical target data of the invalid historical container instances. As Figure 5 shown, the process of the server deleting the historical reporting timestamps and historical target data of the invalid historical container instances is as follows:

[0123] Step 501, receive the instruction sent by at least one container instance to request the set of historical container instances; among them, the instruction to request the set of historical container instances is used to obtain the set of historical container instances in the server from the target cache;

[0124] Among them, the target cache is used to store the data reported by each historical container instance, specifically including: the historical target data reported by each historical container instance and the historical reporting timestamp corresponding to the historical target data. In addition, the reporting period corresponding to the historical container instance can also be stored, etc.

[0125] In specific implementation, the target cache includes: a Redis cache. The reporting timestamp corresponding to the container instance can be stored in the sorted set of the Redis cache, and the target data corresponding to the container instance can be stored in the hash table in the Redis cache.

[0126] Step 502: Send the set of historical container instances to at least one container instance; the set of historical container instances is used for the container instance to determine the invalid historical container instances.

[0127] Among them, the method for the container instance to determine the invalid historical container instances can refer to the above two methods for determining the invalid historical container instances. In practical applications, any one of the above two methods can be adopted according to needs, and will not be elaborated here.

[0128] Step 503: Receive the deletion instructions for deleting the invalid historical container instances sent by each container instance.

[0129] In specific implementation, the instance name of each invalid historical container instance can be carried in the deletion instruction. The instance name is globally unique in the server, and the server finds the historical container instance corresponding to the instance name based on the instance name carried in the deletion instruction.

[0130] Step 504: Based on the deletion instruction, delete the invalid historical container instances, as well as the historical reporting timestamp and historical target data corresponding to the invalid historical container instances.

[0131] Specifically, after finding the historical container instance corresponding to the instance name, delete the historical reporting timestamp and historical target data corresponding to the historical container instance. Specifically, delete the instance name and the historical reporting timestamp from the sorted set; and delete the instance name and the target data corresponding to the instance name from the hash table.

[0132] Based on the same concept, an apparatus for reporting data is provided in an embodiment of the present application. The specific implementation of the apparatus can refer to the description in the method embodiment part, and the repeated parts will not be elaborated.

[0133] As Figure 6 shown, the apparatus is applicable to container instances, and the apparatus mainly includes:

[0134] A reporting module 601, configured to obtain the target data and the current timestamp stored locally in the container instance, and report the target data and the current timestamp to the server.

[0135] An obtaining module 602, configured to obtain, from the server, a set of historical container instances stored in the server when reporting the target data and the current timestamp to the server; wherein, the set of historical container instances includes at least one historical container instance.

[0136] A prediction module 603, configured to obtain the predicted timestamp for each of the historical container instances when reporting data next time, and use the historical container instances whose predicted timestamps are earlier than the current timestamp as invalid historical container instances.

[0137] A sending module 604, configured to send an instruction to the server to delete the invalid container instances; wherein, the server deletes the invalid container instances according to the instruction.

[0138] In a specific embodiment, the prediction module 603 is configured to, for each of the historical container instances, obtain the historical reporting timestamp and the reporting period of the historical container instance; and determine the predicted timestamp for the historical container instance when reporting data next time based on the historical reporting timestamp and the reporting period.

[0139] In a specific embodiment, the prediction module 603 is configured to add the reporting period to the historical reporting timestamp to obtain the predicted timestamp for the historical container instance when reporting data next time.

[0140] In a specific embodiment, the prediction module 603 is configured to obtain a pre-configured delay duration; and add the reporting period and the delay duration to the historical reporting timestamp to obtain the predicted timestamp for the historical container instance when reporting data next time.

[0141] In a specific embodiment, a reporting module 601 is configured to obtain a preset reporting period for the container instance to report the target data to the server; and periodically obtain the target data and the current timestamp of the container instance according to the preset reporting period.

[0142] In a specific embodiment, the reporting module 601 is configured to obtain a preset cache expiration duration of the container instance; divide the preset cache expiration duration by a preset coefficient to obtain a first reporting period; wherein, the preset coefficient is a positive number greater than or equal to 1; obtain a pre-configured second reporting period; and select the smaller value from the first reporting period and the second reporting period as the preset reporting period.

[0143] In a specific embodiment, when the historical container instance set is stored in the target cache of the server, the acquisition module 602 is configured to send an instruction for requesting the historical container instance set to the server; wherein, the server responds to the instruction for requesting the historical container instance set and sends the historical container instance set to the container instance; and receives the historical container instance set sent by the server.

[0144] In a specific embodiment, the target cache includes: a Redis cache, the current timestamp corresponding to the container instance is stored in an ordered set of the Redis cache, and the target data corresponding to the container instance is stored in a hash table in the Redis cache.

[0145] Based on the same concept, an embodiment of the present application provides a data reporting device. For the specific implementation of the device, reference may be made to the description in the method embodiment part, and repeated parts will not be elaborated.

[0146] As Figure 7 shown, the device is applicable to a server, and the device mainly includes:

[0147] A first receiving module 701, configured to receive and store the target data and the current timestamp reported by each container instance respectively;

[0148] A second receiving module 702, configured to receive an instruction for deleting invalid container instances sent by each of the container instances; wherein, when each of the container instances reports the target data and the current timestamp stored locally in the container instance to the server, obtain the historical container instance set stored in the server; wherein, the historical container instance set includes at least one historical container instance; obtain the predicted timestamp for each of the historical container instances when reporting data next time; use the historical container instances with the predicted timestamp earlier than the current timestamp as invalid historical container instances; and send an instruction for deleting the invalid container instances to the server;

[0149] A deletion module 703, configured to respond to the instruction and delete the invalid container instances, as well as the historical reporting timestamps and historical target data corresponding to the invalid container instances.

[0150] In a specific embodiment, the current timestamp corresponding to each of the container instances is stored in an ordered set of the Redis cache, and the target data corresponding to each of the container instances is stored in a hash table in the Redis cache.

[0151] Based on the same concept, an embodiment of the present application further provides an electronic device, as Figure 8As shown, the electronic device mainly includes: a processor 801, a memory 802, and a communication bus 803. Among them, the processor 801 and the memory 802 communicate with each other through the communication bus 803. Among them, the memory 802 stores a program executable by the processor 801, and the processor 801 executes the program stored in the memory 802 to implement the following steps:

[0152] Obtain the target data and the current timestamp stored locally in the container instance, and report the target data and the current timestamp to the server;

[0153] When reporting the target data and the current timestamp to the server, obtain the set of historical container instances stored in the server from the server; among them, the set of historical container instances includes at least one historical container instance;

[0154] Obtain the predicted timestamp for each of the historical container instances when reporting data next time, and use the historical container instances whose predicted timestamp is earlier than the current timestamp as invalid historical container instances;

[0155] Send an instruction to the server to delete the invalid container instance; among them, the server deletes the invalid container instance according to the instruction;

[0156] Or,

[0157] Receive and store the target data and the current timestamp reported by each container instance respectively;

[0158] Receive the instruction sent by each container instance to delete the invalid container instance; among them, when each container instance reports the target data and the current timestamp stored locally in the container instance to the server, obtain the set of historical container instances stored in the server; among them, the set of historical container instances includes at least one historical container instance; obtain the predicted timestamp for each of the historical container instances when reporting data next time; use the historical container instances whose predicted timestamp is earlier than the current timestamp as invalid historical container instances; send an instruction to the server to delete the invalid container instance;

[0159] Respond to the instruction, and delete the invalid container instance, as well as the historical reporting timestamp and historical target data corresponding to the invalid container instance.

[0160] The communication bus 803 mentioned in the above electronic device may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The communication bus 803 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 8 it is represented by only one thick line in Figure 8 , but this does not mean that there is only one bus or one type of bus.

[0161] The memory 802 may include a Random Access Memory (RAM), and may also include a non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located far from the aforementioned processor 801.

[0162] The aforementioned processor 801 may be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc., and may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0163] In another embodiment of the present application, a computer-readable storage medium is further provided. A computer program is stored in the computer-readable storage medium. When the computer program runs on a computer, the computer is caused to execute a method for reporting a type of data described in the above embodiment.

[0164] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer instructions are loaded and executed on a computer, the processes or functions described in the embodiments of the present application are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions are transmitted from one website, computer, server, or data center to another website, computer, server, or data center by wire (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer, or a data storage device such as a server or data center that includes one or more integrated available media. The available medium can be a magnetic medium (such as a floppy disk, hard disk, magnetic tape, etc.), an optical medium (such as a DVD), or a semiconductor medium (such as a solid-state drive), etc.

[0165] It should be noted that in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including", or any other variant thereof is intended to cover a non-exclusive inclusion, such that a process, method, article, or device that includes a series of elements includes not only those elements but also other elements that are not explicitly listed, or also includes elements that are inherent to such process, method, article, or device. Without further limitation, an element defined by the statement "including one..." does not exclude the existence of additional identical elements in the process, method, article, or device that includes the said element.

[0166] The above are only specific embodiments of the present invention, enabling those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to these embodiments shown herein, but rather to the broadest scope consistent with the principles and novel features claimed herein.

Claims

1. A method for reporting data, characterized in that, Applied to a container instance, the method includes: Obtain the target data locally stored in the container instance and the current timestamp, and report the target data and the current timestamp to the server; When reporting the target data and the current timestamp to the server, obtain the set of historical container instances stored in the server from the server; wherein, the set of historical container instances includes at least one historical container instance; Obtain the predicted timestamp for each of the historical container instances when reporting data next time, and use the historical container instances whose predicted timestamp is earlier than the current timestamp as invalid historical container instances; Send an instruction to the server to delete the invalid container instances; wherein, the server deletes the invalid container instances according to the instruction.

2. The method for reporting data according to claim 1, characterized in that, The obtaining the predicted timestamp for each of the historical container instances when reporting data next time includes: For each of the historical container instances, obtain the historical reporting timestamp and the reporting period of the historical container instance; Based on the historical reporting timestamp and the reporting period, determine the predicted timestamp for the historical container instance when reporting data next time.

3. The method for reporting data according to claim 2, characterized in that, The determining the predicted timestamp for the historical container instance when reporting data next time based on the historical reporting timestamp and the reporting period includes: On the basis of the historical reporting timestamp, add the reporting period to obtain the predicted timestamp for the historical container instance when reporting data next time.

4. The method for reporting data according to claim 2, characterized in that, The determining the predicted timestamp for the historical container instance when reporting data next time based on the historical reporting timestamp and the reporting period includes: Obtain the pre-configured delay duration; On the basis of the historical reporting timestamp, add the reporting period and the delay duration to obtain the predicted timestamp for the historical container instance when reporting data next time.

5. The method for reporting data according to claim 1, characterized in that, The obtaining the target data locally stored in the container instance and the current timestamp includes: Obtain the preset reporting period for the container instance to report the target data to the server; According to the preset reporting period, periodically obtain the target data and the current timestamp of the container instance.

6. The method for reporting data according to claim 5, characterized in that, The obtaining the preset reporting period for the container instance to report the target data to the server includes: Obtain the preset cache expiration duration of the container instance; Divide the preset cache expiration duration by a preset coefficient to obtain a first reporting period; wherein, the preset coefficient is a positive number greater than or equal to 1; Obtain the pre-configured second reporting period; Select the smaller value from the first reporting period and the second reporting period as the preset reporting period.

7. The method for reporting data according to any one of claims 1 to 6, characterized in that, The set of historical container instances is stored in the target cache of the server. The obtaining the set of historical container instances stored in the server from the server includes: Send an instruction to the server to request the set of historical container instances; wherein, the server responds to the instruction to request the set of historical container instances, sends the set of historical container instances to the container instance; receive the set of historical container instances sent by the server.

8. The method for reporting data according to claim 7, characterized in that, The target cache includes: a Redis cache, where the current timestamp corresponding to the container instance is stored in the sorted set of the Redis cache, and the corresponding target data of the container instance is stored in the hash table in the Redis cache.

9. A method for reporting data, characterized in that, Applied to a server, the method includes: Receiving and storing the target data and the current timestamp reported by each container instance respectively; Receiving the instruction sent by each container instance to delete the invalid container instance; wherein, when each container instance reports the target data and the current timestamp stored locally in the container instance to the server, it obtains the set of historical container instances stored in the server; wherein, the set of historical container instances includes at least one historical container instance; obtaining the predicted timestamp of each historical container instance when reporting data next time; taking the historical container instance whose predicted timestamp is earlier than the current timestamp as an invalid historical container instance; sending an instruction to the server to delete the invalid container instance; Responding to the instruction, deleting the invalid container instance and the historical reported timestamp and historical target data corresponding to the invalid container instance.

10. The method for reporting data according to claim 9, characterized in that, The current timestamp corresponding to each container instance is stored in the sorted set of the Redis cache, and the corresponding target data of each container instance is stored in the hash table in the Redis cache.

11. A data reporting system, characterized in that Includes: A server and at least one container instance; each container instance is communicatively connected to the server; Each container instance is used to obtain the target data and the current timestamp stored locally in the container instance, and report the target data and the current timestamp to the server; when reporting the target data and the current timestamp to the server, obtaining from the server the set of historical container instances stored in the server; wherein, the set of historical container instances includes at least one historical container instance; obtaining the predicted timestamp of each historical container instance when reporting data next time, and taking the historical container instance whose predicted timestamp is earlier than the current timestamp as an invalid historical container instance; sending an instruction to the server to delete the invalid container instance; wherein, the server deletes the invalid container instance according to the instruction; The server is used to receive and store the target data and the current timestamp reported by each container instance; receive the instruction sent by each container instance to delete the invalid container instance; respond to the instruction, and delete the invalid container instance and the historical reported timestamp and historical target data corresponding to the invalid container instance.

12. A data reporting device, characterized in that Applied to a container instance, the device includes: A reporting module, configured to obtain the target data and the current timestamp stored locally in the container instance, and report the target data and the current timestamp to the server; An obtaining module, configured to obtain from the server the set of historical container instances stored in the server when reporting the target data and the current timestamp to the server; wherein, the set of historical container instances includes at least one historical container instance; A prediction module, configured to obtain the predicted timestamps of each of the historical container instances when they report data next time, and use the historical container instances whose predicted timestamps are earlier than the current timestamp as invalid historical container instances; A sending module, configured to send an instruction to the server to delete the invalid container instances; wherein, the server deletes the invalid container instances according to the instruction.

13. A data reporting device, characterized in that Applied to a server, the device includes: A first receiving module, configured to receive and store the target data and the current timestamp reported by each container instance; A second receiving module, configured to receive the instruction to delete the invalid container instances sent by each of the container instances; wherein, when each of the container instances reports the target data and the current timestamp stored locally in the container instance to the server, it obtains the set of historical container instances stored in the server; wherein, the set of historical container instances includes at least one historical container instance; obtains the predicted timestamps of each of the historical container instances when they report data next time; uses the historical container instances whose predicted timestamps are earlier than the current timestamp as invalid historical container instances; and sends an instruction to the server to delete the invalid container instances; A deletion module, configured to respond to the instruction and delete the invalid container instances, as well as the historical reporting timestamps and historical target data corresponding to the invalid container instances.

14. An electronic device, characterized in that Including: A processor, a memory, and a communication bus, wherein the processor and the memory complete mutual communication through the communication bus; the memory is used to store a computer program; the processor is used to execute the program stored in the memory to implement the data reporting method according to any one of claims 1 to 8 or the data reporting method according to claim 9 or 10.

15. A computer-readable storage medium storing a computer program, characterized in that When the computer program is executed by the processor, it implements the data reporting method according to any one of claims 1 to 8 or the data reporting method according to claim 9 or 10.

Citation Information

Patent Citations

  • Data processing method and device and gateway server

    CN110417901A

  • Container Docker-based application deployment method and device, and electronic equipment

    CN113835827A