Data storage method and device, equipment and medium
By allocating the aggregation time period according to the result of acquiring distributed locks in the passenger flow data processing of the smart camera, the performance degradation and deadlock and live lock problems caused by lock competition in high concurrency environments are solved, and more efficient data aggregation and database performance are achieved.
Patent Information
- Application Number
- CN202412000265.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2025-04-18
AI Technical Summary
In a high concurrency environment, during the inlet and aggregation of passenger data of smart cameras, multi-threaded competition for distributed locks leads to long wait times, degradation of performance, and even live or deadlocks.
By analyzing the passenger flow messages collected by the smart camera, we can determine whether the distributed lock is successfully acquired. If the lock is successfully acquired, the data is aggregated within the current time period. If the lock is not successfully acquired, the data is stored in the database and the data is aggregated when the aggregation conditions are met (i.e. not within the first time period).
The deadlock and live lock situations are avoided, the lock competition process is optimized, the system stability and data processing speed are improved, the number of data rows in the database is reduced, and the database performance is improved.
Smart Images

Figure CN119848073A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a data storage method, device, equipment and medium. Background Art
[0002] Currently, the smart camera (PC8-c) with the function of passenger flow data statistics needs to enter the passenger flow details into the database (passenger_flow table) and aggregate them into the passenger flow aggregation table (is_customer_flow_hourly table), and introduces the redis distributed lock. The smart camera merges and reports once every 5 minutes, but when the number of customers passing through the store is huge, the background multi-threaded consumer lock competition will result in long waiting time, performance degradation, and even live lock or deadlock. Specifically, the lock is obtained when the data is entered into the database, and the aggregation operation is performed after the lock is obtained. If the lock cannot be obtained, the lock will continue to spin until the lock is obtained and the aggregation operation is performed.
[0003] In summary, how to improve the aggregation process to increase the aggregation speed is a problem that needs to be solved urgently. Summary of the invention
[0004] In view of this, the object of the present invention is to provide a data storage method, device, equipment and medium, which can improve the aggregation process to increase the aggregation speed. The specific scheme is as follows:
[0005] In a first aspect, the present application discloses a data storage method, comprising:
[0006] Analyze the passenger flow messages collected by the smart camera to obtain detailed passenger flow statistics;
[0007] Determine whether the distributed lock is successfully acquired;
[0008] If the distributed lock is successfully acquired, the passenger flow statistics detailed data is aggregated into the passenger flow aggregation table corresponding to the current time period in the database; the current time period is the first time period in which the passenger flow statistics detailed data is acquired, and the passenger flow aggregation table is used to record the sum of the passenger flow statistics detailed data generated in the current time period;
[0009] If the distributed lock is not successfully acquired at present, the passenger flow statistics detail data is stored in the database, and the passenger flow statistics detail data in the database is aggregated to the passenger flow aggregation table when the aggregation condition is met; the aggregation condition includes that the aggregation time is not within the first time period.
[0010] The storing of the passenger flow statistics detailed data into a database, and aggregating the passenger flow statistics detailed data into the passenger flow aggregation table when an aggregation condition is met, comprises:
[0011] The passenger flow statistics detailed data is stored in a database, and an aggregation task record corresponding to the passenger flow statistics detailed data is generated in the database, and the aggregation task record is stored in an aggregation task record table;
[0012] When the aggregation condition is met, the passenger flow statistical detail data is aggregated to the passenger flow aggregation table based on the aggregation task record in the aggregation task record table.
[0013] Wherein, aggregating the passenger flow statistical detail data to the passenger flow aggregation table when the aggregation condition is met includes:
[0014] The aggregation task record table is queried periodically based on a timer, and when the acquisition time of the passenger flow statistics detail data in the aggregation task record table is less than any time in the time period of the query time, the passenger flow statistics detail data table is aggregated into the passenger flow aggregation table.
[0015] Wherein, aggregating the passenger flow statistical detail data to the passenger flow aggregation table when the aggregation condition is met includes:
[0016] Aggregate the passenger flow statistical detail data to the passenger flow aggregation table in a second time period; the second time period is the next time period of the first time period.
[0017] Wherein, after aggregating the passenger flow statistics detail data table into the passenger flow aggregation table when the aggregation condition is met, the method further includes:
[0018] Delete the passenger flow statistics detailed data in the database and the aggregation task record table corresponding to the passenger flow statistics detailed data.
[0019] The current time period is the time period between two hourly times corresponding to the acquisition time of the passenger flow statistical detailed data.
[0020] Wherein, the data storage method further includes:
[0021] If the distributed lock is not successfully acquired at present, the passenger flow statistical detail data is stored in the passenger flow aggregation table;
[0022] When the aggregation condition is met, the aggregated data in the passenger flow aggregation table and the passenger flow statistical detail data are aggregated.
[0023] In a second aspect, the present application discloses a data storage device, comprising:
[0024] The data acquisition module is used to parse the passenger flow messages collected by the smart camera to obtain a detailed passenger flow statistics table;
[0025] The judgment module is used to judge whether the distributed lock is successfully acquired;
[0026] The first aggregation module is used to aggregate the passenger flow statistics detailed data to the passenger flow aggregation table corresponding to the current time period in the database if the distributed lock is successfully acquired at present; the current time period is the first time period in which the passenger flow statistics detailed data is acquired; the passenger flow aggregation table is used to record the data sum of each passenger flow statistics detailed data generated in the current time period;
[0027] The second aggregation module is used to store the passenger flow statistics detail data into the database if the distributed lock is not successfully acquired at present, and aggregate the passenger flow statistics detail data in the database to the passenger flow aggregation table when the aggregation conditions are met; the aggregation conditions include that the aggregation time is not within the first time period.
[0028] In a third aspect, the present application discloses an electronic device, comprising:
[0029] Memory, used to store computer programs;
[0030] The processor is used to execute the computer program to implement the data storage method disclosed above.
[0031] In a fourth aspect, the present application discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the aforementioned disclosed data storage method is implemented.
[0032] It can be seen that the present application parses the passenger flow messages collected by the smart camera to obtain passenger flow statistics detailed data; determines whether the distributed lock is successfully acquired at present; if the distributed lock is successfully acquired at present, aggregates the passenger flow statistics detailed data to the passenger flow aggregation table corresponding to the current time period in the database; the current time period is the first time period in which the acquisition time of the passenger flow statistics detailed data is located, and the passenger flow aggregation table is used to record the data and of each passenger flow statistics detailed data generated within the current time period; if the distributed lock is not successfully acquired at present, stores the passenger flow statistics detailed data in the database, and aggregates the passenger flow statistics detailed data in the database to the passenger flow aggregation table when the aggregation conditions are met; the aggregation conditions include that the aggregation time is not within the first time period. It can be seen from this that the present application sets a time outside the first time period to aggregate the passenger flow statistics detail data table that has not obtained the distributed lock into the passenger flow aggregation table, thereby avoiding deadlock and live lock situations, and a more reasonable lock competition process, which improves stability and speeds up data processing, that is, increases the aggregation speed; in addition, the aggregation operation enables the flow aggregation table to record the data and of each passenger flow statistics detail data generated in the current time period, thereby reducing the number of data rows in the current time period, which is beneficial to improving database performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0034] Figure 1 A flow chart of a data storage method disclosed in this application;
[0035] Figure 2 A schematic diagram of a data storage process disclosed in this application;
[0036] Figure 3 A schematic diagram of the structure of a data storage device disclosed in this application;
[0037] Figure 4 This is a structural diagram of an electronic device disclosed in this application. DETAILED DESCRIPTION
[0038] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0039] Currently, the smart camera (PC8-c) with the function of passenger flow data statistics needs to enter the passenger flow details into the database (passenger_flow table) and aggregate them into the passenger flow aggregation table (is_customer_flow_hourly table), and introduces the redis distributed lock. The smart camera merges and reports once every 5 minutes, but when the number of customers passing through the store is huge, the background multi-threaded consumer lock competition will result in long waiting time, performance degradation, and even live lock or deadlock. Specifically, the lock is obtained when the data is entered into the database, and the aggregation operation is performed after the lock is obtained. If the lock cannot be obtained, the lock will continue to spin until the lock is obtained and the aggregation operation is performed.
[0040] To this end, an embodiment of the present application proposes a data storage solution that can improve the aggregation process to increase the aggregation speed.
[0041] The present application discloses a data storage method. Figure 1 As shown, the method includes:
[0042] Step S11: parse the passenger flow messages collected by the smart camera to obtain passenger flow statistics details.
[0043] In this embodiment, the customer flow message transmitted by the smart camera is first obtained and the message is parsed to obtain the detailed data of customer flow statistics. The detailed data of customer flow statistics may include multiple groups of data, wherein the detailed data of customer flow statistics at least includes the store ID (Identity document), the store area ID and the device ID or the device mac (Media Access Control Address) address (such as device a in the cashier area of store A), the customer flow generation time and the customer flow reporting time, the number of customers entering the store and the number of customers leaving the store. In some scenarios, it may also include customer flow personnel feature data and the number of customers passing through the store (the number of customers passing by the store door).
[0044] Step S12: Determine whether the distributed lock is currently acquired successfully.
[0045] Step S13: If the distributed lock is successfully acquired, the passenger flow statistics detail data is aggregated into the passenger flow aggregation table corresponding to the current time period in the database; the current time period is the first time period in which the passenger flow statistics detail data is acquired, and the passenger flow aggregation table is used to record the data and of each passenger flow statistics detail data generated in the current time period.
[0046] In this embodiment, the distributed lock is used to prevent multiple threads from operating the same record in the passenger flow aggregation table.
[0047] In this embodiment, aggregation means adding up the customer flow related information in the current time period, for example, adding up the number of customers entering the store in the current time period and adding up the number of customers leaving the store in the current time period. It should be noted that the purpose of the aggregation operation is to reduce the number of rows recorded in the customer flow hour table and improve the performance of the MySQL database.
[0048] In this embodiment, the current time period is a time period including the passenger flow generation time and the passenger flow reporting time. For example, when the passenger flow generation time is 14:22 and the passenger flow reporting time is 14:22:05, then the current time period is a time period including 14:22 and 14:22:05.
[0049] It should be pointed out that when the program is executed, the length of each time period is generally set to be consistent, and the timer performs aggregation operations regularly. In actual applications, due to reasons such as large concurrency and breakpoint continuation, the passenger flow generation time and the passenger flow reporting time are not exactly the same, and there is a certain time interval. When the passenger flow generation time is in the current time period and the passenger flow reporting time is in the next time period, the execution time of the timer must be no less than the passenger flow generation time-unit time period, and the execution time of the timer must also be no less than the passenger flow reporting time-unit time period.
[0050] In this embodiment, the current time period can be set based on the moment when the passenger flow statistics details are first obtained, such as the current time period is a time period consisting of the starting hour and the ending hour of the moment (the time when the passenger flow is generated); the starting hour is the hour closest to the moment before the moment, and the ending hour is the hour closest to the moment after the moment. For example, if the passenger flow is generated at 14:22, the starting hour is 14:00 and the ending hour is 15:00. The current time period can also be a time period between any two hourly times including the moment in a 24-hour timetable.
[0051] It should be pointed out that the parameters corresponding to the customer flow aggregation table include at least the store ID, store area ID and device ID or device mac address, customer flow generation time, the number of customers entering the store and the number of customers leaving the store. In some scenarios, it can also include customer flow personnel characteristic data and the number of customers passing through the store.
[0052] It should be pointed out that the time when the customer flow is generated can be directly displayed as the initial time or end time of the current time period in which the customer flow is acquired. At this time, the data of the current time period corresponding to the same store ID, store area ID and device ID or device mac address can be counted as one piece of data, that is, the data and.
[0053] In a specific embodiment, regardless of whether a distributed lock is acquired, the current time period is from 14:00 to 15:00. If 14:00 to 15:00 includes three pieces of data in total, 1. Store A, area A, device A, address A, 14:10, 1 person entered the store, and 0 people left the store; 2. Store A, area A, device A, address A, 14:20, 2 people entered the store, and 1 person left the store; 3. Store A, area A, device A, address A, 14:50, 1 person entered the store, and 1 person left the store; the last piece of data obtained by statistics is 1. Store A, area A, device A, address A, 14:00, 4 (1+2+1) people entered the store, and 2 (0+1+1) people left the store.
[0054] Step S14: If the distributed lock is not successfully acquired at present, the passenger flow statistics detail data is stored in the database, and the passenger flow statistics detail data in the database is aggregated to the passenger flow aggregation table when the aggregation condition is met; the aggregation condition includes that the aggregation time is not within the first time period.
[0055] In this embodiment, the passenger flow statistics detail data is stored in a database, and the passenger flow statistics detail data is aggregating to the passenger flow aggregation table when the aggregation condition is met, including: storing the passenger flow statistics detail data in a database, generating an aggregation task record corresponding to the passenger flow statistics detail data in the database, and storing the aggregation task record in an aggregation task record table; aggregating the passenger flow statistics detail data to the passenger flow aggregation table based on the aggregation task record in the aggregation task record table when the aggregation condition is met.
[0056] It should be pointed out that if the distributed lock is not successfully acquired at present, the customer flow statistics detailed data will be stored in the database, and the aggregation operation will not be performed temporarily; when the customer flow statistics detailed data is stored in the database, it is also necessary to record the customer flow generation time, customer flow reporting time, store area ID and device ID or device mac address of this customer flow, generate a pending aggregation task record, and store it in the aggregation task record table for later use.
[0057] In this embodiment, aggregating the passenger flow statistics detail data to the passenger flow aggregation table when the aggregation conditions are met includes: regularly querying the aggregation task record table based on a timer, and aggregating the passenger flow statistics detail data table to the passenger flow aggregation table when the acquisition time of the passenger flow statistics detail data in the aggregation task record table is less than any time in the time period of the query time.
[0058] It should be noted that the timer is used to query once every predetermined time interval whether there is an aggregation task record that meets the aggregation condition.
[0059] In this embodiment, the aggregation condition includes that the aggregation time is not within the first time period; as long as the aggregation time is not within the first time period, it will not affect the aggregation operation of the data of the first time period within the first time period, avoiding the aggregation operation of the same passenger flow aggregation table at the same time and avoiding aggregation data errors.
[0060] In this embodiment, aggregating the passenger flow statistics detailed data to the passenger flow aggregation table when the aggregation condition is met includes: aggregating the passenger flow statistics detailed data to the passenger flow aggregation table in a second time period; the second time period is the next time period of the first time period. It should be noted that the aggregation of the passenger flow statistics detailed data that did not obtain the distributed lock in the first time period can be directly performed in the next time period of the first time period.
[0061] It should be pointed out that the existence of the aggregation condition effectively realizes the separation of dynamic and static. Dynamic refers to the completion of data and aggregation within the first time period by the competing lock in the first time period, and static refers to the direct aggregation of data not aggregated within the first time period by the non-competing lock in other time periods.
[0062] In this embodiment, after aggregating the passenger flow statistics detail data table into the passenger flow aggregation table when the aggregation condition is met, it also includes: deleting the passenger flow statistics detail data in the database and the aggregation task record table corresponding to the passenger flow statistics detail data. It should be noted that deleting redundant data avoids aggregating the same data multiple times.
[0063] In this embodiment, if the distributed lock is not successfully acquired at present, the passenger flow statistics detailed data is stored in the passenger flow aggregation table; when the aggregation condition is met, the aggregated data in the passenger flow aggregation table and the passenger flow statistics detailed data are aggregated. It should be pointed out that if the distributed lock is not successfully acquired, the passenger flow statistics detailed data can be directly stored in the passenger flow aggregation table instead of the database containing the passenger flow aggregation table, so as to facilitate the direct aggregation of the data in the passenger flow aggregation table when the aggregation condition is met, thus saving search time.
[0064] In summary, 1. This application can improve the concurrent performance of the system: 1. Reduce thread waiting time: Through lock elimination technology, when lock competition occurs, first save the detailed customer flow into the database, and then aggregate and merge the data, which can significantly reduce the waiting time of the thread and improve the concurrent performance of the system; 2. Improve resource utilization: After optimizing lock competition, the CPU time slice of the thread is more effectively utilized, reducing thread blocking and context switching caused by lock competition, thereby improving the resource utilization of the entire system. 2. This application can enhance system stability: 1. Avoid deadlock and livelock: Through reasonable lock design and optimization, deadlock and livelock can be avoided to ensure that the system can still run stably in a high-concurrency environment; 2. Reduce the risk of system crash: Long-term lock competition may cause system resources to be exhausted, and then cause system crash. After optimizing lock competition, the risk of system crash is significantly reduced. 3. This application can optimize user experience: 1. Reduce response time: After lock competition optimization, the response time of the system is shortened, and users can get the required data and services faster; 2. Improve system availability: Optimizing lock competition can improve the availability of the system and ensure that users can still access and use the system smoothly in a high-concurrency environment. 4. This application can reduce operation and maintenance costs: 1. Reduce troubleshooting time: After optimizing lock competition, the frequency of system failures is reduced, thereby reducing the time and cost of troubleshooting for operation and maintenance personnel; 2. Improve system maintainability: Through reasonable lock design and optimization, the maintainability of the system is improved, and operation and maintenance personnel can maintain and manage the system more conveniently.
[0065] It can be seen that the present application parses the passenger flow messages collected by the smart camera to obtain passenger flow statistics detailed data; determines whether the distributed lock is successfully acquired at present; if the distributed lock is successfully acquired at present, aggregates the passenger flow statistics detailed data to the passenger flow aggregation table corresponding to the current time period in the database; the current time period is the first time period in which the acquisition time of the passenger flow statistics detailed data is located, and the passenger flow aggregation table is used to record the data and of each passenger flow statistics detailed data generated within the current time period; if the distributed lock is not successfully acquired at present, stores the passenger flow statistics detailed data in the database, and aggregates the passenger flow statistics detailed data in the database to the passenger flow aggregation table when the aggregation conditions are met; the aggregation conditions include that the aggregation time is not within the first time period. It can be seen from this that the present application sets a time outside the first time period to aggregate the passenger flow statistics detail data table that has not obtained the distributed lock into the passenger flow aggregation table, thereby avoiding deadlock and live lock situations, and a more reasonable lock competition process, which improves stability and speeds up data processing, that is, increases the aggregation speed; in addition, the aggregation operation enables the flow aggregation table to record the data and of each passenger flow statistics detail data generated in the current time period, thereby reducing the number of data rows in the current time period, which is beneficial to improving database performance.
[0066] See also Figure 2 As shown, the present application first obtains the passenger flow message reported by the device (smart camera) and parses it to obtain the passenger flow statistics detailed data table. If the distributed lock is obtained later, the passenger flow statistics detailed data will be aggregated and updated to the passenger flow hour table of the database; if the distributed lock is not obtained, the passenger flow statistics detailed data will be stored in the database, and a pending aggregation task record corresponding to the passenger flow statistics detailed data will be generated. The aggregation task record will be queried regularly later to determine the aggregation task record that meets the aggregation conditions, and the passenger flow statistics detailed data corresponding to the aggregation task record will be aggregated into the passenger flow disappearance table to update the data; the aggregation condition includes that the aggregation time is not within the first time period of the acquisition time of the passenger flow statistics detailed data.
[0067] Accordingly, the present application also discloses a data storage device, see Figure 3 As shown, the device comprises:
[0068] The data acquisition module 11 is used to parse the passenger flow messages collected by the intelligent camera to obtain a passenger flow statistics detailed data table;
[0069] The judgment module 12 is used to judge whether the distributed lock is successfully acquired at present;
[0070] The first aggregation module 13 is used to aggregate the passenger flow statistics detailed data to the passenger flow aggregation table corresponding to the current time period in the database if the distributed lock is successfully acquired at present; the current time period is the first time period in which the passenger flow statistics detailed data is acquired; the passenger flow aggregation table is used to record the data sum of each passenger flow statistics detailed data generated in the current time period;
[0071] The second aggregation module 14 is used to store the passenger flow statistics detail data into the database if the distributed lock is not successfully acquired at present, and aggregate the passenger flow statistics detail data in the database to the passenger flow aggregation table when the aggregation condition is met; the aggregation condition includes that the aggregation time is not within the first time period.
[0072] Among them, the more specific working process of each of the above modules can refer to the corresponding content disclosed in the above embodiments, which will not be repeated here.
[0073] It can be seen that the present application parses the passenger flow messages collected by the smart camera to obtain passenger flow statistics detailed data; determines whether the distributed lock is successfully acquired at present; if the distributed lock is successfully acquired at present, aggregates the passenger flow statistics detailed data to the passenger flow aggregation table corresponding to the current time period in the database; the current time period is the first time period in which the acquisition time of the passenger flow statistics detailed data is located, and the passenger flow aggregation table is used to record the data and of each passenger flow statistics detailed data generated within the current time period; if the distributed lock is not successfully acquired at present, stores the passenger flow statistics detailed data in the database, and aggregates the passenger flow statistics detailed data in the database to the passenger flow aggregation table when the aggregation conditions are met; the aggregation conditions include that the aggregation time is not within the first time period. It can be seen from this that the present application sets a time outside the first time period to aggregate the passenger flow statistics detail data table that has not obtained the distributed lock into the passenger flow aggregation table, thereby avoiding deadlock and live lock situations, and a more reasonable lock competition process, which improves stability and speeds up data processing, that is, increases the aggregation speed; in addition, the aggregation operation enables the flow aggregation table to record the data and of each passenger flow statistics detail data generated in the current time period, thereby reducing the number of data rows in the current time period, which is beneficial to improving database performance.
[0074] Furthermore, an embodiment of the present application also provides an electronic device. Figure 4 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content in the diagram cannot be regarded as any limitation on the scope of use of the present application.
[0075] Figure 4A schematic diagram of the structure of an electronic device 20 provided in an embodiment of the present application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a display screen 23, an input / output interface 24, a communication interface 25, a power supply 26, and a communication bus 27. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the data storage method disclosed in any of the aforementioned embodiments. In addition, the electronic device 20 in this embodiment may specifically be an electronic computer.
[0076] In this embodiment, the power supply 26 is used to provide working voltage for each hardware device on the electronic device 20; the communication interface 25 can create a data transmission channel between the electronic device 20 and the external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input and output interface 24 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs and is not specifically limited here.
[0077] In addition, the memory 22, as a carrier for storing resources, may be a read-only memory, a random access memory, a disk or an optical disk, etc., and the resources stored thereon may include a computer program 221, and the storage method may be temporary storage or permanent storage. In addition to including a computer program that can be used to complete the data storage method performed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 221 may further include a computer program that can be used to complete other specific tasks.
[0078] Furthermore, an embodiment of the present application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the aforementioned disclosed data storage method is implemented.
[0079] The specific steps of the method can refer to the corresponding contents disclosed in the above embodiments, which will not be repeated here.
[0080] The various embodiments in this application are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description.
[0081] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0082] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0083] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants 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, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0084] The above is a detailed introduction to a data storage method, device, equipment, and storage medium provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for general technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A data storage method, characterized in that: include: Analyze the passenger flow messages collected by the smart camera to obtain detailed passenger flow statistics; Determine whether the distributed lock is successfully acquired; If the distributed lock is successfully acquired, the passenger flow statistics detailed data is aggregated into the passenger flow aggregation table corresponding to the current time period in the database; the current time period is the first time period in which the passenger flow statistics detailed data is acquired; the passenger flow aggregation table is used to record the data and of each passenger flow statistics detailed data generated in the current time period; If the distributed lock is not successfully acquired at present, the passenger flow statistics detail data is stored in the database, and the passenger flow statistics detail data in the database is aggregated to the passenger flow aggregation table when the aggregation condition is met; the aggregation condition includes that the aggregation time is not within the first time period.
2. The data storage method according to claim 1, characterized in that: The storing the passenger flow statistics detailed data into a database, and aggregating the passenger flow statistics detailed data into the passenger flow aggregation table when an aggregation condition is met, comprises: The passenger flow statistics detailed data is stored in a database, and an aggregation task record corresponding to the passenger flow statistics detailed data is generated in the database, and the aggregation task record is stored in an aggregation task record table; When the aggregation condition is met, the passenger flow statistical detail data is aggregated to the passenger flow aggregation table based on the aggregation task record in the aggregation task record table.
3. The data storage method according to claim 2, characterized in that: The aggregating the passenger flow statistical detail data to the passenger flow aggregation table when the aggregation condition is met includes: The aggregation task record table is queried periodically based on a timer, and when the acquisition time of the passenger flow statistics detail data in the aggregation task record table is less than any time in the time period of the query time, the passenger flow statistics detail data table is aggregated into the passenger flow aggregation table.
4. The data storage method according to claim 2, characterized in that: The aggregating the passenger flow statistical detail data to the passenger flow aggregation table when the aggregation condition is met includes: Aggregate the passenger flow statistical detail data to the passenger flow aggregation table in a second time period; the second time period is the next time period of the first time period.
5. The data storage method according to claim 4, characterized in that: After aggregating the passenger flow statistics detailed data table into the passenger flow aggregation table when the aggregation condition is met, the method further includes: Delete the passenger flow statistics detailed data in the database and the aggregation task record table corresponding to the passenger flow statistics detailed data.
6. The data storage method according to claim 1, characterized in that: The current time period is the time period between two hourly times corresponding to the acquisition time of the passenger flow statistical detailed data.
7. The data storage method according to any one of claims 1 to 6, characterized in that: Also includes: If the distributed lock is not successfully acquired at present, the passenger flow statistical detail data is stored in the passenger flow aggregation table; When the aggregation condition is met, the aggregated data in the passenger flow aggregation table and the passenger flow statistical detail data are aggregated.
8. A data storage device, characterized in that: include: The data acquisition module is used to parse the passenger flow messages collected by the smart camera to obtain a detailed passenger flow statistics table; The judgment module is used to judge whether the distributed lock is successfully acquired; The first aggregation module is used to aggregate the passenger flow statistics detailed data to the passenger flow aggregation table corresponding to the current time period in the database if the distributed lock is successfully acquired at present; the current time period is the first time period in which the passenger flow statistics detailed data is acquired; the passenger flow aggregation table is used to record the data sum of each passenger flow statistics detailed data generated in the current time period; The second aggregation module is used to store the passenger flow statistics detail data into the database if the distributed lock is not successfully acquired at present, and aggregate the passenger flow statistics detail data in the database to the passenger flow aggregation table when the aggregation conditions are met; the aggregation conditions include that the aggregation time is not within the first time period.
9. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to execute the computer program to implement the data storage method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: Used to store computer programs; wherein, when the computer program is executed by a processor, the data storage method according to any one of claims 1 to 7 is implemented.