Data access method and device
By combining the polling thread and independent command receiving channel with real-time task queue, the problem of timely processing of device interaction programs when receiving anti-control commands is solved, the timeliness and reliability of data access is improved, and multi-process management and threading are avoided The complexity of interlocking locks.
Patent Information
- Application Number
- CN202011613771.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-30
- Publication Date
- 2024-12-20
- Estimated Expiration
- 2040-12-30
AI Technical Summary
The existing device interaction program worker is difficult to optimize and process in a timely manner when receiving anti-control commands, and the multi-process concurrent processing solution increases management costs and fault tolerance complexity. The inter-thread sharding mechanism depends on operating system scheduling in a timely manner.
By setting up a polling thread to collect business data and independently receive anti-control commands, it is converted into real-time read and write tasks and write tasks to the task queue. The polling thread monitoring queue is used to achieve real-time processing, avoiding multi-process management and inter-thread locking mechanisms, ensuring anti-control Respond to the command in a timely manner.
Improves the timeliness and reliability of data access, reduces management costs and fault tolerance complexity, and ensures timely optimization and processing of feedback commands.
Smart Images

Figure CN112667381B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to data processing technology, and in particular to a data access method and device. Background Art
[0002] In the field of Internet of Things, especially the field of Industrial Internet of Things, in the process of solving factory intelligence through intelligent Internet of Things platform, the platform software generally has the following data processing steps: equipment data collection, equipment data storage, equipment data storage, equipment data analysis, and feedback of analysis results to the equipment. In the stage of feeding back the analysis results to the equipment, many devices need to be able to receive the reverse control command in real time and respond to the reverse control command to complete the feedback processing of the data in time. The program for receiving the reverse control command and responding to the reverse control command to complete the feedback processing of the data in time, that is, the device interaction program worker, generally also undertakes many other tasks at the same time, such as obtaining a large amount of equipment data, transmitting a large amount of equipment data to the outside, etc. Therefore, the existing device interaction program worker must have the problem of how to timely and preferentially process the reverse control command. Summary of the invention
[0003] In order to solve the above-mentioned defects of the existing device interaction program worker, the embodiment of the present invention creatively provides a data access method and apparatus.
[0004] According to a first aspect of the present invention, a data access method is provided, the method comprising: collecting business data through a polling thread; receiving a reverse control command through a command receiving channel independent of the polling thread; converting the received reverse control command into a real-time read / write task, and writing it into a real-time task queue; monitoring the real-time task queue through a polling thread; and outputting the collected business data when it is detected that the real-time task queue includes a real-time read / write task.
[0005] According to an embodiment of the present invention, the collecting of business data through a polling thread includes: parsing a business data collection configuration file to obtain a polling interval; and collecting business data according to the polling interval.
[0006] According to one embodiment of the present invention, business data is collected through a polling thread at a first set frequency; the real-time task queue is monitored through a polling thread at a second set frequency; wherein the first set frequency is less than the second set frequency.
[0007] According to an embodiment of the present invention, the ratio of the first set frequency to the second set frequency is 1:500.
[0008] According to an embodiment of the present invention, collecting business data through a polling thread includes: obtaining a dynamically updated data collection throughput; and collecting business data according to the data collection throughput through a polling thread.
[0009] According to the second aspect of the present invention, a data access device is also provided, which includes: a data acquisition module, which is used to collect business data through a polling thread; a command receiving module, which is used to receive a reverse control command through the command receiving channel independent of the polling thread; a conversion module, which is used to convert the received reverse control command into a real-time read / write task, and write it into a real-time task queue; a monitoring module, which is used to monitor the real-time task queue through a polling thread; and a data output module, which is used to output the collected business data when it is detected that the real-time task queue includes a real-time read / write task.
[0010] According to an embodiment of the present invention, the data collection module is specifically used to parse the business data collection configuration file to obtain the polling interval time; and collect business data according to the polling interval time.
[0011] According to one embodiment of the present invention, the data acquisition module is specifically used to collect business data through a polling thread according to a first set frequency; the monitoring module is specifically used to monitor the real-time task queue through a polling thread according to a second set frequency; wherein the first set frequency is less than the second set frequency.
[0012] According to an embodiment of the present invention, the data collection module is specifically used to obtain the dynamically updated data collection throughput; and collect business data according to the data collection throughput through a polling thread.
[0013] According to the third aspect of the present invention, a data access device is provided, comprising: one or more processors; a memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement any of the above-mentioned data access methods.
[0014] The data access method and device of the embodiment of the present invention first collects business data through a polling thread; at the same time, receives a reverse control command through the command receiving channel independent of the polling thread; further converts the received reverse control command into a real-time read-write task and writes it into a real-time task queue; then monitors the real-time task queue through a polling thread; and finally outputs the collected business data when it is detected that the real-time task queue includes a real-time read-write task. In this way, the present invention sets a device interaction program (worker) to include at least a polling thread and a command receiving channel independent of the polling thread, so that while collecting business data through the polling thread, feedback commands can be received through the command receiving channel independent of the polling thread, and further introduces a real-time read-write task queue internally, thereby ensuring that the logic of processing the real-time task queue is added to the polling thread at different times according to the business situation, effectively realizing timely optimization processing of feedback commands, thereby improving the timeliness and reliability of data access.
[0015] It should be understood that the teachings of the present invention are not required to achieve all of the beneficial effects described above, but specific technical solutions can achieve specific technical effects, and other embodiments of the present invention can also achieve beneficial effects not mentioned above. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The above and other objects, features and advantages of the exemplary embodiments of the present invention will become readily understood by reading the detailed description below with reference to the accompanying drawings. In the accompanying drawings, several embodiments of the present invention are shown in an exemplary and non-limiting manner, in which:
[0017] In the drawings, the same or corresponding reference numerals represent the same or corresponding parts.
[0018] Figure 1 The following is a schematic diagram showing the implementation process of the data access method according to the embodiment of the present invention. Figure 1 ;
[0019] Figure 2 The following is a schematic diagram showing the implementation process of the data access method according to the embodiment of the present invention. Figure 2 ;
[0020] Figure 3 The following is a schematic diagram showing the implementation process of the data access method according to the embodiment of the present invention. Figure 3 ;
[0021] Figure 4 A schematic diagram of the structure of a data access device according to an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0022] The principles and spirit of the present invention will be described below with reference to several exemplary embodiments. It should be understood that these embodiments are provided only to enable those skilled in the art to better understand and implement the present invention, and are not intended to limit the scope of the present invention in any way. On the contrary, these embodiments are provided to make the present invention more thorough and complete, and to fully convey the scope of the present invention to those skilled in the art.
[0023] The technical solution of the present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments.
[0024] In the related art, in order to solve the problem that the received reverse control command cannot be optimized and processed in time, the existing device interaction program worker usually adopts the following two solutions:
[0025] Solution 1: 1. Connect to the device through multiple processes at the same time for concurrent processing. The advantage of this solution is that it solves the problem of device exclusivity through multiple processes and multiple connections. The disadvantage of this solution is that when the device receives the reverse control command, it often needs to do some business logic (this may require coordination among various modules within the program) before the result can be returned to the device. If a multi-process solution is adopted, it is necessary to manage multiple processes first and establish a communication mechanism between processes to ensure that the logic is processed normally and written to the device. This obviously causes a lot of management costs to the peripheral management program; if an accident occurs in the process, a corresponding fault-tolerant mechanism is also required to ensure the reconstruction of the business.
[0026] Solution 2: Within a program, after receiving a command, the program relies on the sharding mechanism between threads to read and write the device (threads preempt device locks). The problem with this solution is that it leaves the timing of real-time processing to the operating system (OS). For a time-sharing operating system, the application layer cannot fully guarantee that the thread can be scheduled and processed immediately.
[0027] In order to effectively solve the above problems existing in the prior art, an embodiment of the present invention provides a data access method and device.
[0028] Figure 1 The following is a schematic diagram showing the implementation process of the data access method according to the embodiment of the present invention. Figure 1 .
[0029] refer to Figure 1An embodiment of the present invention provides a data access method, which includes: operation 101, collecting business data through a polling thread; operation 102, receiving a reverse control command through a command receiving channel independent of the polling thread; operation 103, converting the received reverse control command into a real-time read / write task, and writing it into a real-time task queue; operation 104, monitoring the real-time task queue through a polling thread; operation 105, when it is detected that the real-time task queue includes a real-time read / write task, outputting the collected business data.
[0030] On the one hand, in order to avoid the problem that multiple processes are connected to the device at the same time for concurrent processing, a corresponding fault-tolerant mechanism is needed to ensure the reconstruction of the business when an accident occurs in the process; on the other hand, in order to overcome the problem that when the device receives a reverse control command, the multi-process solution needs to establish a communication mechanism between processes to ensure that the logic is written to the device after normal processing, the device interaction program is creatively set to directly collect business data through a polling thread.
[0031] Specifically, in operation 101, after the device starts the interactive program, it first needs to parse the business data collection configuration file to obtain the polling interval time; and then collect business data according to the polling interval time.
[0032] Here, when or before starting the interactive program, the device will pre-load the business data collection configuration file from the collection server to the local according to the collection requirements. The business data collection configuration file includes collection parameter information such as collection throughput and polling interval.
[0033] Among them, the collection of business data involved in the embodiments of the present invention is mainly the collection of indicator parameters, performance parameters, etc. of PLC equipment / machine tools used in each production process in the production process of smart devices including laptops, tablets, smart phones, etc.
[0034] In operation 102, in order to ensure that the counter-control command can be called and processed in time, the device of the present invention sets a command receiving channel independent of the polling thread in the interactive program to ensure real-time reception of the counter-control command.
[0035] Furthermore, in operations 103 to 104, due to device exclusivity, in order to ensure that the worker can receive feedback commands and perform response processing in real time while collecting business data through the polling thread, adding a device lock will rely on the processing mechanism of the OS. Therefore, the present invention does not proceed by way of a lock, but by introducing a real-time read-write task queue internally, that is, after receiving the reverse control command, the reverse control command is converted into a real-time read-write task and written into the real-time task queue, so as to monitor the real-time task queue in real time through the polling thread, thereby ensuring that the logic of processing the real-time task queue is added at different times in the polling thread according to the business situation.
[0036] In operation 105, when the device detects a real-time read / write task on the polling thread, it can respond to the reverse control command and output the collected business data, thereby effectively realizing timely optimization processing of the feedback command.
[0037] In this way, the present invention sets the device interaction program (worker) to include at least a polling thread and a command receiving channel independent of the polling thread, so that while collecting business data through the polling thread, feedback commands can be received through the command receiving channel independent of the polling thread. Further, by introducing a real-time read and write task queue internally, it is ensured that the logic of processing the real-time task queue is added to the polling thread at different times according to the business situation, thereby effectively realizing timely optimization processing of feedback commands, thereby improving the timeliness and reliability of data access.
[0038] Figure 2 The following is a schematic diagram showing the implementation process of the data access method according to the embodiment of the present invention. Figure 2 .
[0039] refer to Figure 2 An embodiment of the present invention provides a data access method, which includes: operation 201, collecting business data through a polling thread according to a first set frequency; operation 202, receiving a reverse control command through a command receiving channel independent of the polling thread; operation 203, converting the received reverse control command into a real-time read / write task, and writing it into a real-time task queue; operation 204, monitoring the real-time task queue through a polling thread according to a second set frequency; operation 205, when it is monitored that the real-time task queue includes a real-time read / write task, outputting the collected business data.
[0040] On the one hand, in order to avoid the problem that multiple processes are connected to the device at the same time for concurrent processing, a corresponding fault-tolerant mechanism is needed to ensure the reconstruction of the business when an accident occurs in the process; on the other hand, in order to overcome the problem that when the device receives a reverse control command, the multi-process solution needs to establish a communication mechanism between processes to ensure that the logic is written to the device after normal processing, the device interaction program is creatively set to directly collect business data through a polling thread.
[0041] Specifically, in operation 201, after the device starts the interactive program, it first needs to parse the business data collection configuration file to obtain the polling interval; convert the polling interval to obtain the first set frequency; and then collect business data according to the first set frequency.
[0042] Here, when or before starting the interactive program, the device will pre-load the business data collection configuration file from the collection server to the local according to the collection requirements. The business data collection configuration file includes collection parameter information such as collection throughput and polling interval.
[0043] In operation 202, in order to ensure that the counter-control command can be called and processed in time, the device of the present invention sets a command receiving channel independent of the polling thread in the interactive program to ensure real-time reception of the counter-control command.
[0044] Furthermore, in operations 203 to 204, due to device exclusivity, in order to ensure that the worker can receive feedback commands and perform response processing in real time while collecting business data through the polling thread, adding a device lock will rely on the processing mechanism of the OS. Therefore, the present invention does not proceed by way of a lock, but by introducing a real-time read-write task queue internally, that is, after receiving the reverse control command, the reverse control command is converted into a real-time read-write task and written to the real-time task queue, so as to monitor the real-time task queue in real time through the polling thread, thereby ensuring that the logic of processing the real-time task queue is added at different times in the polling thread according to the business situation.
[0045] In one embodiment, the polling thread generally has a frequency for data collection during the data collection process. If the frequency is relatively long, when a real-time read / write task comes, in order to be able to process it immediately, the polling thread also needs to check the real-time task queue at a very short frequency during the sleep process. If there is a task, it will immediately enter the processing state. Based on this, the present invention corresponds to the operation 201 that the device collects business data through the polling thread according to the first set frequency; in operation 204, the device monitors the real-time task queue through the polling thread according to the second set frequency; wherein the first set frequency is less than the second set frequency.
[0046] In an application example, the ratio of the first set frequency to the second set frequency is 1: 500. For example, if the polling interval is 1 second, in order to support data acquisition, the polling thread cannot be allowed to sleep for 1 second before executing, so it is hoped that the polling thread monitors the real-time task queue every 2 ms.
[0047] In operation 205, when the device detects a real-time read / write task on the polling thread, it can respond to the reverse control command and output the collected business data, thereby effectively realizing timely optimization processing of the feedback command.
[0048] Figure 3 The following is a schematic diagram showing the implementation process of the data access method according to the embodiment of the present invention. Figure 3 .
[0049] refer to Figure 3An embodiment of the present invention provides a data access method, which includes: operation 301, obtaining a dynamically updated data acquisition throughput; 302, collecting business data according to the data acquisition throughput through a polling thread; operation 303, receiving a reverse control command through a command receiving channel independent of the polling thread; operation 304, converting the received reverse control command into a real-time read / write task, and writing it into a real-time task queue; operation 305, monitoring the real-time task queue through a polling thread; operation 306, when it is detected that the real-time task queue includes a real-time read / write task, outputting the collected business data.
[0050] In the process of collecting business data, in order to speed up the collection speed and solve the problem of device data alignment, business data is generally read in batches (interact with the device once and obtain multiple business data at a time), which reduces the interaction of the device and improves the throughput of data collection. However, the single acquisition time will be longer. For tasks with real-time requirements, this time will obviously affect the real-time requirements. Therefore, the collection server needs to dynamically adjust the collection throughput size in the business data collection configuration file according to the real-time demand target.
[0051] Based on this, in operations 301 to 302, the device will monitor in real time in the polling thread whether there is an update to the business data configuration file on the collection server. When it is detected that there is an update to the business data configuration file, the dynamically updated data collection throughput is obtained; and business data is further collected according to the data collection throughput through the polling thread.
[0052] Here, when or before starting the interactive program, the device will pre-load the business data collection configuration file from the collection server to the local according to the collection requirements. The business data collection configuration file includes collection parameter information such as collection throughput and polling interval.
[0053] Among them, the collection of business data involved in the embodiments of the present invention is mainly the collection of indicator parameters, performance parameters, etc. of PLC equipment / machine tools used in each production process in the production process of smart devices including laptops, tablets, smart phones, etc.
[0054] In operation 303, in order to ensure that the counter-control command can be called and processed in time, the device of the present invention sets a command receiving channel independent of the polling thread in the interactive program to ensure real-time reception of the counter-control command.
[0055] Furthermore, in operations 304 to 305, due to device exclusivity, in order to ensure that the worker can receive feedback commands and perform response processing in real time while collecting business data through the polling thread, adding a device lock will rely on the processing mechanism of the OS. Therefore, the present invention does not proceed by way of a lock, but by introducing a real-time read-write task queue internally, that is, after receiving the reverse control command, the reverse control command is converted into a real-time read-write task and written into the real-time task queue, so as to monitor the real-time task queue in real time through the polling thread, thereby ensuring that the logic of processing the real-time task queue is added at different times in the polling thread according to the business situation.
[0056] In operation 305, when the device detects a real-time read / write task on the polling thread, it can respond to the reverse control command and output the collected business data, thereby effectively realizing timely optimization processing of the feedback command.
[0057] Similarly, based on the data access method described above, an embodiment of the present invention also provides a data access device, including: one or more processors; a memory for storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement the following operation steps: operation 101, collecting business data through a polling thread; operation 102, receiving a reverse control command through the command receiving channel independent of the polling thread; operation 103, converting the received reverse control command into a real-time read and write task, and writing it to the real-time task queue; operation 104, monitoring the real-time task queue through a polling thread; operation 105, when it is monitored that the real-time task queue includes a real-time read and write task, outputting the collected business data.
[0058] Furthermore, based on the data access method described above, an embodiment of the present invention provides a data access device, such as Figure 4 As shown, the device 40 includes: a data acquisition module 401, which is used to collect business data through a polling thread; a command receiving module 402, which is used to receive a reverse control command through a command receiving channel independent of the polling thread; a conversion module 403, which is used to convert the received reverse control command into a real-time read / write task, and write it into a real-time task queue; a monitoring module 404, which is used to monitor the real-time task queue through a polling thread; and a data output module 405, which is used to output the collected business data when it is detected that the real-time task queue includes a real-time read / write task.
[0059] According to an embodiment of the present invention, the data collection module 401 is specifically used to parse the business data collection configuration file to obtain the polling interval time; and collect business data according to the polling interval time.
[0060] According to one embodiment of the present invention, the data acquisition module 401 is specifically used to collect business data through a polling thread according to a first set frequency; the monitoring module 404 is specifically used to monitor the real-time task queue through a polling thread according to a second set frequency; wherein the first set frequency is less than the second set frequency.
[0061] According to an embodiment of the present invention, the data collection module 401 is specifically used to obtain the dynamically updated data collection throughput; and collect business data according to the data collection throughput through a polling thread.
[0062] It should be noted that: the above description of the data access device embodiment is different from the above description of the data access device embodiment. Figures 1 to 3 The description of the method embodiment shown is similar, with the same Figures 1 to 3 The method embodiment shown in the figure has similar beneficial effects, so it will not be described in detail. For technical details not disclosed in the data access device embodiment of the present invention, please refer to the aforementioned Figures 1 to 3 The description of the method embodiment shown in the figure can be understood, and in order to save space, it will not be repeated.
[0063] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0064] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0065] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units; they may be located in one place or distributed on multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0066] In addition, all functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may be separately used as a unit, or two or more units may be integrated into one unit; the above-mentioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0067] A person skilled in the art can understand that all or part of the steps of implementing the above method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above method embodiment; and the aforementioned storage medium includes: mobile storage devices, read-only memories (ROM), magnetic disks or optical disks, etc., various media that can store program codes.
[0068] Alternatively, if the above-mentioned integrated unit of the present invention is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present invention can be essentially or partly reflected in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROMs, magnetic disks, or optical disks.
[0069] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A data access method, the method comprising: Collect business data through polling threads; Receiving a reverse control command through a command receiving channel independent of the polling thread; Convert the received reverse control command into a real-time read / write task and write it into the real-time task queue; Monitoring the real-time task queue via a polling thread; When it is detected that the real-time task queue includes a real-time read / write task, the collected business data is output; wherein, the business data is collected through a polling thread at a first set frequency; and the real-time task queue is monitored through a polling thread at a second set frequency; wherein the first set frequency is less than the second set frequency; The collecting of business data through polling threads includes: Parse the business data collection configuration file to obtain the polling interval; The business data is collected according to the polling interval.
2. The method according to claim 1, characterized in that The ratio of the first set frequency to the second set frequency is 1:
500.
3. The method according to any one of claims 1 to 2, characterized in that: The collecting of business data through polling threads includes: Get the data collection throughput after dynamic update; The business data is collected according to the data collection throughput through a polling thread.
4. A data access device, characterized in that: The device comprises: Data collection module, used to collect business data through polling threads; A command receiving module, used for receiving a reverse control command through a command receiving channel independent of the polling thread; A conversion module, used for converting the received reverse control command into a real-time read / write task and writing it into a real-time task queue; A monitoring module, used for monitoring the real-time task queue through a polling thread; A data output module, used for outputting the collected business data when it is detected that the real-time task queue includes a real-time read and write task; The data collection module is specifically used to collect business data through a polling thread according to a first set frequency; The monitoring module is specifically used to monitor the real-time task queue through a polling thread according to a second set frequency; Wherein, the first set frequency is less than the second set frequency; The data collection module is specifically used to parse the business data collection configuration file to obtain the polling interval time; and collect business data according to the polling interval time.
5. The device according to claim 4, characterized in that The data collection module is specifically used to obtain the dynamically updated data collection throughput; and collect business data according to the data collection throughput through a polling thread.
6. A data access device, comprising: one or more processors; and a memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the data access method as described in any one of claims 1 to 3.
