Caching method and device of offline equipment instruction, electronic equipment and medium
Through dual-time queue mechanism and time window management, the storage capacity, performance limitation and timeliness of the IoT platform when handling offline device instructions is solved, and efficient instruction caching and dynamic resource management are achieved.
Patent Information
- Application Number
- CN202411508314.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-28
- Publication Date
- 2025-02-25
- Estimated Expiration
- 2044-10-28
AI Technical Summary
When processing offline device instructions, IoT platforms face storage capacity and performance limitations, as well as timeliness of instructions. In the prior art, solutions based on delay queues and Redis have problems that cannot directly delete specific device messages and have poor performance.
The dual-timed queue mechanism is adopted, and two consecutive time queues are initialized through the current time node as the target time node. Each queue contains multiple time windows. The pending instructions are inserted into the corresponding time window based on the expiration time, and the cleaning operation is performed when the time changes, and the time window is dynamically switched.
It effectively reduces the consumption of memory resources, improves the caching efficiency of offline device instructions, avoids frequent database scanning when time windows are scrolled, and improves system performance and response speed.
Smart Images

Figure CN119512627A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a method, device, electronic device and medium for caching instructions of an offline device. Background Art
[0002] IoT platforms face two major challenges when processing offline device commands: storage capacity and performance limitations, and command timeliness. 1. Storage capacity and performance limitations: IoT platforms need to manage many devices and data, and storage resources are limited. Excessive caching of commands will take up storage space, affecting platform performance and response speed. Storage resources need to be planned reasonably to avoid excessive system burden. 2. Command timeliness: Many control commands in IoT applications are time-sensitive and may lose their meaning beyond a specific time window. The platform needs to set a reasonable command lifetime (TTL) to ensure that commands are processed within the validity period.
[0003] In the prior art, the two typical solutions have their own problems:
[0004] 1. Delay queue-based solution: Use message queue services (such as Kafka and Pulsar) to implement delay queues and store unprocessed instructions. The process includes creating delay queues, queueing instructions, processing devices online, and clearing and marking expired instructions. However, there is a problem that specific device messages cannot be deleted directly, resulting in the issued instructions still occupying storage space until the TTL expires.
[0005] 2. Redis-based device command cache solution: Design a Redis list structure to store device commands, using the device ID as the key. The process includes creating a device-level command list, caching commands, processing device online, and clearing and marking expired commands. To delete a successfully issued command, you need to traverse the command list, with a time complexity of O(n); to clear expired commands, you need to scan them regularly, with a time complexity of O(m)×O(n). When the number of devices and cached commands is large, the performance is poor. Summary of the invention
[0006] The present invention proposes a method, apparatus, electronic device and medium for caching offline device instructions, aiming to solve one of the technical problems in the related art at least to a certain extent. The embodiments of the present invention can efficiently implement the caching of offline device instructions.
[0007] On the one hand, an embodiment of the present invention provides a method for caching offline device instructions, comprising:
[0008] The current time node is used as the target time node, and two consecutive time queues are initialized with the target time node as the starting point; the time queues include the first window queue and the second window queue in sequence; each time queue includes multiple time windows in a preset time range after the target time node;
[0009] Obtain the pending instructions and their expiration time of all offline devices, and insert the pending instructions into the corresponding time window in the timing queue based on the expiration time; wherein the pending instructions are associated with the device identification;
[0010] Obtain the running status of the offline device, and determine the offline device whose running status is online as the online device; based on the device identification of the online device, take out the corresponding to-be-processed instruction from the timing queue and send it to the online device;
[0011] In response to the time change, the next time node of the target time node is used as the target time node, and the time window corresponding to the previous time node of the target time node is cleaned up;
[0012] Return to the step of obtaining pending instructions and their expiration times of all offline devices until all time windows in the first window queue have completed the cleanup operation;
[0013] Based on the next preset time range of the second window queue, the time node corresponding to each time window of the first window queue is reloaded, the queue pointers of the first window queue and the second window queue are exchanged, and the step of obtaining the pending instructions and their expiration times of all offline devices is returned to continue the instruction caching of offline devices.
[0014] Optionally, initializing two consecutive timed queues with the target time node as the starting point includes the following steps:
[0015] According to two consecutive preset time ranges after the target time node, a first window queue and a second window queue are created in combination with a preset basic data structure corresponding to the time window;
[0016] Among them, all time windows in each timing queue correspond to each time node within a preset time range in sequence; an instruction list is set in the time window, and the instruction list is used to store one or more instructions to be processed.
[0017] Optionally, all time windows in each timing queue correspond to each time node within a preset time range, and a command list is set in the time window; based on the expiration time, inserting the to-be-processed command into the corresponding time window in the timing queue includes the following steps:
[0018] Determine the target time window according to the time node corresponding to the expiration time;
[0019] Insert the pending instruction into the instruction list in the target time window.
[0020] Optionally, the to-be-processed instructions are obtained from an instruction database; after the step of taking out the corresponding to-be-processed instructions from the timing queue and sending them to the online device, the method further comprises the following steps:
[0021] The instruction state of the corresponding instruction to be processed in the instruction database is marked as the first state.
[0022] Optionally, the to-be-processed instruction is obtained from an instruction database; and a time window corresponding to a previous time node of the target time node is cleaned up, including the following steps:
[0023] Dequeue the pending instructions in the time window corresponding to the previous time node of the target time node.
[0024] Optionally, the method further comprises the following steps:
[0025] The instruction state of the pending instruction for executing the dequeue operation in the instruction database is marked as the second state.
[0026] Optionally, the instruction to be processed is obtained from an instruction database; the method further comprises the following steps:
[0027] In response to the target object's cancel operation on the pending instruction, the pending instruction on which the cancel operation is performed is deleted from the timing queue, and the instruction state of the pending instruction on which the cancel operation is performed is marked as a third state in the instruction database.
[0028] On the other hand, an embodiment of the present invention provides a cache device for offline device instructions, including:
[0029] The first module is used to take the current time node as the target time node and initialize two consecutive time queues with the target time node as the starting point; the time queues include the first window queue and the second window queue in sequence; each time queue includes multiple time windows in a preset time range after the target time node;
[0030] The second module is used to obtain the pending instructions and their expiration time of all offline devices, and insert the pending instructions into the corresponding time window in the timing queue based on the expiration time; wherein the pending instructions are associated with the device identification;
[0031] The third module is used to obtain the operating status of the offline device, determine the offline device whose operating status is online as the online device; based on the device identification of the online device, take out the corresponding to-be-processed instruction from the timing queue and send it to the online device;
[0032] The fourth module is used to respond to the time change, take the next time node of the target time node as the target time node, and perform a cleaning operation on the time window corresponding to the previous time node of the target time node;
[0033] A fifth module is used to return to execute the second module until all time windows in the first window queue have completed the cleanup operation;
[0034] The sixth module is used to reload the time node corresponding to each time window of the first window queue based on the next preset time range of the second window queue, exchange the queue pointers of the first window queue and the second window queue, return to execute the second module, and continue to cache instructions of offline devices.
[0035] Optionally, the instruction to be processed is obtained from an instruction database; the device further includes:
[0036] A seventh module is used to mark the instruction state of the corresponding to-be-processed instruction in the instruction database as the first state;
[0037] Among them, the seventh module is executed after the third module.
[0038] Optionally, the instruction to be processed is obtained from an instruction database; the device further includes:
[0039] The eighth module is used to mark the instruction status of the pending instruction that performs the dequeue operation in the instruction database as the second status.
[0040] Optionally, the instruction to be processed is obtained from an instruction database; the device further includes:
[0041] The ninth module is used for deleting the pending instructions that perform the cancellation operation from the timing queue in response to the target object's cancellation operation on the pending instructions, and marking the instruction status of the pending instructions that perform the cancellation operation in the instruction database as the third status.
[0042] On the other hand, an embodiment of the present invention provides an electronic device, including: a processor and a memory; the memory is used to store programs; the processor executes the program to implement the above-mentioned offline device instruction caching method.
[0043] On the other hand, an embodiment of the present invention provides a computer storage medium, in which a program executable by a processor is stored. When the program executable by the processor is executed by the processor, it is used to implement the above-mentioned caching method of offline device instructions.
[0044] The embodiment of the present invention takes the current time node as the target time node and initializes two continuous timing queues with the target time node as the starting point; the timing queues sequentially include a first window queue and a second window queue; each timing queue includes multiple time windows of a preset time range after the target time node; the pending instructions of all offline devices and their expiration times are obtained, and based on the expiration time, the pending instructions are inserted into the corresponding time windows of the timing queue; wherein the pending instructions are associated with device identifiers; the operating status of the offline devices is obtained, and the offline devices whose operating status is online are determined as online devices; based on the device identifiers of the online devices, the corresponding pending instructions are taken out of the timing queue and sent to the online device. Send to the online device; in response to the time change, take the next time node of the target time node as the target time node, and perform a cleanup operation on the time window corresponding to the previous time node of the target time node; return to execute the step of obtaining the pending instructions and their expiration time of all offline devices until all time windows of the first window queue have completed the cleanup operation; reload the time node corresponding to each time window of the first window queue based on the next preset time range of the second window queue, exchange the queue pointers of the first window queue and the second window queue, return to execute the step of obtaining the pending instructions and their expiration time of all offline devices, and continue to cache the instructions of the offline device. The present invention includes the following beneficial effects: the present invention uses the mechanism of two timing queues, only loads the cached instructions within the two time windows, and only scans the cached instructions of the next time window when the queue is switched, which can avoid frequent database scanning when the time window is scrolled. The embodiment of the present invention can effectively reduce the consumption of memory resources and efficiently realize the caching of offline device instructions. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] The accompanying drawings are used to provide a further understanding of the technical solution of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the technical solution of the present invention and do not constitute a limitation on the technical solution of the present invention.
[0046] Figure 1 A schematic diagram of an implementation environment for caching offline device instructions provided by an embodiment of the present invention;
[0047] Figure 2 A schematic diagram of a flow chart of a method for caching instructions of an offline device provided in an embodiment of the present invention;
[0048] Figure 3 A schematic diagram of the expansion flow of instruction insertion provided by an embodiment of the present invention;
[0049] Figure 4 A schematic diagram of the overall flow of a method for caching offline device instructions provided by an embodiment of the present invention;
[0050] Figure 5A schematic diagram of a data structure of a timing queue provided by an embodiment of the present invention;
[0051] Figure 6 A schematic diagram of the principle flow of a new cache instruction enqueue provided by an embodiment of the present invention;
[0052] Figure 7 A schematic diagram of the principle flow of dequeuing a cache instruction provided by an embodiment of the present invention;
[0053] Figure 8 A schematic diagram of the principle of the time window switching process provided by an embodiment of the present invention;
[0054] Fig. 9 A schematic diagram of the structure of a cache device for offline device instructions provided by an embodiment of the present invention;
[0055] Fig.10 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0056] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0057] It should be noted that, although the functional modules are divided in the system schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the system or the order in the flowchart. The terms "first / S100", "second / S200", etc. in the specification, claims and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0058] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present invention. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0059] To facilitate the understanding of the technical solution of the present invention, the technical feature terms that may appear in the embodiments of the present invention are first explained:
[0060] Instruction status: The instruction status is an important node in the process of sending instructions to IoT devices, indicating the running status of an instruction, such as "stored", "sent", "expired", "canceled", "failed to send", etc.
[0061] TTL (Time to Live): indicates the maximum cache time of the command. For offline IoT devices, the platform will cache the commands issued to these devices for a period of time. Commands that exceed the maximum cache time will be cleared by the platform and will no longer be issued to the device. The command status will be updated to "expired".
[0062] Time window: The present invention uses a time window to represent a period of time, and the time window 10:00:00-10:59:59 represents the time within this period of time.
[0063] Time grid: the smallest unit of the timing queue in the present invention. One grid represents a time period of one second, and stores the instructions cached within this second.
[0064] Cached instructions within the time window: Indicates that the expiration time of the device instructions cached in the system is within the time window.
[0065] Time window sliding: If we regard time as a one-dimensional straight line, the time window will continue to move forward on the timeline. The process of continuously reading data at new time points can be called the sliding of the time window.
[0066] It is understandable that the caching method of offline device instructions provided in the embodiment of the present invention can be applied to any computer device with data processing and computing capabilities, and this computer device can be various types of terminals or servers. When the computer device in the embodiment is a server, the server is an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. Optionally, the terminal is a smart phone, a tablet computer, a laptop computer, a desktop computer, etc., but is not limited to this.
[0067] like Figure 1 FIG. 1 is a schematic diagram of an implementation environment provided by an embodiment of the present invention. Figure 1 The implementation environment includes at least one terminal 102 and a server 101. The terminal 102 and the server 101 can be connected to a network wirelessly or wired to complete data transmission and exchange.
[0068] Server 101 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), as well as big data and artificial intelligence platforms.
[0069] In addition, the server 101 can also be a node server in the blockchain network. Blockchain is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, and encryption algorithm.
[0070] The terminal 102 may be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited thereto. The terminal 102 and the server 101 may be directly or indirectly connected via wired or wireless communication, which is not limited in the embodiment of the present invention.
[0071] Based on the example Figure 1 In the implementation environment shown, an embodiment of the present invention provides a method for caching offline device instructions. The following is an example of applying the method for caching offline device instructions in the terminal 102. It can be understood that the method for caching offline device instructions can also be applied to the server 101.
[0072] Reference Figure 2 , Figure 2 The flowchart of the method for caching offline device instructions applied to a terminal provided in an embodiment of the present invention is provided. The execution subject of the method for caching offline device instructions can be any of the aforementioned computer devices (including a server or a terminal). Figure 2 , the method comprises the following steps:
[0073] S100, taking the current time node as the target time node, and initializing two consecutive timing queues with the target time node as the starting point;
[0074] The timing queue includes a first window queue and a second window queue in sequence; each timing queue includes multiple time windows within a preset time range after a target time node;
[0075] It should be noted that, in some embodiments, initializing two consecutive timing queues with the target time node as the starting point may include the following steps: creating a first window queue and a second window queue based on two consecutive preset time ranges after the target time node and combining the preset basic data structure corresponding to the time window; wherein all time windows in each timing queue correspond sequentially to each time node within the preset time range; an instruction list is set in the time window, and the instruction list is used to store one or more instructions to be processed.
[0076] For example, in some specific implementations, the present invention first creates a timed queue: initialize two queues, representing the current and next time windows respectively. Fill the two queues according to the current time to ensure that each grid corresponds to an instruction within the next second. In some application scenarios, the present invention can create a timed queue as follows:
[0077] Data structure selection: Use HashMap <Long,HashSet <instruction>As the basic data structure, the Long type represents the timestamp (accurate to the second), and the HashSet <instruction>Stores a list of instructions to be processed within the same second. Using HashMap as the basic data structure of the queue takes into account the scalability of the queue capacity, and can flexibly adjust the time window size, that is, the capacity of the Map. You can also use a fixed-length array instead of HashMap, but you need to add records about the start timestamps of the two queues. To access the grid at each moment, you need to use the time offset (current time - queue start time) as the array index to access.
[0078] Queue initialization: When the system starts, two queues are created, one for the current time window and the other for the next time window. Each queue contains a series of grids, each of which corresponds to a list of instructions within the next second. The instruction data within the two time windows is loaded from the database, and the instruction ID is inserted into the Set of cached instructions stored in the grid.
[0079] The timed queue built based on the time window can ensure that only the instruction data within the time window range is loaded, without loading all the cached instruction data.
[0080] S200, obtaining the pending instructions and their expiration times of all offline devices, and inserting the pending instructions into the corresponding time window in the timing queue based on the expiration time;
[0081] The pending instruction is associated with a device identifier;
[0082] It should be noted that all time windows in each timing queue correspond to each time node within a preset time range, and a command list is set in the time window; in some embodiments, such as Figure 3 As shown, based on the expiration time, inserting the pending instructions into the corresponding time window in the timing queue can include the following steps: S201, determining the target time window according to the time node corresponding to the expiration time; S202, inserting the pending instructions into the instruction list in the target time window.
[0083] For example, in some specific implementations, the present invention performs command queueing: when receiving a command for an offline device, check whether its expiration time falls within the time range covered by the current dual queue. If so, insert the command into the list of the corresponding "second" time. In some application scenarios, the command queueing of the present invention can be implemented as follows:
[0084] Timestamp calculation: When the command service receives a command sent to an offline device, it calculates its cache expiration timestamp to determine whether it is within the time range of the current dual queue. If it is within the time window, it needs to be queued. Commands that are not within the time range can be directly stored and wait for the window to roll over.
[0085] Instruction insertion: If the expiration time of the instruction is within the time window covered by the two queues, the instruction is inserted into the Set of the corresponding time grid according to the expiration timestamp.
[0086] This instruction enqueue method can ensure that newly added cache instructions can be quickly added to the corresponding time grid without the need to perform instruction cache expiration time sorting operations with high time complexity.
[0087] S300, obtaining the operating status of the offline device, determining the offline device whose operating status is online as the online device; based on the device identification of the online device, taking out the corresponding to-be-processed instruction from the timing queue and sending it to the online device;
[0088] It should be noted that the pending instructions are obtained from the instruction database; in some optional embodiments, after the step of taking out the corresponding pending instructions from the timing queue and sending them to the online device, the method may also include the following steps: marking the instruction status of the corresponding pending instructions in the instruction database as the first status.
[0089] For example, in some specific implementations, the present invention is directed to device online processing: after the device is back online, all unexpired instructions are immediately extracted from the queue and sent to the device, and the instruction status is updated to "issued" (a case of the first state), and removed from the queue. In some application scenarios, the device online processing of the present invention can be implemented as follows:
[0090] Status update and record deletion: After the device is online, immediately take out the unexpired instructions of the device from the device session and send them to the device. For the successfully sent instructions, the corresponding records need to be removed from the queue, and the instruction status in the database is updated to "successful" (another case of the first status).
[0091] S400, in response to the time change, taking the next time node of the target time node as the target time node, and performing a clearing operation on the time window corresponding to the previous time node of the target time node;
[0092] It should be noted that the pending instructions are obtained from the instruction database; in some embodiments, the cleanup operation on the time window corresponding to the previous time node of the target time node may include the following steps: dequeueing the pending instructions in the time window corresponding to the previous time node of the target time node.
[0093] In some optional embodiments, the method may further include the following step: marking the instruction status of the pending instruction that performs the dequeue operation in the instruction database as the second status.
[0094] For example, in some specific implementations, the present invention can implement device instruction expiration cleaning and marking: check the instructions in the current time window queue every second, mark the status of the unissued and expired instructions as "expired" (i.e., the second status), and asynchronously update the database. In some application scenarios, the device instruction expiration cleaning and marking of the present invention can be implemented as follows:
[0095] Instruction dequeue: The system periodically takes out the instruction Set cached in the time grid of this second from the queue every second and performs the dequeue operation.
[0096] Status update: Based on the cached expired instruction Set retrieved, use an asynchronous thread to update the instruction status of the corresponding instruction in the database to "expired".
[0097] The time complexity of dequeuing cache expired instructions from the timing queue is O(1), which has a significant performance advantage over the above two technical solutions.
[0098] In some optional embodiments, the method may further include the following steps: in response to the target object's cancellation operation on the pending instruction, deleting the pending instruction that performs the cancellation operation from the timing queue, and marking the instruction status of the pending instruction that performs the cancellation operation in the instruction database as a third state.
[0099] Exemplarily, in some specific implementations, the present invention can also implement processing of canceled instructions: before a command is issued to a device, it can be supported to cancel it. If the cache expiration time of the command is within the time window of two timing queues, the command can be deleted from the timing queue. In some application scenarios, the present invention can implement processing of canceled instructions as follows:
[0100] Delete the canceled instruction from the queue: According to the cache expiration time stored in the instruction data. If the instruction cache expiration time is within the current time window, find the corresponding time grid according to the expiration time, and then remove the corresponding instruction record in the Set according to the instruction ID. If it is not within the time window, directly update the status of the instruction in the database to "cancelled" (i.e. the third state).
[0101] S500, returning to the step of obtaining the pending instructions of all offline devices and their expiration times, until all time windows in the first window queue have completed the cleanup operation;
[0102] S600, reload the time node corresponding to each time window of the first window queue based on the next preset time range of the second window queue, exchange the queue pointers of the first window queue and the second window queue, return to execute the step of obtaining the pending instructions and their expiration times of all offline devices, and continue to cache the instructions of the offline devices.
[0103] For example, in some specific implementations, the present invention can perform window switching: when the first window period ends, the current window queue is cleared, the next time window queue is upgraded to the current window, and the above process is repeated. In some application scenarios, the window switching of the present invention can be implemented as follows:
[0104] Window switching: When the first time window ends, the pointers to the two queues are swapped. The next time window queue is upgraded to the current window. At the same time, the next time window is pointed to the "current window queue" that has been executed, all data in the queue is cleared, and the instruction data within the next time window range is loaded from the database, and the above process is repeated.
[0105] Loop processing: The system continuously monitors the device status and instruction status, and cyclically executes operations such as instruction queuing, device online processing, and expired instruction cleaning and marking to ensure the continuity and efficiency of instruction processing.
[0106] In order to explain the principle of the technical solution of the present invention in detail, the overall process of the present invention is described below in combination with some specific embodiments. It is easy to understand that the following is an explanation of the technical principle of the present invention and cannot be regarded as a limitation of the present invention.
[0107] First of all, it should be noted that the connection and data interaction between IoT devices and IoT platforms are the core of the IoT system. IoT devices usually include sensors, actuators and smart terminals, which are connected to the IoT platform through various communication protocols (such as Wi-Fi, Bluetooth, LoRa, NB-IoT, etc.). The interaction between devices and the platform includes data uplink and data downlink. IoT devices transmit the collected data to the IoT platform through the uplink channel; data downlink refers to the IoT platform sending instructions or configuration updates to the device.
[0108] IoT devices may not be able to stay online or maintain long-term connections with the platform due to battery life limitations, insufficient network coverage, network congestion, device failures, security mechanisms, and protocol limitations. These factors together hinder real-time communication between devices and platforms, resulting in the inability of devices to receive and execute commands issued by the platform in a timely manner, affecting the efficiency and accuracy of remote control. For example, in order to extend battery life, devices will periodically enter low-power mode, during which time they are offline and unable to receive commands; when network signals are weak or network resources are tight, devices may frequently drop offline, which also affects the real-time issuance of commands.
[0109] In order to deal with the offline state of IoT devices due to various reasons, IoT platforms usually implement a command cache strategy. When the platform detects that the target device is offline, it does not immediately give up sending commands, but stores these commands in the cache. Once the device is back online, the platform will immediately retrieve these pending commands from the cache and quickly send them to the device, ensuring that the commands are ultimately delivered even when the device is temporarily offline, thereby improving system reliability and user experience.
[0110] Although IoT platforms use caching mechanisms to handle commands from offline devices, they cannot store these commands indefinitely for two key reasons:
[0111] 1. Storage capacity and performance limitations: The IoT platform needs to manage a large number of devices and data, and its storage resources are not unlimited. Excessive instruction cache will take up valuable storage space and affect the overall performance and response speed of the platform. Therefore, the platform must reasonably plan storage resources to avoid excessive system burden caused by caching too many instructions.
[0112] 2. Instruction timeliness: Many control instructions in IoT applications are time-sensitive, that is, they are valid within a specific time window. Beyond this time window, the instruction may lose its meaning or become invalid. Therefore, the platform needs to set a reasonable instruction TTL to ensure that the instruction is processed within the validity period. Instructions that exceed the TTL will be automatically cleared to avoid resource waste.
[0113] There are two typical technical implementations in the existing technology:
[0114] 1. A delayed queue-based solution to control the device instruction cache TTL expiration cleanup mechanism. The delayed queue is a special data structure that can be implemented using existing message queue services, such as Kafka, Pulsar, etc. It allows messages to be consumed after a specified time point, which is very suitable for processing tasks that need to be executed at a certain point in the future, such as instructions for offline devices. The specific process is as follows:
[0115] (1) Creating a delay queue: In the IoT platform, a delay queue is created for each device or device group to store unprocessed instructions for the device.
[0116] (2) Command queuing: When a command is received for an offline device, the command service writes it into the database (the command status is "stored"), stores the message in the device's session information, sends it to the corresponding delay queue, and sets a TTL value to indicate the validity period of the command.
[0117] (3) Device online processing: When an offline device comes back online, the platform should immediately check the session of the device, send all non-timed-out commands to the device for processing, and store a command message and its status as "issued".
[0118] (4) Device command expiration cleanup and marking: Messages in the delay queue will still notify the command service to update the command status after the TTL expires. If the command status in the database is "issued", no processing will be done; if the command status is "stored", the command status will be updated to "expired".
[0119] Since the message queue middleware generally cannot directly delete a specific device message, after the cached instructions in the device session are issued, the delayed messages in the message queue will not be directly deleted. The problems caused are:
[0120] (1) Actively canceled instructions cannot be deleted from the message queue.
[0121] (2) The cached command has been successfully sent and cannot be cleared from the message queue.
[0122] (3) All cached messages are accumulated in the message queue. When the message volume is large, it will cause a certain amount of pressure on the message queue.
[0123] Therefore, these issued instructions will still occupy storage space in the message cache queue until the TTL expires and the cached instruction message is consumed.
[0124] 2. A solution for device command caching based on Redis is to design a list data type to store cached device commands, using the device ID as the key of the Redis key-value pair, and the value is the command list corresponding to the device ID. The specific process of processing cached commands is as follows:
[0125] (4) Create a device-level command list: In the IoT platform, create a Redis list structure for each device or device group to store unprocessed commands for the device.
[0126] (5) Cache instructions: When receiving an instruction for an offline device, the instruction service writes it to the database (the instruction status is "stored") and stores the message in the device's session information and in Redis. Since Redis's expiration policy can only set the TTL value of a key, it is not possible to set the TTL value of a specific instruction in the list. Therefore, only the device's cache time and the instruction ID can be stored in the list as values.
[0127] (6) Device online processing: When an offline device comes back online, the platform should immediately check the session of the device, send all non-timed commands to the device for processing, and store a command message and its status as "issued". Traverse the cached command list of the device in Redis and delete the issued commands.
[0128] (7) Expired device command cleanup and marking: Expired commands stored in Redis need to be scanned by a scheduled task in the command queue of each device cache. If the expiration time is less than the current time, the command is removed from the queue and the command service is notified to update the command status to "expired".
[0129] In this solution, to delete successfully issued instructions from the cache list, it is necessary to traverse the instruction list, with a time complexity of O(n), where n is the number of instructions cached by the device; to clean up expired instructions in the platform, it is necessary to periodically scan the cache instruction queue of each device, with a time complexity of O(m)×O(n), where m is the number of devices and n is the number of cached instructions. When the number of devices and the number of cached instructions are large, the performance is poor.
[0130] In summary, when processing instructions from offline devices, the IoT platform needs to provide necessary instruction caching capabilities, consider storage capacity, performance limitations, and instruction timeliness, and provide high-performance instruction caching strategies and TTL mechanisms.
[0131] In view of this, the present invention designs two timed task queues, and designs the precision of instruction expiration time to be 1 second (which can be adjusted adaptively according to actual needs), which are divided into two queues, each queue contains a specified time grid, and each grid time unit is 1s (which can be adjusted adaptively according to actual needs), pointing to the instruction cache list that expires in this second. The queue takes out the instructions of the whole second every second for unified operation. Figure 4 As shown, the main process steps of the present invention are as follows:
[0132] (1) Create a timed queue: Initialize two queues, one for the current time window and the other for the next time window. Fill the two queues according to the current time, ensuring that each grid corresponds to an instruction within the next second.
[0133] (2) Enqueueing commands: When receiving a command for an offline device, check whether its expiration time falls within the time range covered by the current dual queue. If so, insert the command into the list at the corresponding "second" time.
[0134] (3) Device online processing: After the device comes back online, all unexpired commands are immediately extracted from the queue and sent to the device. At the same time, the command status is updated to "issued" and removed from the queue.
[0135] (4) Expired device command cleanup and marking: Check the commands in the current time window queue every second. For commands that have not been issued and have expired, mark their status as "expired" and update the database asynchronously.
[0136] (5) Processing of canceled commands: A command can be canceled before it is sent to the device. If the cache expiration time of the command is within the time window of the two timing queues, the command can be deleted from the timing queue.
[0137] (6) Window switching: When the first window period ends, the current window queue is cleared, the next time window queue is upgraded to the current window, and the above process is repeated.
[0138] The present invention can solve the following technical problems:
[0139] (1) Expired instruction cache occupies storage space: The technical solution based on the delay queue requires all cached messages to be accumulated in the message queue. There is no guarantee that the cached instructions will be deleted immediately after they are issued. They still need to continue to occupy storage space until the instruction reaches the expiration time, and the delayed message can be processed by the instruction service.
[0140] (2) Poor performance when the number of devices is large: The Redis-based solution has a large time complexity. When the number of devices is large, the scanning task will time out.
[0141] The technical effects that can be achieved by the present invention are as follows: (1) High-precision time management: Through the instruction expiration time management accurate to seconds, the timeliness and accuracy of the instructions are ensured. (2) Dynamic window switching: The dual queue mechanism supports dynamic window switching to ensure the continuity and flexibility of instruction processing. (3) Efficient resource utilization: The HashMap data structure is used to achieve fast retrieval and efficient storage of instructions; only the instruction data within the time window is loaded to reduce the consumption of memory resources.
[0142] In some preferred embodiments, Figure 4 As shown, the process logic of the present invention can be specifically implemented as follows:
[0143] 1. Create a timed queue:
[0144] Data structure selection: Use HashMap <Long,HashSet <instruction>As the basic data structure, the Long type represents the timestamp (accurate to the second), and the HashSet <instruction>Stores a list of instructions to be processed within the same second. Using HashMap as the basic data structure of the queue takes into account the scalability of the queue capacity, and can flexibly adjust the time window size, that is, the capacity of the Map. You can also use a fixed-length array instead of HashMap, but you need to add records about the start timestamps of the two queues. To access the grid at each moment, you need to use the time offset (current time - queue start time) as the array index to access.
[0145] Queue initialization: When the system starts, two queues are created, one for the current time window and the other for the next time window. Each queue contains a series of grids, each of which corresponds to a list of instructions within the next second. The instruction data within the two time windows is loaded from the database, and the instruction ID is inserted into the Set of cached instructions stored in the grid.
[0146] The timed queue built based on the time window can ensure that only the instruction data within the time window range is loaded, without loading all the cached instruction data.
[0147] 2. Instruction entry:
[0148] Timestamp calculation: When the command service receives a command sent to an offline device, it calculates its cache expiration timestamp to determine whether it is within the time range of the current dual queue. If it is within the time window, it needs to be queued. Commands that are not within the time range can be directly stored and wait for the window to roll over.
[0149] Instruction insertion: If the expiration time of the instruction is within the time window covered by the two queues, the instruction is inserted into the Set of the corresponding time grid according to the expiration timestamp.
[0150] This instruction enqueue method can ensure that newly added cache instructions can be quickly added to the corresponding time grid without the need to perform instruction cache expiration time sorting operations with high time complexity.
[0151] 3. Equipment online processing:
[0152] Status update and record deletion: After the device is online, immediately take out the unexpired instructions of the device from the device session and send them to the device. For successfully sent instructions, the corresponding records need to be removed from the queue, and the instruction status in the database is updated to "successful".
[0153] Delete successful instructions from the queue: According to the cache expiration time stored in the instruction data. If the instruction cache expiration time is within the current time window, find the corresponding time grid according to the expiration time, and then remove the corresponding instruction record in the Set according to the instruction ID. If it is not within the time window, directly update the status of the instruction in the database to "sent".
[0154] The time complexity of the above operation of removing instructions from the timing queue is O(1), and there is no need to fully scan the entire queue.
[0155] 4. Expired instruction cleaning and marking:
[0156] Instruction dequeue: The system periodically takes out the instruction Set cached in the time grid of this second from the queue every second and performs the dequeue operation.
[0157] Status update: Based on the cached expired instruction Set retrieved, use an asynchronous thread to update the instruction status of the corresponding instruction in the database to "expired".
[0158] The time complexity of dequeuing cache expired instructions from the timing queue is O(1), which has a significant performance advantage over the above two technical solutions.
[0159] 5. Processing of cancelled instructions:
[0160] Delete the canceled instructions from the queue: According to the cache expiration time stored in the instruction data. If the instruction cache expiration time is within the current time window, find the corresponding time grid according to the expiration time, and then remove the corresponding instruction record in the Set according to the instruction ID. If it is not within the time window, directly update the status of the instruction in the database to "cancelled".
[0161] 6. Window switching and cycling:
[0162] Window switching: When the first time window ends, the pointers to the two queues are swapped. The next time window queue is upgraded to the current window. At the same time, the next time window is pointed to the "current window queue" that has been executed, all data in the queue is cleared, and the instruction data within the next time window range is loaded from the database, and the above process is repeated.
[0163] Loop processing: The system continuously monitors the device status and instruction status, and cyclically executes operations such as instruction queuing, device online processing, and expired instruction cleaning and marking to ensure the continuity and efficiency of instruction processing.
[0164] Exemplarily, the process steps of the present invention are described in detail below with reference to data examples of specific application scenarios. For example, when the device is offline at 10:00:05, the platform receives an instruction with an expiration time of 10:00:15, and the instruction is inserted into the 15th second grid of the second queue. The device goes online at 10:00:15, and the system immediately sends all non-expired instructions and updates the status. Subsequently, the system checks the current queue every second, marks and clears expired instructions. When 10:00:59 arrives, the first queue is cleared, and the second queue becomes the new current queue, continuing to perform instruction management and expiration processing. An example of a specific processing flow is as follows:
[0165] 1. Create a timed queue:
[0166] like Figure 5 As shown in the figure, assuming that the current time is 10:00:00, the system initializes two 1-hour window queues, covering the two time windows of 10:00:00-10:59:59 and 11:00:00-11:59:59 respectively. They correspond to the current time window and the next time window respectively. Each queue contains 3600 grids, each grid key value is a timestamp, and an initial size of 1000 HashSet is assigned, corresponding to the instruction list within the next second. If the queue is implemented using a data structure, the array subscript is the offset in seconds between the expiration time and the queue start time.
[0167] 2. Instruction entry:
[0168] by Figure 5 Take the data structure of the timing queue shown as an example, Figure 6 As shown in the figure, when the device is offline at 10:05:00, the platform receives a command with an expiration time of 11:05:00, and the command will be inserted into the 300th second grid of the second queue. The cached commands with expiration times outside the time windows corresponding to the two timing queues are only processed into the warehouse.
[0169] 3. Equipment online processing:
[0170] by Figure 5 Take the data structure of the timing queue shown as an example, Figure 7 As shown in the figure, assuming that the device corresponding to the instruction with an expiration time of 11:05:00 comes online at 10:10:15, the system immediately sends all non-expired instructions and updates the instruction status in the database to "successful". According to the instruction expiration time 11:05:00, the successful instruction is deleted from the queue with a time window of 11:00:00-11:59:59. Among them, the cached instructions with an expiration time outside the time window corresponding to the two timing queues only exist in the database, so only the status of the corresponding instruction in the database is directly updated.
[0171] 4. Expired instruction cleaning and marking:
[0172] The system periodically takes out the cached instruction Set in the time grid of this second from the queue every second, performs the dequeue operation, and updates the status of the instruction in the database to "expired". For example, when the time reaches 10:15:00, the instruction Set stored in the time grid is taken out from the current time queue and handed over to the asynchronous thread for execution, and the current time grid is removed from the Map. In the asynchronous thread, according to the instructions in the Set, the "expired" status is updated to the database. The system waits for the next second to start and repeats the above operation.
[0173] 5. Processing of cancelled instructions:
[0174] Suppose there is a command that will expire at 11:10:59. After judging that the cache expiration time of this command is within the next time window, the corresponding time grid is found according to the cache expiration time 11:10:59 of the command, and then the corresponding command record in Set is removed according to the command ID. If it is not within the time window, the status of the command is directly updated in the database to "cancelled".
[0175] 6. Window switching and cycling:
[0176] like Figure 8 As shown, when 10:59:59 arrives, the pointers of the two queues are exchanged, the second queue becomes the new current queue, and continues to perform instruction management and expiration processing. The first queue is cleared and the instruction data of the next time window is loaded.
[0177] In summary, the present invention proposes an instruction management scheme based on dual timed task queues, which can realize the caching of offline device instructions on the Internet of Things platform, aiming to solve the problem of instruction cache occupying storage space and performance bottleneck in a large-scale device environment. The core of the scheme of the present invention is to design two high-precision (1 second) timing queues for storing instructions that are about to expire. Each queue is composed of a series of grids with a time unit of 1 second, and the instructions are stored in the form of a Map, where the key is a timestamp and the value is a cached instruction list. The main process includes: initializing the queue and filling the instructions within the current time range, receiving and classifying and storing new instructions in real time, quickly issuing non-expired instructions when the device is online, regularly cleaning up expired instructions, and supporting instruction cancellation functions. Through the dynamic window switching mechanism, efficient management of instructions and rational use of resources are achieved, solving the problems of storage waste and poor performance in traditional delay queues and Redis solutions, and improving the timeliness, accuracy and overall system performance of instruction processing.
[0178] Compared with the prior art, the present invention includes at least the following innovative features and beneficial effects:
[0179] 1. Dual timing queues ensure the continuity of processing cache instructions:
[0180] The present invention uses a mechanism of two timing queues, and only loads cached instructions within the two time windows by creating a current time window queue and a next time window queue. Frequent database scanning when the time window is scrolled can be avoided. Only when the queue is switched, the cached instructions of the next time window are scanned, reducing the number of IO times. The system supports dynamic window switching. When the first time window ends, the next time window queue is automatically upgraded to the current window to ensure the continuity of instruction processing.
[0181] 2. The time window and time grid mechanism ensures high-precision instruction expiration time management:
[0182] The introduction of the concepts of time windows and time grids enables high-precision management of instruction expiration time. Each queue consists of a series of grids with a time unit of 1 second, that is, the accuracy of the instruction expiration time is set to 1 second, and instructions are assigned to the corresponding grids through precise timestamp matching. This high-precision time management method avoids instruction processing delays or resource waste caused by time ambiguity in traditional cache strategies.
[0183] 3. Dynamic deletion of cache instruction status:
[0184] The system is designed to support the deletion of cached instructions that have been queued, and the underlying data structure already supports the rapid retrieval and restoration of instructions that have expired at a specific time. For cached instructions that have been successfully issued or canceled, they can be removed from the queue at a very low cost to avoid being repeatedly processed by the system.
[0185] 4. Data structure design with high performance and low resource usage:
[0186] The HashMap data structure is used to store instructions, where the key is the timestamp and the value is the instruction list. This design not only supports fast retrieval and efficient storage of instructions, but also reduces memory usage and improves system resource utilization.
[0187] On the other hand, Fig. 9 As shown, an embodiment of the present invention provides a cache device 900 for offline device instructions, which may include:
[0188] The first module 901 is used to take the current time node as the target time node and initialize two consecutive timing queues with the target time node as the starting point; the timing queues include a first window queue and a second window queue in sequence; each timing queue includes multiple time windows in a preset time range after the target time node;
[0189] The second module 902 is used to obtain the pending instructions and their expiration time of all offline devices, and insert the pending instructions into the corresponding time window of the timing queue based on the expiration time; wherein the pending instructions are associated with the device identification;
[0190] The third module 903 is used to obtain the running status of the offline device, determine the offline device whose running status is online as the online device; based on the device identification of the online device, take out the corresponding to-be-processed instruction from the timing queue and send it to the online device;
[0191] The fourth module 904 is used to respond to the time change, take the next time node of the target time node as the target time node, and perform a cleaning operation on the time window corresponding to the previous time node of the target time node;
[0192] The fifth module 905 is used to return to execute the second module until all time windows in the first window queue have completed the cleanup operation;
[0193] The sixth module 906 is used to reload the time node corresponding to each time window of the first window queue based on the next preset time range of the second window queue, exchange the queue pointers of the first window queue and the second window queue, return to execute the second module, and continue to cache instructions of the offline device.
[0194] In some embodiments, the instruction to be processed is obtained from an instruction database; the apparatus may further include:
[0195] A seventh module is used to mark the instruction state of the corresponding to-be-processed instruction in the instruction database as the first state;
[0196] Among them, the seventh module is executed after the third module.
[0197] In some embodiments, the instruction to be processed is obtained from an instruction database; the apparatus may further include:
[0198] The eighth module is used to mark the instruction status of the pending instruction that performs the dequeue operation in the instruction database as the second status.
[0199] In some embodiments, the instruction to be processed is obtained from an instruction database; the apparatus may further include:
[0200] The ninth module is used for deleting the pending instructions that perform the cancellation operation from the timing queue in response to the target object's cancellation operation on the pending instructions, and marking the instruction status of the pending instructions that perform the cancellation operation in the instruction database as the third status.
[0201] The contents of the method embodiments of the present invention are all applicable to the device embodiments. The functions specifically implemented by the device embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0202] On the other hand, an embodiment of the present invention further provides an electronic device, the electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the above sensitive information method when executing the computer program. The electronic device can be any intelligent terminal including a tablet computer, a car computer, etc.
[0203] It can be understood that the contents of the above method embodiments are all applicable to the present device embodiments, the functions specifically implemented by the present device embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0204] like Fig.10 As shown, Fig.10 A specific example of the hardware structure of an electronic device 1000 according to an embodiment is shown. The electronic device 1000 includes:
[0205] The processor 1001 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present invention.
[0206] The memory 1002 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 1002 can store an operating system and other application programs. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 1002, and the processor 1001 calls and executes the network node population optimization method of the embodiment of the present invention;
[0207] Input / output interface 1003, used to implement information input and output;
[0208] The communication interface 1004 is used to realize the communication interaction between the device and other devices. The communication can be realized through a wired manner (such as USB, network cable, etc.) or a wireless manner (such as mobile network, WIFI, Bluetooth, etc.);
[0209] A bus 1005 , which transmits information between various components of the device (e.g., the processor 1001 , the memory 1002 , the input / output interface 1003 , and the communication interface 1004 );
[0210] The processor 1001 , the memory 1002 , the input / output interface 1003 and the communication interface 1004 are connected to each other in communication within the device via the bus 1005 .
[0211] The electronic device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0212] The contents of the method embodiments of the present invention are all applicable to the electronic device embodiments. The functions specifically implemented by the electronic device embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0213] Another aspect of an embodiment of the present invention further provides a computer-readable storage medium, the storage medium stores a program, and the program is executed by a processor to implement the above method.
[0214] It should be noted that the computer-readable medium shown in the embodiment of the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (Compact Disc Read to Only Memory, CD to ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer readable signal media may also be any computer readable medium other than computer readable storage media, which may send, propagate, or transmit programs for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0215] The contents of the method embodiments of the present invention are all applicable to the computer-readable storage medium embodiments. The functions specifically implemented by the computer-readable storage medium embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0216] The embodiment of the present invention also discloses a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. A processor of a computer device can read the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the above method.
[0217] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0218] It should be noted that, although several modules of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to an embodiment of the present invention, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into being embodied by multiple modules or units.
[0219] Through the description of the above implementation, it is easy for those skilled in the art to understand that the example implementation described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation of the present invention can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD to ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a touch terminal, or a network device, etc.) to execute the method according to the implementation of the present invention.
[0220] In some selectable embodiments, the function / operation mentioned in the block diagram may not occur in the order mentioned in the operation diagram. For example, depending on the function / operation involved, the two boxes shown in succession can actually be executed substantially simultaneously or the boxes can sometimes be executed in reverse order. In addition, the embodiment presented and described in the flow chart of the present invention is provided by way of example, for the purpose of providing a more comprehensive understanding of technology. The disclosed method is not limited to the operation and logic flow presented herein. Selectable embodiments are expected, wherein the order of various operations is changed and the sub-operation of a part for which is described as a larger operation is performed independently.
[0221] In addition, although the present invention is described in the context of functional modules, it should be understood that, unless otherwise specified, one or more of the functions and / or features can be integrated into a single physical device and / or software module, or one or more functions and / or features can be implemented in a separate physical device or software module. It is also understood that a detailed discussion of the actual implementation of each module is unnecessary for understanding the present invention. More specifically, in view of the properties, functions and internal relationships of the various functional modules in the device disclosed herein, the actual implementation of the module will be understood within the conventional skills of the engineer. Therefore, those skilled in the art can implement the present invention set forth in the claims without excessive experimentation using ordinary techniques. It is also understood that the specific concepts disclosed are merely illustrative and are not intended to limit the scope of the present invention, which is determined by the full scope of the appended claims and their equivalents.
[0222] If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods of each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0223] The logic and / or steps represented in the flowchart or otherwise described herein, for example, may be considered as an ordered list of executable instructions for implementing logical functions, and may be embodied in any computer-readable medium for use by an instruction execution device, apparatus or device (such as a computer-based device, a device including a processor, or other device that can fetch instructions from an instruction execution device, apparatus or device and execute the instructions), or in conjunction with such instruction execution device, apparatus or device. For purposes of this specification, "computer-readable medium" may be any device that can contain, store, communicate, propagate or transmit a program for use by or in conjunction with such instruction execution device, apparatus or device.
[0224] More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection with one or more wires (electronic device), a portable computer disk case (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), a fiber optic device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be a paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, deciphering or, if necessary, processing in another suitable manner, and then stored in a computer memory.
[0225] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, a plurality of steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution device. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0226] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner.
[0227] Although the embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the claims and their equivalents.
[0228] The above is a specific description of the preferred implementation of the present invention, but the present invention is not limited to the embodiments. Those skilled in the art can make various equivalent modifications or substitutions without violating the spirit of the present invention. These equivalent modifications or substitutions are all included in the scope defined by the claims of the present invention.< / instruction> < / instruction> < / instruction> < / instruction>
Claims
1. A method for caching instructions of an offline device, characterized in that: The following steps are involved: The current time node is used as the target time node, and two consecutive timing queues are initialized with the target time node as the starting point; the timing queues include a first window queue and a second window queue in sequence; each of the timing queues includes multiple time windows in a preset time range after the target time node; Obtaining pending instructions and their expiration times of all offline devices, and inserting the pending instructions into the corresponding time window in the timing queue based on the expiration time; wherein the pending instructions are associated with a device identifier; Acquire the running status of the offline device, and determine the offline device whose running status is online as an online device; based on the device identification of the online device, take out the corresponding to-be-processed instruction from the timing queue and send it to the online device; In response to the time change, taking the next time node of the target time node as the target time node, and performing a clearing operation on the time window corresponding to the previous time node of the target time node; Return to the step of obtaining the pending instructions of all offline devices and their expiration times until all the time windows of the first window queue have completed the cleanup operation; Reload the time node corresponding to each time window of the first window queue based on the next preset time range of the second window queue, exchange the queue pointers of the first window queue and the second window queue, return to execute the step of obtaining the pending instructions and their expiration times of all offline devices, and continue to cache the instructions of the offline devices.
2. The method for caching offline device instructions according to claim 1, characterized in that: The initialization of two consecutive timing queues with the target time node as the starting point includes the following steps: The first window queue and the second window queue are created according to two consecutive preset time ranges after the target time node and in combination with a preset basic data structure corresponding to the time window; Among them, all the time windows in each of the timing queues correspond sequentially to each time node within the preset time range; an instruction list is set in the time window, and the instruction list is used to store one or more instructions to be processed.
3. The method for caching offline device instructions according to claim 1, characterized in that: All the time windows in each of the timing queues correspond sequentially to each time node within the preset time range, and a command list is set in the time window; inserting the to-be-processed command into the corresponding time window in the timing queue based on the expiration time comprises the following steps: Determine a target time window according to the time node corresponding to the expiration time; Insert the pending instruction into the instruction list in the target time window.
4. The method for caching offline device instructions according to claim 1, characterized in that: The pending instructions are obtained from an instruction database; after the step of taking out the corresponding pending instructions from the timing queue and sending them to the online device, the method further comprises the following steps: The instruction state of the corresponding instruction to be processed in the instruction database is marked as the first state.
5. The method for caching offline device instructions according to claim 1, characterized in that: The to-be-processed instruction is obtained from an instruction database; the clearing operation on the time window corresponding to the previous time node of the target time node comprises the following steps: A dequeue operation is performed on the pending instructions in the time window corresponding to the previous time node of the target time node.
6. The method for caching offline device instructions according to claim 5, characterized in that: The method further comprises the following steps: The instruction state of the pending instruction for executing the dequeue operation in the instruction database is marked as a second state.
7. The method for caching offline device instructions according to claim 1, characterized in that: The instructions to be processed are obtained from an instruction database; the method further comprises the following steps: In response to the target object's cancel operation on the pending instruction, the pending instruction executing the cancel operation is deleted from the timing queue, and the instruction state of the pending instruction executing the cancel operation in the instruction database is marked as a third state.
8. A cache device for offline device instructions, characterized in that: include: The first module is used to take the current time node as the target time node and initialize two consecutive time queues with the target time node as the starting point; the time queues include a first window queue and a second window queue in sequence; each of the time queues includes multiple time windows in a preset time range after the target time node; The second module is used to obtain the pending instructions of all offline devices and their expiration times, and insert the pending instructions into the corresponding time window in the timing queue based on the expiration time; wherein the pending instructions are associated with device identifiers; The third module is used to obtain the running status of the offline device, determine the offline device whose running status is online as an online device; based on the device identification of the online device, take out the corresponding to-be-processed instruction from the timing queue and send it to the online device; A fourth module is used for, in response to a time change, taking a next time node of the target time node as the target time node, and performing a clearing operation on the time window corresponding to a previous time node of the target time node; A fifth module is used to return to execute the second module until all the time windows of the first window queue have completed the cleanup operation; The sixth module is used to reload the time node corresponding to each time window of the first window queue based on the next preset time range of the second window queue, exchange the queue pointers of the first window queue and the second window queue, return to execute the second module, and continue to cache instructions of the offline device.
9. An electronic device, characterized in that: including a processor and a memory; The memory is used to store programs; The processor executes the program to implement the method according to any one of claims 1 to 7.
10. A computer storage medium storing a program executable by a processor, characterized in that: The program executable by the processor is used to implement the method according to any one of claims 1 to 7 when executed by the processor.
Citation Information
Patent Citations
Equipment command configuration method and device, electronic equipment and storage medium
CN110427220A
Queue timeout processing method in request task processing and storage medium
CN111858086A
Message cache overdue monitoring method and device, equipment and medium
CN113709257A
Data table expiration notification and automatic cleaning method and system
CN117093573A
Transaction capable queuing
US20140289744A1