Index statistical method, system, device and storage medium
By using the State object to store parameters such as time linked lists in the big data processing framework, efficient indicator statistics are achieved, solving the problems of large calculations and high delays in the existing technology, and supporting indicator backtracking.
Patent Information
- Application Number
- CN201810450749.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2018-05-11
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2038-05-11
AI Technical Summary
The default window mechanism of the existing big data real-time processing framework does not support item-by-item updates of time windows, resulting in large calculations, high latency, and does not support indicator backtracking.
The State object in the mapWithState operator is used to store the time linked list, the minimum value, maximum value and indicator statistical value of the time linked list. The indicator statistical value is obtained through multiplexing calculation, which reduces the calculation amount and delay, and realizes the backtracking of the indicator statistical value.
It realizes efficient indicator statistics in the big data processing framework, reduces the amount of calculation and delay, can quickly respond to business needs, and supports indicator backtracking.
Smart Images

Figure CN110471944B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of indicator statistics of big data, and in particular to an indicator statistics method, system, device and storage medium of a sliding window based on a big data processing framework. Background Art
[0002] With the rapid development of big data processing technology, businesses have increasingly higher requirements for the timeliness of data. Traditional offline indicator calculations can no longer meet business requirements. The rapid growth in demand has promoted the updating and iteration of technology. Various big data real-time processing frameworks have emerged. Flink (a big data processing framework) has received widespread attention for its ultra-short processing delay and high throughput, and has been applied in production environments.
[0003] In the field of indicator statistics, statistical indicators based on time windows are the most common form. Among various types of time windows, sliding time windows are the most consistent with human cognition. The smaller the time of each sliding, the higher the timeliness of the indicator and the more accurate the statistical results. If the sliding calculation can be done item by item, the real-time statistics and updates of the indicators can be achieved. Although Flink supports time window statistics, its default window mechanism does not support item by item updates of time windows. Even if it is developed by inheriting the API (application programming interface), it will still cause serious consequences of memory overflow when the window is long and the data volume is large. In addition, Flink does not support indicator backtracking. In addition, each time the sliding window mechanism supported by Flink is used for calculation, the data of the entire window must be calculated. The calculation amount is large and the delay is high when the window is long. Summary of the invention
[0004] The technical problem to be solved by the present invention is to overcome the defects that the default window mechanism of the big data real-time processing framework in the prior art does not support the update of time windows one by one, and the inherited API method has large calculation amount and high delay. A method, system, device and storage medium for indicator statistics based on a sliding window of a big data processing framework is provided, which can fully reuse the calculated statistical values and thus reduce the calculation amount and delay.
[0005] The present invention solves the above technical problems through the following technical solutions:
[0006] The present invention provides an index statistics method based on a sliding window of a big data processing framework, which is characterized in that a State (an object in a big data processing framework) object in a mapWithState (an operator in a big data processing framework) operator is used to store several parameters, wherein the parameters include a time chain list, a minimum value of the time chain list, a maximum value of the time chain list and an index statistics value;
[0007] The indicator statistical method comprises the following steps:
[0008] The big data processing framework receives data, each piece of the data includes a to-be-counted indicator field and a corresponding timestamp, and the time linked list is used to store the timestamps of the data in chronological order;
[0009] Taking the latest piece of data received as current data;
[0010] The time chain table, the minimum value, the maximum value and the indicator statistical value are updated according to the timestamp of the current data, the indicator field to be counted of the current data and the preset time window value, and the indicator statistical value is obtained by multiplexing calculation.
[0011] In this solution, the indicator fields to be counted vary according to different business requirements. The state storage and calculation operators provided by the big data processing framework have the function of storing state information and can store user-specified data. In this solution, the State object is used to store the time chain table, the minimum value of the time chain table, the maximum value of the time chain table, and the indicator statistics. Among them, the time chain table is used to store the timestamps of the data in chronological order, and the timestamps are used to implement the disorder processing and expiration processing of the data one by one. The minimum and maximum values are used to implement the time switch mechanism, which is specifically used to determine the type of data currently arriving and use the most appropriate process to process the current data, which greatly reduces the amount of data calculation in the indicator statistics process and improves the response speed. The State object also stores the indicator statistics value, which is the final statistical result. The indicator statistics are only performed on the data in a time window each time, avoiding the defects of large amount of calculation and high delay caused by calculating the data of the entire window each time in the prior art. This solution reduces the amount of calculation, improves the calculation speed, and reduces the delay by reusing the indicator statistics that have been calculated.
[0012] Preferably, updating the time chain table, the minimum value, the maximum value and the indicator statistical value according to the timestamp of the current data, the indicator field to be counted of the current data and the preset time window value specifically includes the following steps:
[0013] S1, determine whether the current data is the first data received, if yes, execute step S2, if no, execute step S3;
[0014] S2, initialize the State object and execute step S8;
[0015] S3, determining whether the timestamp of the current data is less than or equal to the minimum value, if so, executing step S4, if not, executing step S5;
[0016] S4, placing the timestamp of the current data at the head of the time chain table, setting the minimum value as the timestamp of the current data, and executing step S8;
[0017] S5, determining whether the timestamp of the current data is greater than the minimum value and less than the maximum value, if so, executing step S6, if not, executing step S7;
[0018] S6, traverse the time chain table, insert the timestamp of the current data into the corresponding position of the time chain table in chronological order, and execute step S8;
[0019] S7, update the time chain table, the minimum value and the maximum value according to the size relationship between the timestamp of the current data and the first window value and the second window value, and execute step S8; the first window value is the sum of the preset time window value and the minimum value, and the second window value is the sum of the preset time window value and the maximum value;
[0020] S8. Update the indicator statistics.
[0021] In this solution, when the current data received is the first data to arrive, the State object is empty and needs to be initialized. When other data arrives, it needs to be updated accordingly according to the specific situation. Specifically, when the timestamp of the current data is less than or equal to the minimum value, the timestamp of the current data is placed at the head of the time list, and the minimum value is set as the timestamp of the current data. At the same time, the indicator statistics need to be updated; when the timestamp of the current data is greater than the minimum value and less than the maximum value, it means that the current data is disordered data and needs to be inserted into the appropriate position in the time list. It can be traversed from the end of the list to the head to find a suitable position to insert the element and update various parameters at the same time; when the timestamp of the current data is greater than or equal to the maximum value, it is normal data. At this time, it is necessary to update various parameters according to the size relationship between the timestamp and the first window value and the second window value.
[0022] Preferably, step S7 includes the following steps:
[0023] S 71 , determine whether the timestamp of the current data is greater than or equal to the second window value, if so, execute step S2, if not, execute step S 72 ;
[0024] S 72 , determine whether the timestamp of the current data is less than the first window value, if so, execute step S 73 , if otherwise, execute step S 74 ;
[0025] S 73, adding the timestamp of the current data to the end of the time linked list, setting the maximum value to the timestamp of the current data, and executing step S8;
[0026] S 74 , traverse the time linked list to find the data that has not expired, and set the timestamp of the data that has not expired to the minimum value, add the timestamp of the current data to the end of the time linked list, set the maximum value to the timestamp of the current data, and execute step S8.
[0027] In this solution, for data that arrives normally, it is divided into three situations for processing, specifically: when the timestamp of the current data is greater than or equal to the second window value, it means that all data are expired, and the State object is reinitialized at this time; when the timestamp of the current data is less than the first window value, it means that no data is expired, the timestamp of the current data is added to the end of the time linked list, the maximum value is set to the timestamp of the current data, and the indicator statistics are updated; when the timestamp of the current data is between the first window value and the second window value, it means that some data is expired. The time linked list is the timestamp of all data stored by time, so the linked list is traversed from the head until the unexpired data is found, the timestamp of this data is set to the minimum value, and then the timestamp of the current data is added to the end of the linked list, the maximum value is set to the timestamp of the current data, and the indicator statistics are updated. The indicator statistics are the final statistical results.
[0028] Preferably, initializing the State object in step S2 includes the following steps:
[0029] Clear the time chain table, add the timestamp of the current data to the time chain table, set the maximum value and the minimum value to the timestamp of the current data, and preset the indicator statistical value.
[0030] In this solution, the indicator statistical values are preset to corresponding initial values according to the specific meaning of the corresponding business.
[0031] Preferably, the latest piece of data received is used as the current data, which specifically includes the following steps:
[0032] T1, taking the latest received data as the first data;
[0033] T2. Use a map (an operator in a big data processing framework) operator to convert the first data into second data of a Tuple (a data structure) type;
[0034] T3. Use the second data as the current data.
[0035] In this solution, when the received data comes from different data sources, the data format and content are very different. In order to be processed in real time and efficiently, this solution standardizes the data format and converts different data contents into a unified Tuple data format through the map operator to facilitate efficient data calculation.
[0036] Preferably, each piece of the data includes a number of indicator fields to be counted;
[0037] The method of taking the latest received data as the current data specifically includes the following steps:
[0038] U1, taking the latest received data as the third data;
[0039] U2. Use the KeyBy operator (an operator in the big data processing framework) to distribute the third data to different nodes according to the dimension of the indicator field to be counted, and the data distributed to the nodes is the fourth data;
[0040] U3. Use the fourth data as the current data.
[0041] In this solution, common statistical indicators are all counted based on a certain business dimension. In this solution, different dimensions are extended according to different business needs. For each piece of data, several indicator fields to be counted can be included. The KeyBy operator provided by the big data processing framework is used to divert the data to different nodes for statistics. The data is diverted according to the dimension of the indicator field to be counted to form a hash data stream. Distributing data of the same dimension to the same node and using multiple nodes to perform data processing can improve overall performance and throughput.
[0042] In this solution, the State object stores detailed information of historical data, and expands the indicator statistics of multiple indicator fields to be counted. Multiple indicators can be counted at the same time, which can improve efficiency. At the same time, because the State object stores detailed information of historical data, it can realize the backtracking of indicator statistical values.
[0043] Preferably, the big data processing framework receives the data in a parallel manner.
[0044] In this solution, the big data processing framework receives external real-time data from different pipelines, and receiving data in parallel can improve the overall throughput.
[0045] Preferably, the big data processing framework is Flink.
[0046] Preferably, the time linked list is a bidirectional linked list.
[0047] In this solution, the timestamps of historical data stored in the State object use a bidirectional linked list. The bidirectional linked list stores data in chronological order. Each time a search is performed, the fastest direction can be selected to locate the disordered data and expired data. The complexity of the insertion and deletion operations of the time linked list is O(1) (a way of expressing algorithm complexity), which can improve processing speed and efficiency.
[0048] The present invention also provides an index statistics system of a sliding window based on a big data processing framework, which is characterized in that it includes a parameter storage module, a data processing module, and a real-time processing module;
[0049] The big data processing framework includes a data receiver;
[0050] The parameter storage module uses the State object in the mapWithState operator to store several parameters, including a time chain list, a minimum value of the time chain list, a maximum value of the time chain list, and an indicator statistical value;
[0051] The data receiver is used to receive data, each piece of the data includes a to-be-counted indicator field and a corresponding timestamp, and the time linked list is used to store the timestamps of the data in chronological order;
[0052] The real-time processing module is used to take the latest received data as current data;
[0053] The data processing module is used to update the time chain table, the minimum value, the maximum value and the indicator statistical value according to the timestamp of the current data, the indicator field to be counted of the current data and the preset time window value, and the indicator statistical value is obtained by multiplexing calculation.
[0054] Preferably, the data processing module includes a first judgment module, an initialization module, a second judgment module, a first processing module, a third judgment module, a second processing module and a normal data processing module;
[0055] The first judgment module is used to judge whether the current data is the first data received by the data receiver, and if so, call the initialization module, and if not, call the second judgment module;
[0056] The initialization module is used to initialize the State object and call the update module;
[0057] The second judgment module is used to judge whether the timestamp of the current data is less than or equal to the minimum value, and if so, call the first processing module, and if not, call the third judgment module;
[0058] The first processing module is used to place the timestamp of the current data at the head of the time chain table, set the minimum value as the timestamp of the current data, and call the update module;
[0059] The third judgment module is used to judge whether the timestamp of the current data is greater than the minimum value and less than the maximum value, and if so, call the second processing module, otherwise call the normal data processing module;
[0060] The second processing module is used to traverse the time chain table, insert the timestamp of the current data into the corresponding position of the time chain table in chronological order, and call the update module;
[0061] The normal data processing module is used to update the time chain table, the minimum value and the maximum value according to the size relationship between the timestamp of the current data and the first window value and the second window value, and call the update module; the first window value is the sum of the preset time window value and the minimum value, and the second window value is the sum of the preset time window value and the maximum value;
[0062] The updating module is used to update the indicator statistics.
[0063] Preferably, the normal data processing module includes a fourth judgment module, a fifth judgment module, a third processing module and a fourth processing module;
[0064] The fourth judgment module is used to judge whether the timestamp of the current data is greater than or equal to the second window value, and if so, call the initialization module, and if not, call the fifth judgment module;
[0065] The fifth judgment module is used to judge whether the timestamp of the current data is less than the first window value, and if so, call the third processing module, and if not, call the fourth processing module;
[0066] The third processing module is used to add the timestamp of the current data to the end of the time chain list, set the maximum value to the timestamp of the current data, and call the update module;
[0067] The fourth processing module is used to traverse the time linked list to find the data that has not expired, and set the timestamp of the data that has not expired to the minimum value, add the timestamp of the current data to the end of the time linked list, set the maximum value to the timestamp of the current data, and call the update module.
[0068] Preferably, the initialization module includes an initialization execution module, and the initialization execution module is used to initialize the State object;
[0069] The initialization execution module includes a linked list initialization module and a value initialization module;
[0070] The linked list initialization module is used to clear the time linked list and add the timestamp of the current data to the time linked list;
[0071] The numerical initialization module is used to set the maximum value and the minimum value as the timestamp of the current data and preset the indicator statistical value.
[0072] Preferably, the real-time processing module includes a first data generating module, a second data generating module and a first current data generating module;
[0073] The first data generating module is used to use the latest received data as the first data;
[0074] The second data generating module is used to convert the first data into second data of Tuple type by using a map operator;
[0075] The first current data generating module is used to use the second data as the current data.
[0076] Preferably, each piece of the data includes a number of indicator fields to be counted;
[0077] The real-time processing module includes a third data generating module, a fourth data generating module and a second current data generating module;
[0078] The third data generating module is used to use the latest received data as the third data;
[0079] The fourth data generating module is used to use the KeyBy operator to distribute the third data to different nodes according to the dimension of the indicator field to be counted, and the data distributed to the nodes is the fourth data;
[0080] The second current data generating module is used to use the fourth data as the current data.
[0081] Preferably, the indicator statistics system includes a plurality of the data receivers, and the plurality of the data receivers receive the data in parallel.
[0082] Preferably, the big data processing framework is Flink.
[0083] Preferably, the time linked list is a bidirectional linked list.
[0084] The present invention also provides a device for indicator statistics of a sliding window based on a big data processing framework, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the device implements the aforementioned indicator statistics method of a sliding window based on a big data processing framework when the processor executes the computer program.
[0085] The present invention also provides a computer-readable storage medium having a computer program stored thereon, wherein when the program is executed by a processor, the steps of the aforementioned indicator statistics method of a sliding window based on a big data processing framework are implemented.
[0086] The positive and progressive effects of the present invention are: the index statistics method, system, device and storage medium of the sliding window based on the big data processing framework provided by the present invention adopts the State object to store key parameters, and the key parameters include the time chain table, the minimum value of the time chain table, the maximum value of the time chain table and the index statistics value. The index statistics value is the final statistical result. The index statistics are only performed on the data in a time window each time, which avoids the defects of large amount of calculation and high delay caused by calculating the data of the entire window each time in the prior art. The present invention can respond to the statistical needs of the business more quickly by reusing the already calculated statistics to reduce the amount of calculation, improve the calculation speed and reduce the delay. Furthermore, it can accurately identify whether the data is expired, and the expired data will not be used for the calculation of the index statistics value; by expanding the detailed information of the historical data stored in the State object, the index statistics value can be traced back. BRIEF DESCRIPTION OF THE DRAWINGS
[0087] Figure 1 This is a flowchart of an indicator statistics method of a sliding window based on a big data processing framework according to Example 1 of the present invention.
[0088] Figure 2 This is a module diagram of an indicator statistics system of a sliding window based on a big data processing framework according to Example 2 of the present invention.
[0089] Figure 3 for Figure 2 Module diagram of the data processing module.
[0090] Figure 4 for Figure 3 Module diagram of the normal data processing module.
[0091] Figure 5 for Figure 3 Module diagram of the initialization module in .
[0092] Figure 6 for Figure 2 Module diagram of the real-time processing module.
[0093] Figure 7 This is a module diagram of the real-time processing module of the indicator statistics system of the sliding window based on the big data processing framework of Example 3 of the present invention.
[0094] Figure 8 This is a schematic diagram of the hardware structure of a device for index statistics of a sliding window based on a big data processing framework according to Example 4 of the present invention. DETAILED DESCRIPTION
[0095] The present invention is further described below by way of examples, but the present invention is not limited to the scope of the examples.
[0096] Example 1
[0097] like Figure 1 As shown, this embodiment provides an indicator statistics method for a sliding window based on a big data processing framework, wherein the big data processing framework is Flink. The method uses the State object in the mapWithState operator provided by Flink to store the following key parameters, namely, a time list, a minimum value of the time list, a maximum value of the time list, and an indicator statistics value; wherein the time list is a bidirectional linked list, which stores data in chronological order. Each time a search is performed, the fastest direction can be selected to locate the disordered data and expired data. The complexity of the insertion and deletion operations of the time list is O(1), which can improve the processing speed and efficiency.
[0098] The indicator statistics method provided in this embodiment includes the following steps:
[0099] Step 101, Flink uses multiple receivers to receive external data in parallel; each piece of data includes a field of the indicator to be counted and a corresponding timestamp, and the time linked list is used to store the timestamps of the data in chronological order;
[0100] Step 102: Take the latest received data as the first data, and use the map operator to convert the first data into the second data of Tuple type;
[0101] Step 103: Use the KeyBy operator to distribute the second data to different nodes according to the dimension of the indicator field to be counted, the data distributed to the node is the fourth data, and the fourth data is used as the current data;
[0102] Step 104, determine whether the current data is the first data received, if so, execute step 105, if not, execute step 106;
[0103] Step 105, initializing the State object, specifically including clearing the time chain table, adding the timestamp of the current data to the time chain table, setting the maximum and minimum values to the timestamp of the current data, presetting the indicator statistics, and ending the current data processing flow, and continuing to wait for the next received data;
[0104] Step 106, determine whether the timestamp of the current data is less than or equal to the minimum value, if yes, execute step 107, if no, execute step 108;
[0105] Step 107, placing the timestamp of the current data at the head of the time chain table, setting the minimum value as the timestamp of the current data, and executing step 114;
[0106] Step 108, determine whether the timestamp of the current data is greater than the minimum value and less than the maximum value, if so, execute step 109, if not, execute step 110;
[0107] Step 109, traverse the time chain table, insert the timestamp of the current data into the corresponding position of the time chain table according to the time sequence, and execute step 114;
[0108] Step 110, determine whether the timestamp of the current data is greater than or equal to the second window value, if yes, execute step 105, if no, execute step 111;
[0109] Step 111, determine whether the timestamp of the current data is less than the first window value, if yes, execute step 112, if no, execute step 113;
[0110] Step 112, add the timestamp of the current data to the end of the time chain list, set the maximum value to the timestamp of the current data, and execute step 114;
[0111] Step 113: traverse the time linked list to find the unexpired data, set the timestamp of the unexpired data as the minimum value, add the timestamp of the current data to the end of the time linked list, and set the maximum value as the timestamp of the current data;
[0112] Step 114: Update the indicator statistics, which are obtained by multiplexing calculation. The current data processing flow ends, and the next received data is continued to be waited for.
[0113] In this embodiment, the indicator fields to be counted vary according to different business requirements. The state storage and calculation operators provided by Flink have state information storage functions and can store user-specified data. In this embodiment, the State object is used to store the time chain table, the minimum value of the time chain table, the maximum value of the time chain table, and the indicator statistics. Among them, the time chain table is used to store the timestamps of the data in chronological order, and the timestamps are used to implement the disorder processing and expiration processing of the data one by one. The minimum and maximum values are used to implement the time switch mechanism, which is specifically used to determine the type of data currently arriving and use the most appropriate process to process the current data, which greatly reduces the amount of data calculation in the indicator statistics process and improves the response speed. The State object also stores the indicator statistics, which is the final statistical result. Each time, the indicator statistics are only performed for the data in a time window, avoiding the defects of large amount of calculation and high delay caused by calculating the data of the entire window each time in the prior art. This embodiment reduces the amount of calculation, improves the calculation speed, and reduces the delay by reusing the already calculated statistics.
[0114] In this embodiment, when the current data received is the first data to arrive, the State object is empty at this time, and the State object needs to be initialized, and the indicator statistics are preset to the corresponding initial value according to the specific meaning of the corresponding business. When other data arrives, it needs to be updated accordingly according to the specific situation. Specifically, when the timestamp of the current data is less than or equal to the minimum value, the timestamp of the current data is placed at the head of the time chain list, and the minimum value is set as the timestamp of the current data. At the same time, the indicator statistics need to be updated; when the timestamp of the current data is greater than the minimum value and less than the maximum value, it means that the current data is disordered data, and it needs to be inserted into the appropriate position in the time chain list. It can be traversed from the end of the chain list to the head, find a suitable position to insert the element, and update various parameters at the same time; when the timestamp of the current data is greater than or equal to the maximum value, it belongs to the data that arrives normally. At this time, it is necessary to update various parameters according to the size relationship between the timestamp and the first window value and the second window value. For data that arrives normally, it is divided into three situations for processing, specifically: when the timestamp of the current data is greater than or equal to the second window value, it means that all data are expired, and the State object is reinitialized at this time; when the timestamp of the current data is less than the first window value, it means that no data is expired, and the timestamp of the current data is added to the end of the time linked list, the maximum value is set to the timestamp of the current data, and the indicator statistics are updated; when the timestamp of the current data is between the first window value and the second window value, it means that some data is expired. The time linked list is the timestamp of all data stored by time, so the linked list is traversed from the head until the unexpired data is found, the timestamp of this data is set to the minimum value, and then the timestamp of the current data is added to the end of the linked list, the maximum value is set to the timestamp of the current data, and the indicator statistics are updated. The indicator statistics are the final statistical results.
[0115] In this embodiment, the big data processing framework receives external real-time data from different pipelines, and the use of parallel data reception can improve the overall throughput. Since the received data comes from different data sources, the data formats and contents are very different. In order to be processed in real time and efficiently, this embodiment standardizes the data format and converts different data contents into a unified Tuple data format through the map operator, which facilitates efficient data calculation.
[0116] In this embodiment, common statistical indicators are all counted based on a certain business dimension. In this embodiment, different dimensions are extended according to different business needs. For each piece of data, several indicator fields to be counted can be included. The KeyBy operator provided by the big data processing framework is used to divert the data to different nodes for statistics. The data is diverted according to the dimension of the indicator field to be counted to form a hash data stream. Distributing data of the same dimension to the same node and using multiple nodes to perform data processing can improve overall performance and throughput.
[0117] In this embodiment, the State object stores detailed information of historical data, and expands the indicator statistics of multiple indicator fields to be counted. Multiple indicators can be counted at the same time, which can improve efficiency. At the same time, because the State object stores detailed information of historical data, it can realize the backtracking of indicator statistical values.
[0118] Example 2
[0119] like Figure 2 As shown, the sliding window indicator statistics system based on the big data processing framework of this embodiment includes a parameter storage module 1, a data processing module 2 and a real-time processing module 3.
[0120] The big data processing framework is Flink, which includes multiple data receivers.
[0121] The parameter storage module 1 uses the State object in the mapWithState operator to store several parameters, including the time list, the minimum value of the time list, the maximum value of the time list, and the indicator statistics. Among them, the time list is a two-way linked list, which stores data in chronological order. Each time it is searched, it can choose the fastest direction to locate the disordered data and expired data. The complexity of the insertion and deletion operations of the time list is O(1), which can improve the processing speed and efficiency.
[0122] The multiple data receivers are used to receive data in parallel, each piece of data includes an indicator field to be counted and a corresponding timestamp, and the time linked list is used to store the timestamps of the data in chronological order.
[0123] The real-time processing module 3 is used to take the latest piece of data received as the current data.
[0124] The data processing module 2 is used to update the time chain table, minimum value, maximum value and indicator statistics according to the timestamp of the current data, the indicator field to be counted of the current data and the preset time window value. The indicator statistics are obtained by multiplexing calculation.
[0125] In this embodiment, the indicator fields to be counted vary according to different business requirements. The state storage and calculation operators provided by the big data processing framework have state information storage functions and can store user-specified data. In this solution, the State object is used to store the time list, the minimum value of the time list, the maximum value of the time list, and the indicator statistics. Among them, the time list is used to store the timestamps of the data in chronological order, and the timestamps are used to implement the disorder processing and expiration processing of the data one by one. The minimum and maximum values are used to implement the time switch mechanism, which is specifically used to determine the type of data currently arriving and use the most appropriate process to process the current data, which greatly reduces the amount of data calculation in the indicator statistics process and improves the response speed. The State object also stores the indicator statistics, which is the final statistical result. The indicator statistics are only performed on the data in a time window each time, and the calculated statistics can be reused to reduce the amount of calculation, improve the calculation speed, and reduce the delay.
[0126] like Figure 3 As shown, the data processing module 2 in this embodiment includes a first judgment module 201, an initialization module 202, a second judgment module 203, a first processing module 204, a third judgment module 205, a second processing module 206, a normal data processing module 207 and an update module 208.
[0127] The first judgment module 201 is used to judge whether the current data is the first data received by the data receiver, and if so, call the initialization module 202, and if not, call the second judgment module 203.
[0128] The initialization module 202 is used to initialize the State object and call the update module 208.
[0129] The second judgment module 203 is used to judge whether the timestamp of the current data is less than or equal to the minimum value, and if so, call the first processing module 204, and if not, call the third judgment module 205.
[0130] The first processing module 204 is used to place the timestamp of the current data at the head of the time chain list, set the minimum value as the timestamp of the current data, and call the updating module 208.
[0131] The third judgment module 205 is used to judge whether the timestamp of the current data is greater than the minimum value and less than the maximum value. If so, the second processing module 206 is called; otherwise, the normal data processing module 207 is called.
[0132] The second processing module 206 is used to traverse the time chain list, insert the timestamp of the current data into the corresponding position of the time chain list according to the time sequence, and call the updating module 208.
[0133] The normal data processing module 207 is used to update the time list, the minimum value and the maximum value according to the size relationship between the timestamp of the current data and the first window value and the second window value, and call the update module 208; the first window value is the sum of the preset time window value and the minimum value, and the second window value is the sum of the preset time window value and the maximum value.
[0134] The updating module 208 is used to update the indicator statistics.
[0135] In this embodiment, the data processing module uses different modules to implement different processing according to the different received data. When the current data received is the first data to arrive, the State object is empty at this time, and the initialization module needs to be used to initialize the State object. When other data arrives, it needs to be updated accordingly according to the specific situation. Specifically, when the timestamp of the current data is less than or equal to the minimum value, the first processing module is used to place the timestamp of the current data at the head of the time chain list, and the minimum value is set as the timestamp of the current data. At the same time, the indicator statistics need to be updated; when the timestamp of the current data is greater than the minimum value and less than the maximum value, it means that the current data is disordered data, and the second processing module needs to be used to insert it into the appropriate position in the time chain list. It can be traversed from the tail of the chain list to the head, find a suitable position to insert the element, and update various parameters at the same time; when the timestamp of the current data is greater than or equal to the maximum value, it belongs to the data that arrives normally. At this time, the normal data processing module needs to be used to update various parameters according to the size relationship between the timestamp and the first window value and the second window value.
[0136] like Figure 4 As shown, in this embodiment, the normal data processing module 207 includes a fourth judgment module 2071 , a fifth judgment module 2072 , a third processing module 2073 and a fourth processing module 2074 .
[0137] The fourth judgment module 2071 is used to judge whether the timestamp of the current data is greater than or equal to the second window value, and if so, call the initialization module 202, and if not, call the fifth judgment module 2072.
[0138] The fifth judgment module 2072 is used to judge whether the timestamp of the current data is less than the first window value, and if so, call the third processing module 2073, and if not, call the fourth processing module 2074.
[0139] The third processing module 2073 is used to add the timestamp of the current data to the end of the time linked list, set the maximum value to the timestamp of the current data, and call the updating module 208.
[0140] The fourth processing module 2074 is used to traverse the time linked list to find the data that has not expired, and set the timestamp of the data that has not expired to the minimum value, add the timestamp of the current data to the end of the time linked list, set the maximum value to the timestamp of the current data, and call the update module 208.
[0141] In this embodiment, for data that arrives normally, it is divided into three situations for processing, specifically: when the timestamp of the current data is greater than or equal to the second window value, it means that all data are expired, and the initialization module is called again to initialize the State object; when the timestamp of the current data is less than the first window value, it means that no data is expired, and the third processing module is required to add the timestamp of the current data to the end of the time linked list, set the maximum value to the timestamp of the current data, and update the indicator statistics; when the timestamp of the current data is between the first window value and the second window value, it means that some data is expired, and the time linked list is the timestamp of all data stored by time. Therefore, the fourth processing module is used to traverse the linked list from the head until the unexpired data is found, and the timestamp of this data is set to the minimum value, and then the timestamp of the current data is added to the end of the linked list, and the maximum value is set to the timestamp of the current data, and the indicator statistics are updated. The indicator statistics are the final statistical results.
[0142] like Figure 5 As shown, in this embodiment, the initialization module 202 includes an initialization execution module 2021, and the initialization execution module is used to initialize the State object.
[0143] The initialization execution module 2021 includes a linked list initialization module 20211 and a numerical value initialization module 20212 .
[0144] The linked list initialization module 20211 is used to clear the time linked list and add the timestamp of the current data to the time linked list.
[0145] The numerical initialization module 20212 is used to set the maximum value and the minimum value as the timestamp of the current data and preset the indicator statistical value.
[0146] like Figure 6 As shown, in this embodiment, the real-time processing module 3 includes a first data generating module 301 , a second data generating module 302 and a first current data generating module 303 .
[0147] The first data generating module 301 is used to take the latest received data as the first data.
[0148] The second data generating module 302 is configured to use a map operator to convert the first data into second data of a Tuple type.
[0149] The first current data generating module 303 is configured to use the second data as the current data.
[0150] In this embodiment, the received data comes from different data sources, and the formats and contents of the data are very different. In order to be processed in real time and efficiently, this embodiment uses a real-time processing module to unify the format of the data. Specifically, the second data generation module uses a map operator to convert different data contents into a unified Tuple data format, which facilitates efficient calculation of the data.
[0151] Example 3
[0152] Based on Example 2, each piece of data in this example includes several indicator fields to be counted. Figure 7 As shown, different from the real-time processing module 3 in Embodiment 2, the real-time processing module 3 in this embodiment includes a third data generating module 304 , a fourth data generating module 305 and a second current data generating module 306 .
[0153] The third data generating module 304 is configured to use the latest received data as the third data.
[0154] The fourth data generating module 305 is used to use the KeyBy operator to distribute the third data to different nodes according to the dimension of the indicator field to be counted, and the data distributed to the nodes is the fourth data.
[0155] The second current data generating module 306 is configured to use the fourth data as the current data.
[0156] Common statistical indicators are all based on a certain business dimension. In this embodiment, different dimensions are extended according to different business needs. For each piece of data, several indicator fields to be counted can be included. The real-time processing module uses the KeyBy operator provided by the big data processing framework to divert the data to different nodes for statistics, and divert the data according to the dimension of the indicator field to be counted to form a hash data stream. Distributing data of the same dimension to the same node and using multiple nodes to perform data processing can improve overall performance and throughput.
[0157] Example 4
[0158] Figure 8 A schematic diagram of the hardware structure of a device for index statistics of a sliding window based on a big data processing framework provided in Example 4 of the present invention. Figure 8 A block diagram of an exemplary indicator statistics device 80 suitable for implementing the embodiments of the present invention is shown. Figure 8 The device 80 for displaying the indicator statistics is merely an example and should not bring any limitation to the functions and scope of use of the embodiment of the present invention.
[0159] like Figure 8 As shown, the device 80 for measuring indicators statistics can be in the form of a general computing device, for example, it can be a server device. The components of the device 80 for measuring indicators statistics can include but are not limited to: at least one processor 81, at least one memory 82, and a bus 83 connecting different system components (including the memory 82 and the processor 81).
[0160] The bus 83 includes a data bus, an address bus, and a control bus.
[0161] The memory 82 may include a volatile memory, such as a random access memory (RAM) 821 and / or a cache memory 822 , and may further include a read-only memory (ROM) 823 .
[0162] The memory 82 may also include a program / utility 825 having a set (at least one) of program modules 824, such program modules 824 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0163] The processor 81 executes various functional applications and data processing by running the computer programs stored in the memory 82, such as the indicator statistics method provided in Example 1 of the present invention.
[0164] The device 80 for indicator statistics can also communicate with one or more external devices 84 (e.g., keyboards, pointing devices, etc.). Such communication can be performed through an input / output (I / O) interface 85. In addition, the device 80 for indicator statistics can also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) through a network adapter 86. As shown in the figure, the network adapter 86 communicates with other modules of the device 80 for indicator statistics through a bus 83. It should be understood that, although not shown in the figure, other hardware and / or software modules can be used in conjunction with the device 80 for indicator statistics, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID (disk array) systems, tape drives, and data backup storage systems, etc.
[0165] It should be noted that, although several units / modules or subunits / modules of the device for index statistics are mentioned in the above detailed description, this division is merely exemplary and not mandatory. In fact, according to the embodiments of the present application, the features and functions of two or more units / modules described above can be concretized in one unit / module. Conversely, the features and functions of one unit / module described above can be further divided into multiple units / modules to be concretized.
[0166] Example 5
[0167] This embodiment provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the steps of the indicator statistics method provided in Embodiment 1 are implemented.
[0168] The following is a more specific introduction to the application examples of the index statistics method and system of the sliding window based on the big data processing framework of the present invention, so as to better understand the present invention.
[0169] This application example takes access to clickstream data as an example to count the number of user clicks on the same IP (a protocol for interconnection between networks) within two hours (a preset time window value). This application example provides a millisecond-level sliding window real-time statistics system.
[0170] Some modules of this application example are introduced as follows:
[0171] 1. Source (Receiver): Flink receives external real-time data components such as Kafka (an open source stream processing platform), MQ (an instant messaging software), and other pipelines. In order to improve the overall throughput of the system, multiple receivers are usually used to receive data in parallel. Therefore, even if the external real-time data arrives in chronological order, the data received by Flink may be out of order. In order to ensure the correct statistics of indicators related to time sequence (such as the variance statistics of adjacent time intervals), it is necessary to process the out-of-order data.
[0172] 2. Tuple data stream: The data received by the receiver comes from different data sources. The data formats and contents are very different. In order to be efficiently processed by the real-time system, this application example standardizes the data format and converts different data contents into a unified Tuple data format through the map operator to facilitate efficient data calculation.
[0173] 3. KeyedStream (hash data stream): Common statistical indicators are all based on a certain business dimension. This application example uses the IP dimension for statistics (depending on different business needs, it can be extended to different dimensions). Therefore, the data needs to be diverted to different nodes for statistics. The KeyBy operator provided by Flink can achieve this function and divert the data according to the dimension field to form a hash data stream.
[0174] 4. mapWithState (state and result calculation): The state storage and calculation operator provided by Flink has the function of storing state information and can store user-specified data. In this application example, the State object stores the timestamp information of the click stream data to implement out-of-order processing and item-by-item expiration functions. At the same time, the State object stores statistical value information. By reusing the statistical value, the statistical indicators can be quickly calculated and updated.
[0175] Now let's introduce the overall process: Flink receives real-time data through Source, transforms the original data, and uses the map operator to transform the data into a Tuple type. Taking clickstream data as an example, assemble a Tuple type data stream of device fingerprint IP, account, and timestamp. Most statistical values are statistics relative to a certain dimension, so the KeyBy operator can be used to distribute data of the same dimension to the same partition, and data processing can be performed on multiple partitions to improve system performance and throughput. In the application example, sliding window statistics are performed on clickstream data by IP dimension.
[0176] After partitioning, each partition receives the data to be processed, and uses the mapWithState operator combined with the stored state information to calculate the statistical value in real time, as follows:
[0177] The format of the received data is (ip, account, time), and the meaning of each field is as follows:
[0178] 1) ip: the ip information attached to the current click stream;
[0179] 2)account: user name information of the current click stream;
[0180] 3) time: the time when the current click stream is generated.
[0181] The State object in the mapWithState operator stores several key indicators, as follows:
[0182] 1) dataList: a two-way linked list that stores the timestamps of all data on the corresponding IP in chronological order. Using a two-way linked list, the linked list can be traversed from both ends to improve processing speed;
[0183] 2) s: the minimum value in the time list, the time switch mechanism, reduces the amount of data processed;
[0184] 3) e: the maximum value in the time list, the time switch mechanism;
[0185] 4)value: indicator statistical value.
[0186] When the first data in a dimension arrives, the State object is empty and needs to be initialized. State initialization process: clear dataList, add the timestamp attached to the current message to the linked list, set s and e to the value, and set value to the initial value according to the business meaning of the statistical indicator.
[0187] When other data under this dimension arrives, it is processed according to the following process:
[0188] 1. When time (the timestamp attached to the message) <= s, the current message timestamp is placed at the head of the linked list, s=time is updated, and value is updated at the same time;
[0189] 2. When e>time>s, the current message is an out-of-order message and needs to be inserted into the appropriate position in the linked list. The entire system is connected to a real-time stream, and out-of-order data will not be delayed for a long time. Therefore, you can traverse from the end of the linked list to the head to find a suitable position to insert the element and update the value at the same time;
[0190] 3. When time>=e, the data is normal arrival and is processed in three cases:
[0191] 1) time >= e + window (preset time window value): All data has expired, perform the State initialization operation described above;
[0192] 2) time < s + window: No data has expired. Add the timestamp of the current message to the end of the linked list, set e = time, and update value;
[0193] 3) e + window > time > s + window: Some data has expired. Since the linked list stores the timestamps of all messages in chronological order, traverse the linked list from the head until an unexpired data is found. Set this data as s, update value, then add the current message timestamp to the end of the linked list, set e = time, and update value.
[0194] Finally, output the value of value to the downstream to obtain the statistical result.
[0195] This application example fully reuses the calculated statistical values, reducing the amount of calculation; the real-time metric processing delay is within 20 ms (milliseconds); the data expires precisely, and the expired data does not participate in the metric statistics; by expanding the detailed information stored in the State object, metric backtracking is supported. Among them, metric backtracking refers to backtracking the data before meeting the threshold condition. Taking the example of counting users with different user numbers greater than or equal to 5 on a certain IP, when the number of different users is less than 5, these users do not meet the conditions. When another different user enters the statistics and meets the threshold condition, ordinary statistical calculations will only output the users after meeting the threshold, and the users who participated in the accumulation before cannot be backtracked. The backtracking function means that the metrics that participated in the accumulation before meeting the threshold condition are also output.
[0196] Although the specific implementation manners of the present invention are described above, those skilled in the art should understand that this is only an example. The protection scope of the present invention is defined by the appended claims. Without departing from the principles and essence of the present invention, those skilled in the art can make various changes or modifications to these implementation manners, but these changes and modifications all fall within the protection scope of the present invention.
Claims
1. A sliding window index statistics method based on a big data processing framework, characterized in that: Use the State object in the mapWithState operator to store several parameters, including a time list, a minimum value of the time list, a maximum value of the time list, and an indicator statistical value; The indicator statistical method comprises the following steps: The big data processing framework receives data, each piece of the data includes a to-be-counted indicator field and a corresponding timestamp, and the time linked list is used to store the timestamps of the data in chronological order; Taking the latest piece of data received as current data; The time chain table, the minimum value, the maximum value and the indicator statistical value are updated according to the timestamp of the current data, the indicator field to be counted of the current data and the preset time window value, and the indicator statistical value is obtained by multiplexing calculation, specifically including the following steps: S1, determine whether the current data is the first data received, if yes, execute step S2, if no, execute step S3; S2, initialize the State object and execute step S8; S3, determining whether the timestamp of the current data is less than or equal to the minimum value, if so, executing step S4, if not, executing step S5; S4, placing the timestamp of the current data at the head of the time chain table, setting the minimum value as the timestamp of the current data, and executing step S8; S5, determining whether the timestamp of the current data is greater than the minimum value and less than the maximum value, if so, executing step S6, if not, executing step S7; S6, traverse the time chain table, insert the timestamp of the current data into the corresponding position of the time chain table in chronological order, and execute step S8; S7, update the time chain table, the minimum value and the maximum value according to the size relationship between the timestamp of the current data and the first window value and the second window value, and execute step S8; the first window value is the sum of the preset time window value and the minimum value, and the second window value is the sum of the preset time window value and the maximum value; S8. Update the indicator statistics.
2. The index statistics method of sliding window based on big data processing framework according to claim 1 is characterized in that: Step S7 includes the following steps: S 71 , determine whether the timestamp of the current data is greater than or equal to the second window value, if so, execute step S2, if not, execute step S 72 ; S 72 , determine whether the timestamp of the current data is less than the first window value, if so, execute step S 73 , if otherwise, execute step S 74 ; S 73 , adding the timestamp of the current data to the end of the time linked list, setting the maximum value to the timestamp of the current data, and executing step S8; S 74 , traverse the time linked list to find the data that has not expired, and set the timestamp of the data that has not expired to the minimum value, add the timestamp of the current data to the end of the time linked list, set the maximum value to the timestamp of the current data, and execute step S8.
3. The index statistics method of sliding window based on big data processing framework according to claim 1 is characterized in that: Initializing the State object in step S2 includes the following steps: Clear the time chain table, add the timestamp of the current data to the time chain table, set the maximum value and the minimum value to the timestamp of the current data, and preset the indicator statistical value.
4. The index statistics method of sliding window based on big data processing framework according to claim 1 is characterized in that: in, The latest received data is used as the current data, specifically including the following steps: T1, taking the latest received data as the first data; T2. Use the map operator to convert the first data into second data of Tuple type; T3. Use the second data as the current data.
5. The index statistics method of sliding window based on big data processing framework according to claim 1 is characterized in that: Each piece of data includes several indicator fields to be counted; The method of taking the latest received data as the current data specifically includes the following steps: U1, taking the latest received data as the third data; U2. Use the KeyBy operator to distribute the third data to different nodes according to the dimension of the indicator field to be counted, and the data distributed to the nodes is the fourth data; U3. Use the fourth data as the current data.
6. The index statistics method of a sliding window based on a big data processing framework according to any one of claims 1 to 5, characterized in that: The big data processing framework receives the data in a parallel manner.
7. The index statistics method of sliding window based on big data processing framework according to claim 6 is characterized in that: The big data processing framework is Flink.
8. The index statistics method of sliding window based on big data processing framework according to claim 7 is characterized in that: The time linked list is a bidirectional linked list.
9. A sliding window indicator statistics system based on a big data processing framework, characterized in that: It includes parameter storage module, data processing module and real-time processing module; The big data processing framework includes a data receiver; The parameter storage module uses the State object in the mapWithState operator to store several parameters, including a time chain list, a minimum value of the time chain list, a maximum value of the time chain list, and an indicator statistical value; The data receiver is used to receive data, each piece of the data includes a to-be-counted indicator field and a corresponding timestamp, and the time linked list is used to store the timestamps of the data in chronological order; The real-time processing module is used to take the latest received data as current data; The data processing module is used to update the time chain table, the minimum value, the maximum value and the indicator statistical value according to the timestamp of the current data, the indicator field to be counted of the current data and the preset time window value, and the indicator statistical value is obtained by multiplexing calculation; The data processing module includes an update module, a first judgment module, an initialization module, a second judgment module, a first processing module, a third judgment module, a second processing module and a normal data processing module; The first judgment module is used to judge whether the current data is the first data received by the data receiver, and if so, call the initialization module, and if not, call the second judgment module; The initialization module is used to initialize the State object and call the update module; The second judgment module is used to judge whether the timestamp of the current data is less than or equal to the minimum value, and if so, call the first processing module, and if not, call the third judgment module; The first processing module is used to place the timestamp of the current data at the head of the time chain table, set the minimum value as the timestamp of the current data, and call the update module; The third judgment module is used to judge whether the timestamp of the current data is greater than the minimum value and less than the maximum value, and if so, call the second processing module, otherwise call the normal data processing module; The second processing module is used to traverse the time chain table, insert the timestamp of the current data into the corresponding position of the time chain table according to the time sequence, and call the update module; The normal data processing module is used to update the time chain table, the minimum value and the maximum value according to the size relationship between the timestamp of the current data and the first window value and the second window value, and call the update module; The first window value is the sum of the preset time window value and the minimum value, and the second window value is the sum of the preset time window value and the maximum value; The updating module is used to update the indicator statistics.
10. The index statistics system of sliding window based on big data processing framework according to claim 9, characterized in that: The normal data processing module includes a fourth judgment module, a fifth judgment module, a third processing module and a fourth processing module; The fourth judgment module is used to judge whether the timestamp of the current data is greater than or equal to the second window value, and if so, call the initialization module, and if not, call the fifth judgment module; The fifth judgment module is used to judge whether the timestamp of the current data is less than the first window value, and if so, call the third processing module, and if not, call the fourth processing module; The third processing module is used to add the timestamp of the current data to the end of the time chain list, set the maximum value to the timestamp of the current data, and call the update module; The fourth processing module is used to traverse the time linked list to find the data that has not expired, and set the timestamp of the data that has not expired to the minimum value, add the timestamp of the current data to the end of the time linked list, set the maximum value to the timestamp of the current data, and call the update module.
11. The index statistics system of sliding window based on big data processing framework according to claim 9, characterized in that: The initialization module includes an initialization execution module, and the initialization execution module is used to initialize the State object; The initialization execution module includes a linked list initialization module and a value initialization module; The linked list initialization module is used to clear the time linked list and add the timestamp of the current data to the time linked list; The numerical initialization module is used to set the maximum value and the minimum value as the timestamp of the current data and preset the indicator statistical value.
12. The index statistics system of sliding window based on big data processing framework according to claim 9, characterized in that: The real-time processing module includes a first data generating module, a second data generating module and a first current data generating module; The first data generating module is used to use the latest received data as the first data; The second data generating module is used to convert the first data into second data of Tuple type by using a map operator; The first current data generating module is used to use the second data as the current data.
13. The index statistics system of sliding window based on big data processing framework according to claim 9, characterized in that: Each piece of data includes several indicator fields to be counted; The real-time processing module includes a third data generating module, a fourth data generating module and a second current data generating module; The third data generating module is used to use the latest received data as the third data; The fourth data generating module is used to use the KeyBy operator to distribute the third data to different nodes according to the dimension of the indicator field to be counted, and the data distributed to the nodes is the fourth data; The second current data generating module is used to use the fourth data as the current data.
14. The index statistics system of sliding window based on big data processing framework according to any one of claims 9 to 13, characterized in that: The indicator statistics system includes a plurality of data receivers, and the plurality of data receivers receive the data in parallel.
15. The index statistics system of sliding window based on big data processing framework according to claim 14, characterized in that: The big data processing framework is Flink.
16. The index statistics system of sliding window based on big data processing framework according to claim 15, characterized in that: The time linked list is a bidirectional linked list.
17. A device for index statistics of a sliding window based on a big data processing framework, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the indicator statistics method of the sliding window based on the big data processing framework described in any one of claims 1 to 8 is implemented.
18. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the indicator statistics method of a sliding window based on a big data processing framework as described in any one of claims 1 to 8 are implemented.
