Real-time data statistics device and method and computer-readable storage medium

Through the combination of the multi-level statistical module and the in-memory database Redis, the decentralized storage and processing of data is realized, which solves the problem of performance degradation in traditional real-time data statistics methods and improves the efficiency of real-time data statistics.

CN110471943BActive Publication Date: 2024-09-20BEIJING JINGDONG SHANGKE INFORMATION TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN201810434471.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2018-05-09
Publication Date
2024-09-20
Estimated Expiration
2038-05-09

AI Technical Summary

Technical Problem

In the environment of massive real-time data, traditional real-time data statistics methods have complex statistical logic calculations, which leads to a decrease in database computing and reading and writing performance, making it difficult to improve the efficiency of real-time data statistics.

Method used

It adopts a multi-level statistical module architecture, including a first-level statistical module, a second-level statistical module and a third-level statistical module. Data is stored and processed through the first-level cache unit and the second-level cache unit, and the in-memory database Redis is used to achieve uniform multi-point data distribution to improve statistical efficiency.

Benefits of technology

Through multi-level processing and decentralized storage of data, uniform multi-point distribution of data is achieved, which improves the efficiency of real-time data statistics and avoids database performance degradation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN110471943B
    Figure CN110471943B
Patent Text Reader

Abstract

The present invention discloses a real-time data statistics device and method and a computer-readable storage medium, and relates to the field of real-time data processing. The real-time data statistics device includes: a first-level statistics module, configured to use a preset time granularity to perform statistics on the acquired raw data, generate intermediate statistics including statistical items and statistical result fields in the raw data, and write the intermediate statistics into a first-level cache unit; a second-level statistics module, configured to read intermediate statistics in multiple first-level cache units, and write intermediate statistics with the same statistical item value into the same second-level cache unit; a third-level statistics module, configured to perform statistics on the data in each second-level cache unit, generate final statistics, and persistently store the final statistics generated by each second-level cache unit. The present invention realizes uniform multi-point distribution of data by performing multi-level processing on data, and improves the efficiency of real-time data statistics.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of real-time data processing, and in particular to a real-time data statistics device and method and a computer-readable storage medium. Background Art

[0002] For real-time statistics of massive data, traditional real-time data statistics methods are mostly based on batch processing mode, and real-time data streams need to be stored in the database management system in advance before subsequent statistical calculations can be performed. Related technologies mainly use relational databases, such as Oracle, MySQL, etc. to store raw data streams, and write corresponding SQL (Structured Query Language) statements and statistical scripts according to data statistical logic, and save the final statistical results obtained by the statistical script to the database. However, in the environment of massive real-time data, the statistical logic calculation of related technologies is relatively complex, resulting in a decrease in database calculation and read and write performance. Summary of the invention

[0003] A technical problem to be solved by the embodiments of the present invention is: how to improve the efficiency of real-time data statistics.

[0004] According to a first aspect of some embodiments of the present invention, there is provided a real-time data statistics device, including: a first-level statistics module, configured to perform statistics on the acquired original data with a preset time granularity, generate intermediate statistical data including statistical items and statistical result fields in the original data, and write the intermediate statistical data into a first-level cache unit; a second-level statistics module, configured to read the intermediate statistical data in multiple first-level cache units, and write the intermediate statistical data with the same statistical item value into the same second-level cache unit; a third-level statistics module, configured to perform statistics on the data in each second-level cache unit, generate final statistical data, and persistently store the final statistical data generated by each second-level cache unit.

[0005] In some embodiments, the primary statistical module, the secondary statistical module, and the tertiary statistical module are executed in parallel.

[0006] In some embodiments, the first-level statistical module includes multiple first-level statistical processes, each of which is configured to obtain raw data from a data source pre-associated with the first-level statistical process; or, the second-level statistical module includes multiple second-level statistical processes, each of which is configured to read intermediate statistical data from a first-level cache unit pre-associated with the second-level statistical process; or, the third-level statistical module includes multiple third-level statistical processes, each of which is configured to count the data in each second-level cache unit pre-associated with the third-level statistical process, and the number of third-level statistical processes is equal to the number of second-level cache units.

[0007] In some embodiments, the real-time data statistics device also includes: a main process unit located in one or more of the first-level statistical module, the second-level statistical module, and the third-level statistical module, configured to read the configuration information of the configuration center, and create, monitor, rebuild, or destroy one or more of the first-level statistical process of the first-level statistical module, the second-level statistical process of the second-level statistical module, and the third-level statistical process of the third-level statistical module according to the configuration information.

[0008] In some embodiments, the first-level cache unit is a queue type; or, the second-level cache unit is an ordered set type; the second-level statistical module is further configured to add a universal unique identifier field and value to the intermediate statistical data.

[0009] In some embodiments, the first-level statistics module is further configured to write each intermediate statistical data into one of the plurality of first-level cache units in a random polling manner.

[0010] In some embodiments, the secondary statistics module is further configured to calculate a hash value of a value of a statistical item of each intermediate statistical data, and write intermediate statistical data having the same calculated hash value into the same secondary cache unit.

[0011] In some embodiments, the real-time data statistics device also includes one or more of a first-level cache unit, a second-level cache unit, and a configuration center; wherein the configuration center is configured to store configuration information of a first-level statistical module, a second-level statistical module, and a third-level statistical module.

[0012] In some embodiments, the first-level cache unit and the second-level cache unit are nodes of the in-memory database Redis.

[0013] According to a second aspect of some embodiments of the present invention, a real-time data statistics method is provided, including: a first-level statistics module uses a preset time granularity to perform statistics on the acquired original data, generates intermediate statistical data including statistical items and statistical result fields in the original data, and writes the intermediate statistical data into a first-level cache unit; a second-level statistics module reads the intermediate statistical data in multiple first-level cache units, and writes the intermediate statistical data with the same statistical item value into the same second-level cache unit; a third-level statistics module performs statistics on the data in each second-level cache unit, generates final statistical data, and persistently stores the final statistical data generated by each second-level cache unit.

[0014] In some embodiments, the primary statistical module, the secondary statistical module, and the tertiary statistical module are executed in parallel.

[0015] In some embodiments, the first-level statistical module includes multiple first-level statistical processes, each of which obtains raw data from a data source pre-associated with the first-level statistical process; or, the second-level statistical module includes multiple second-level statistical processes, each of which reads intermediate statistical data from a first-level cache unit pre-associated with the second-level statistical process; or, the third-level statistical module includes multiple third-level statistical processes, each of which respectively counts the data in each second-level cache unit pre-associated with the third-level statistical process, and the number of third-level statistical processes is equal to the number of second-level cache units.

[0016] In some embodiments, the real-time data statistics method also includes: a main process unit located in one or more of the first-level statistical module, the second-level statistical module, and the third-level statistical module, configured to read the configuration information of the configuration center, and create, monitor, rebuild, or destroy one or more of the first-level statistical process of the first-level statistical module, the second-level statistical process of the second-level statistical module, and the third-level statistical process of the third-level statistical module according to the configuration information.

[0017] In some embodiments, the first-level cache unit is a queue type; or, the second-level cache unit is an ordered set type; the real-time data statistics method also includes: the second-level statistics module adds a universal unique identification code field and value to the intermediate statistical data.

[0018] In some embodiments, the first-level statistics module writes each intermediate statistical data into one of the plurality of first-level cache units in a random polling manner.

[0019] In some embodiments, the secondary statistical module calculates a hash value of the value of the statistical item of each intermediate statistical data, and writes the intermediate statistical data with the same calculated hash value into the same secondary cache unit.

[0020] In some embodiments, the first-level cache unit and the second-level cache unit are nodes of the in-memory database Redis.

[0021] According to a third aspect of some embodiments of the present invention, there is provided a real-time data statistics device, comprising: a memory; and a processor coupled to the memory, wherein the processor is configured to execute any one of the aforementioned real-time data statistics methods based on instructions stored in the memory.

[0022] According to a fourth aspect of some embodiments of the present invention, there is provided a computer-readable storage medium having a computer program stored thereon, wherein the program implements any one of the aforementioned real-time data statistics methods when executed by a processor.

[0023] Some embodiments of the above invention have the following advantages or beneficial effects: the present invention can first disperse the statistics of the original data, then disperse the data according to the values ​​of the statistical items, and finally count the dispersedly stored data to obtain the final statistical results. Through multi-level processing of the data, uniform multi-point distribution of the data is achieved, thereby improving the efficiency of real-time data statistics.

[0024] Further features and advantages of the present invention will become apparent from the following detailed description of exemplary embodiments of the present invention with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] 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 some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0026] Figure 1 is an exemplary structural diagram of a real-time data statistics device according to some embodiments of the present invention.

[0027] Figure 2 is an exemplary structural diagram of a primary statistical module and related modules according to some embodiments of the present invention.

[0028] Figure 3 is an exemplary structural diagram of a secondary statistical module and related modules according to some embodiments of the present invention.

[0029] Figure 4 4 is an exemplary structural diagram of a three-level statistical module and related modules according to some embodiments of the present invention.

[0030] Figure 5 1 is an exemplary structural diagram of a real-time data statistics device according to some other embodiments of the present invention.

[0031] Figure 6 The figure is an exemplary flow chart of a real-time data statistics method according to some embodiments of the present invention.

[0032] Figure 7 The figure is an exemplary flow chart of a real-time data statistics method according to some other embodiments of the present invention.

[0033] Fig. 8A is an exemplary flow chart of a primary statistics module processing method according to some embodiments of the present invention.

[0034] Figure 8B and 8C is an exemplary flow chart of a secondary statistics module processing method according to some embodiments of the present invention.

[0035] Fig. 9A and 9B is an exemplary flow chart of a processing method within each layer according to some embodiments of the present invention.

[0036] Fig.10 is an exemplary structural diagram of a real-time data statistics device according to some further embodiments of the present invention.

[0037] Fig.11 1 is an exemplary structural diagram of a real-time data statistics device according to some further embodiments of the present invention. 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, rather than all the embodiments. The following description of at least one exemplary embodiment is actually only illustrative and is by no means intended to limit the present invention and its application or use. 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] The relative arrangement of components and steps, the numerical expressions and numerical values ​​set forth in these embodiments do not limit the scope of the present invention unless specifically stated otherwise.

[0040] At the same time, it should be understood that for the convenience of description, the sizes of the various parts shown in the drawings are not drawn according to the actual proportional relationship.

[0041] Technologies, methods, and apparatus known to ordinary technicians in the relevant field may not be discussed in detail, but where appropriate, such technologies, methods, and apparatus should be considered part of the authorization specification.

[0042] In all examples shown and discussed herein, any specific values ​​should be interpreted as merely exemplary and not as limiting. Therefore, other examples of the exemplary embodiments may have different values.

[0043] It should be noted that like reference numerals and letters refer to similar items in the following figures, and therefore, once an item is defined in one figure, it need not be further discussed in subsequent figures.

[0044] Figure 1 FIG. 1 is an exemplary structural diagram of a real-time data statistics device according to some embodiments of the present invention. Figure 1 As shown, the real-time data statistics device 10 of this embodiment includes a primary statistics module 110, a secondary statistics module 120 and a tertiary statistics module 130. The real-time data statistics device 10 can be implemented based on a memory.

[0045] The first-level statistical module 110 is configured to use a preset statistical granularity to perform statistics on the acquired raw data, generate intermediate statistical data including statistical items and statistical result fields in the raw data, and write the intermediate statistical data into a first-level cache unit. There are multiple first-level cache units, which can be nodes of a memory database. The statistical items are fields in the raw data and are fields required in the data statistics process, for example, timestamps, data source identifiers, data types, data volumes, etc.

[0046] The original data can be obtained by the primary statistical module from the data source, and the data source can be distributed on one or more devices in various forms. The original data can include multiple fields. When obtaining data, the primary statistical module can obtain all fields from the data source, or only some of the fields required for statistics, that is, statistical items.

[0047] The time granularity is used to determine the amount of data that the primary statistical module 110 performs a single statistical operation. For example, when the statistical granularity is one minute, the primary statistical module obtains data generated within one minute for statistical operation. Other statistical granularities may also be set as needed, which will not be described in detail here.

[0048] The statistical result field may be, for example, the number of data at the current statistical granularity, the average value of a certain field, etc. The field may be a field that exists in the original data, or may not exist in the original data.

[0049] For example, the data to be counted obtained by the first-level statistics module within a time granularity is shown in Table 1. The time span involved in the time granularity is represented by a timestamp as [1524477300, 1524477360]. In Table 1, id represents the data source identifier, and ts represents the timestamp.

[0050] Table 1

[0051] id ts 1 1524477303 1 1524477308 1 1524477346 1 1524477361

[0052] If the statistical field is the total amount of data, expressed as amount, the intermediate statistical data can be: {id=1,ts=1524477300,amout=4}, indicating that 4 data were obtained from the data source identified as 1 during the period corresponding to timestamp 1524477300. The ts in this exemplary statistical result uses the first timestamp corresponding to the time granularity. If needed, it can also be expressed in the last timestamp of the time granularity or time range, etc., which will not be repeated here.

[0053] In some embodiments, the intermediate statistical data generated by the primary statistical module may be of a map (hash) type, such as a map container in an STL (Standard Template Library). That is, it is stored in the form of key-value. The key stores the value of the statistical item, and the value stores the value of the statistical result field. Therefore, the above statistical results may be represented as {key:1+1524477300, value:4} using a map type.

[0054] The secondary statistical module 120 is configured to read the intermediate statistical data in multiple primary cache units, and write the intermediate statistical data with the same statistical item value into the same secondary cache unit, that is, write the intermediate statistical data with the same value of the same dimension into the same secondary cache unit. Thus, each secondary cache unit stores data with the field value concerned by the same key, so as to facilitate subsequent statistics. The secondary cache unit can be a node of an in-memory database.

[0055] For example, assume that the intermediate statistical data acquired by the secondary statistical module 120 is as shown in Table 2. In Table 2, id represents a data source identifier, type represents a type, ts represents a timestamp, and amount is a statistical result field, representing the data amount.

[0056] Table 2

[0057] id type ts amount 1 1 1524477300 42 1 1 1524477300 7 1 2 1524477480 15 1 2 1524477480 63

[0058] Then the first two pieces of data in Table 2 can be written into the secondary cache unit A, and the last two pieces of data can be written into the secondary cache unit B. Moreover, the statistical items of the data in the secondary cache unit A are all {id=1, type=1, ts=1524477300}, and the statistical items of the data in the secondary cache unit B are all {id=1, type=2, ts=1524477480}.

[0059] In some embodiments, the secondary statistics module 120 may be further configured to calculate the hash value of the statistical item of each intermediate statistical data, and write the intermediate statistical data with the same calculated hash value into the same secondary cache unit. The hash algorithm may be, for example, MurmurHash (non-encrypted hash function), MD5 (Message-Digest Algorithm 5), SHA (Secure Hash Algorithm), etc. MurmurHash is a non-encrypted hash function suitable for general hash retrieval operations. For key values ​​with strong regularity, the random distribution characteristics of MurmurHash perform better.

[0060] In some embodiments, similar to the first-level cache unit, each data in the second-level cache unit may also be of a map type. In this case, a hash operation may be directly performed on the key of the data to obtain the hash value of the key of the statistical item.

[0061] The third-level statistical module 130 is configured to collect statistics on the data in each second-level cache unit, generate final statistical data, and persistently store the final statistical data generated by each second-level cache unit, for example, the final statistical data can be stored in an external memory.

[0062] Since the data stored in the same L2 cache unit has the same statistical item key, the data in each L2 cache unit can be quickly aggregated and counted to obtain the final statistical result.

[0063] The third-level statistics module 130 can count all data in the corresponding second-level cache unit, or divide the data in a second-level cache unit into multiple parts for retrospective aggregation statistics as needed. For example, the data in the second-level cache unit can be counted at a granularity of 5 minutes and a statistical result can be generated.

[0064] Through the above embodiments, the present invention can first disperse the statistics of the original data, then disperse the data according to the values ​​of the statistical items, and finally count the dispersedly stored data to obtain the final statistical results. Through multi-level processing of the data, the uniform multi-point distribution of the data is achieved, thereby improving the efficiency of real-time data statistics.

[0065] In some embodiments, the primary statistical module, the secondary statistical module, and the tertiary statistical module are executed in parallel. Although the same piece of data flows from the primary statistical module to the secondary statistical module and then to the tertiary statistical module, while the secondary statistical module is processing the acquired data, the primary statistical module obtains updated data, and the secondary statistical module is processing the data acquired earlier. Thus, the present invention can make statistical modules belonging to different levels and performing different processing execute in parallel, further improving the efficiency of data statistics.

[0066] In some embodiments, one or more of the primary statistical module, the secondary statistical module, and the tertiary statistical module may include multiple statistical processes so as to perform parallel processing within each level to further improve data statistical efficiency. The following is an introduction to exemplary implementations of statistical modules at each level.

[0067] Reference below Figure 2 The embodiments of the primary statistical module and related modules of the present invention are described.

[0068] Figure 2 FIG. 1 is an exemplary structural diagram of a primary statistical module and related modules according to some embodiments of the present invention. Figure 2 As shown, the primary statistical module 210 of this embodiment obtains data from data sources 2001, 2002...200M, and the primary statistical module 210 includes multiple primary statistical processes 2101, 2102, 2003...210N, which are configured to obtain raw data from data sources pre-associated with the primary statistical processes. M and N are both positive integers. For example, the primary statistical processes 2101 and 2102 are associated with the data source 2001, and the two primary statistical processes obtain data from the data source 2001 when running. When creating each primary statistical process, the corresponding relationship between the primary statistical process and the data source can be configured, and the corresponding relationship can be read from the configuration center.

[0069] After each first-level statistical process counts the original data, it writes the generated intermediate statistical data into the first-level cache units 2111, 2112, ..., 211K, where K is a positive integer. Each first-level statistical process can randomly store the intermediate statistical data into a certain first-level cache unit.

[0070] In some embodiments, the first-level statistical module is further configured to write each intermediate statistical data into one of the multiple first-level cache units in a random polling manner. That is, each first-level statistical process in the first-level statistical module can be further configured to write each intermediate statistical data into one of the multiple first-level cache units in a random polling manner. Random polling means starting writing from a random position in the list of the first-level cache unit, polling the list of the first-level cache units one by one, and writing the data into the first-level cache unit in sequence. If writing to the current first-level cache unit fails, writing to the next first-level cache unit, thereby ensuring load balancing and improving the efficiency of data statistics.

[0071] In some embodiments, the first-level cache unit can be of queue type. The characteristic of the queue is first-in-first-out, so the embodiments of the present invention can make use of this characteristic of the queue, so that the first-level statistical module writes data at the head of the queue, that is, the Push method of the queue is used to add data, and then the second-level statistical module reads data at the tail of the queue, that is, the Pop method of the queue is used to take out data. Therefore, the processing processes of the first-level statistical module and the second-level statistical module do not interfere with each other. The same queue can be consumed by multiple second-level statistical processes. The simultaneous consumption of multiple statistical processes will further avoid data backlogs in the queue, avoid performance degradation, and improve statistical efficiency.

[0072] Reference below Figure 3 Describe the embodiments of the secondary statistics module and related modules of the present invention.

[0073] Figure 3 FIG. 4 is an exemplary structural diagram of a secondary statistical module and related modules according to some embodiments of the present invention. Figure 3As shown, the secondary statistical module 320 of this embodiment includes multiple secondary statistical processes 3201, 3202, 3203...320P, P is a positive integer, and each secondary statistical process is configured to read intermediate statistical data from the primary cache unit pre-associated with the secondary statistical process. For example, the secondary statistical process 3201 reads data from the primary cache unit 3111, and the secondary statistical processes 3202 and 3203 read data from the primary cache unit 3112. Then, each secondary statistical process writes the intermediate statistical data with the same value of the statistical item into the same secondary cache unit, such as one of the secondary cache units 3211, 3212... When creating each secondary statistical process, the corresponding relationship between the secondary statistical process and the primary cache unit can be configured, and the corresponding relationship can be read from the configuration center.

[0074] In some embodiments, the secondary cache unit can be of ordered set type. The data in the ordered set (Sortedset) is stored in order, and the elements in the set can be sorted according to the score value (score). The field representing the score value can be selected as needed, for example, it can be a timestamp. In some embodiments, two identical data are not allowed to appear in the ordered set, and in fact, the two data may have exactly the same value. In order to make this distinction, the secondary statistical module can be further configured to add a universally unique identifier (UUID, Universally Unique Identifierb) field and the value of the field to the intermediate statistical data, so that there are no two identical data in the set. By using the data type of the ordered set to store data, the calculation speed of the next aggregate statistics can be increased, and the efficiency of data statistics is improved.

[0075] Reference below Figure 4 An embodiment of the three-level statistical module and related modules of the present invention is described.

[0076] Figure 4 FIG. 4 is an exemplary structural diagram of a three-level statistical module and related modules according to some embodiments of the present invention. Figure 4 As shown, the three-level statistical module 430 of this embodiment includes multiple three-level statistical processes 4301, 4302, 4303...430Q, Q is a positive integer, the number of three-level statistical processes is equal to the number of second-level cache units, and corresponds to each second-level cache unit one by one, that is, these three-level statistical processes correspond to second-level cache units 4211, 4212, 4213...421Q one by one, and each three-level statistical process counts the data in a second-level cache unit. As needed, the three-level statistical process and the second-level cache unit can also be other corresponding relationships, which will not be repeated here.

[0077] In some embodiments, the real-time data statistics device may further include a main process module, which is located in one or more of the primary statistical module, the secondary statistical module, and the tertiary statistical module, that is, each statistical module may selectively have a main process module. The main process module is configured to read the configuration information of the configuration center, and create, monitor, rebuild, or destroy one or more of the primary statistical process of the primary statistical module, the secondary statistical process of the secondary statistical module, and the tertiary statistical process of the tertiary statistical module according to the configuration information. Thus, dynamic expansion or contraction of the system can be achieved.

[0078] This application can be implemented based on the in-memory database Redis. Redis is an open source Key-Value database, written in the American National Standards Institute (ANSI) C language, compliant with the BSD (Berkeley Software Distribution) protocol, supporting networks, and based on memory storage. It supports multiple data types, such as strings, hashes, lists (List) or queues, sets (Sets), and ordered sets (SortedSets), etc. Figure 5 An embodiment of a real-time data statistics device implemented by Redis in the present invention is described.

[0079] Figure 5 FIG. 2 is an exemplary structural diagram of a real-time data statistics device according to some other embodiments of the present invention. Figure 5 As shown, the real-time data statistics device 50 of this embodiment includes a real-time data source 510, a primary statistics module 520, a primary cache module 530, a secondary statistics module 540, a secondary cache module 550, a tertiary statistics module 560, and a configuration center 570. In addition, the real-time data statistics device 50 stores the statistically completed data persistently in a persistent storage module 580.

[0080] The real-time data source 510 includes data sources 5101, 5102, ... 510A; the primary statistical module 520 includes a primary main process 5200, and primary statistical processes 5201, 5202, ... 520B; the primary cache module 530 includes Redis queues 5301, 5302, ... 530C, each queue is stored in a Redis instance; the secondary statistical module 540 includes a secondary main process 5400, and secondary statistical processes 5401, 5402, ... 540D; the secondary cache module 550 includes Redis ordered sets 5501, 5502, ... 550E; the tertiary statistical module 560 includes a tertiary main process 5600, and tertiary statistical processes 5601, 5602, ... 560E. The primary main process 5200, the secondary main process 5400, and the tertiary main process 5600 obtain configuration information from the configuration center 570 to create a statistical process.

[0081] The first-level cache module 530 is used to store the intermediate statistical data of the first-level statistical module 520, wherein the data type of the first-level cache unit is the List (queue) type of Redis, and one List is stored on a Redis instance. When traversing the map container storing the intermediate statistical data, the first-level cache module 530 composes a data packet, and the "RPUSH key value" command can be used to write the data to the Redis queue. When writing to the Redis queue, data can be written in a random polling manner. If writing to the current queue fails, write to the next queue. Thus, the load balancing of Redis is guaranteed. At the same time, selecting a random bit to start traversal also avoids the downtime of a Redis node, causing all the data originally written to the node to be written to the next node of the Redis list, causing the system to avalanche.

[0082] The secondary statistical process of the secondary statistical module 540 can use the "LPOP key" command to consume Redis queue data and further perform aggregate statistics. The secondary cache module 550 can store the statistical results of the secondary statistical module 540, where the data type of the secondary cache unit is Redis's Sortedset, that is, an ordered set type, and an ordered set is stored on a Redis instance. Since sets do not allow duplicate elements, the secondary statistical module can generate a globally unique data packet for each piece of data when traversing the map container that stores the statistical results to avoid failure to insert into the set. For example, a UUID field can be added to each data packet to ensure that the elements inserted into the set will not be repeated. When inserting data, the "ZADD key score member" command can be used to insert the data into the ordered set of Redis. The score value in the data structure can be, for example, the timestamp of each piece of data, so that the tertiary statistical module 560 can retrieve the data at one time according to the time dimension, and the member in the data structure can be the specific content of the data packet.

[0083] The secondary statistics process can use the consistent hashing algorithm to determine which Redis node to store based on the key of the map data. The consistent hashing algorithm aggregates data of the same type, that is, the same dimension, into the same Redis set. In addition, the monotonicity of data storage can be guaranteed, that is, when the storage module is expanded to add new nodes or delete failed nodes, the hash result can ensure that the original stored content can be mapped to the original or new cache area, and will not be mapped to other cache areas in the old node set, which solves the problem of data disaster recovery to a certain extent.

[0084] The third-level statistics process can use the "ZRANGEBYSCORE key min max" command to read the data in the second-level cache module 550 to obtain a certain amount of historical data for retrospective statistics to avoid delayed data being discarded.

[0085] If the statistical process at each level can read data, the processing flow of the above embodiments is performed; if there is no data, it can enter a dormant state. If the statistical process receives a kill signal sent by the main process, the process is terminated.

[0086] Configuration center 570 can be a distributed system that provides services for adding, deleting, checking and modifying configuration information. Statistics modules at all levels will request the configuration center under preset conditions, such as regularly requesting the configuration center, to obtain the latest configuration. Configuration information can exist in the form of key-value, for example.

[0087] The configuration information of the first-level statistical module 520 is mainly the number of processes for processing each original data source. For example, "Data Source 1:4, Data Source 2:3" can indicate that data source 1 needs to open 4 first-level statistical processes for processing, and data source 2 needs to open 3 first-level statistical processes for processing. The configuration information of the second-level statistical module is mainly the instance list of the Redis queue and the number of its consumer processes. The configuration information of the third-level statistical module is mainly the list of Redis ordered set instances and the list of machine IP (Internet Protocol) addresses of the module process deployed, so that one process processes one Redis set. The second-level statistical module can also periodically pull the Redis ordered set list configuration when writing to the second-level cache. Those skilled in the art can increase or decrease statistical processes and Redis instances according to actual conditions and actual needs, thereby realizing dynamic expansion and contraction of the system's computing resources and storage resources.

[0088] Reference below Figure 6 An embodiment of the real-time data statistics method of the present invention is described.

[0089] Figure 6 FIG. 4 is an exemplary flow chart of a real-time data statistics method according to some embodiments of the present invention. Figure 6 As shown, the real-time data statistics method of this embodiment includes steps S602 to S606.

[0090] In step S602, the first-level statistical module uses a preset time granularity to perform statistics on the acquired original data, generates intermediate statistical data including statistical items and statistical result fields in the original data, and writes the intermediate statistical data into the first-level cache unit.

[0091] In some embodiments, the first-level cache unit may be of queue type.

[0092] In step S604, the L2 statistical module reads the intermediate statistical data in the plurality of L1 cache units, and writes the intermediate statistical data with the same statistical item value into the same L2 cache unit.

[0093] In some embodiments, the second-level cache unit may be of an ordered set type.

[0094] In step S606, the third-level statistical module counts the data in each second-level cache unit, generates final statistical data, and persistently stores the final statistical data generated by each second-level cache unit.

[0095] In some embodiments, the first-level cache unit and the second-level cache unit may be nodes of a memory database Redis.

[0096] In some embodiments, the same data flow flows and is executed in the order of steps S602 to S606, but the primary statistical module, the secondary statistical module, and the tertiary statistical module can be executed in parallel. That is, the three steps can be executed simultaneously, but different data are processed simultaneously. Therefore, the present invention can make statistical modules belonging to different levels and performing different processing execute in parallel, further improving the efficiency of data statistics.

[0097] Through the above embodiments, the present invention can first disperse the statistics of the original data, then disperse the data according to the values ​​of the statistical items, and finally count the dispersedly stored data to obtain the final statistical results. Through multi-level processing of the data, the uniform multi-point distribution of the data is achieved, thereby improving the efficiency of real-time data statistics.

[0098] Reference below Figure 7 An embodiment of the real-time data statistics method of the present invention is described.

[0099] Figure 7 FIG. 1 is an exemplary flow chart of a real-time data statistics method according to some other embodiments of the present invention. Figure 7 As shown, the real-time data statistics method of this embodiment includes steps S702 to S706.

[0100] In step S702, the first-level statistical module includes multiple first-level statistical processes, each of which obtains original data from a data source pre-associated with the first-level statistical process, and performs statistics on the obtained original data using a preset time granularity, generates intermediate statistical data including statistical items and statistical result fields in the original data, and writes the intermediate statistical data into the first-level cache unit.

[0101] In step S704, the secondary statistical module includes multiple secondary statistical processes, each secondary statistical process reads intermediate statistical data from a primary cache unit pre-associated with the secondary statistical process, and writes intermediate statistical data with the same statistical item value into the same secondary cache unit.

[0102] In step S706, the three-level statistical module includes multiple three-level statistical processes, each of which counts the data in each second-level cache unit pre-associated with the three-level statistical process, generates final statistical data, and persistently stores the final statistical data generated by each second-level cache unit. The number of three-level statistical processes is equal to the number of second-level cache units.

[0103] One or more of steps S702 to S706 may be optionally combined with Figure 6 Execute in conjunction with the other steps in .

[0104] Therefore, parallel processing can be performed within each level to further improve data statistical efficiency.

[0105] Combine the following Figures 8A to 8C An embodiment of a processing method of a primary statistical module and a secondary statistical module is introduced.

[0106] Fig. 8A FIG. 4 is an exemplary flow chart of a primary statistical module processing method according to some embodiments of the present invention. Fig. 8A As shown, the method of this embodiment includes steps S802 to S806.

[0107] In step S802, the primary statistical module reads raw data from the data source.

[0108] In step S804, the primary statistical module uses a preset time granularity to perform statistics on the acquired original data, and generates intermediate statistical data including statistical items in the original data and statistical result fields.

[0109] In step S806, the first-level statistics module writes each intermediate statistical data into one of the plurality of first-level cache units by random polling.

[0110] Thus, load balancing of data writing can be achieved, thereby improving processing efficiency.

[0111] Figure 8B and 8C is an exemplary flow chart of a secondary statistics module processing method according to some embodiments of the present invention.

[0112] In 8B, the method of this embodiment includes steps S812 to S816. In this embodiment, the secondary cache unit is of ordered set type.

[0113] In step S812, the L2 statistical module reads intermediate statistical data from a plurality of L1 cache units.

[0114] In step S814, the secondary statistics module adds the UUID field and value to the intermediate statistics.

[0115] In step S816, the secondary statistical module writes the intermediate statistical data with the same statistical item value into the same secondary cache unit.

[0116] In 8C, the method of this embodiment includes steps S822 to S824.

[0117] In step S822, the L2 statistical module reads intermediate statistical data from a plurality of L1 cache units.

[0118] In step S824, the secondary statistical module calculates the hash value of the value of the statistical item of each intermediate statistical data, and writes the intermediate statistical data with the same calculated hash value into the same secondary cache unit.

[0119] Thus, data having the same value of the statistical item can be quickly obtained.

[0120] In some embodiments, the main process unit may also be used to read the configuration information of the configuration center, and create, monitor, rebuild, or destroy one or more of the primary statistical process of the primary statistical module, the secondary statistical process of the secondary statistical module, and the tertiary statistical process of the tertiary statistical module according to the configuration information. An embodiment of the processing method within each level of the present invention is described below with reference to FIG. 9.

[0121] Fig. 9A and 9B is an exemplary flow chart of a processing method within each layer according to some embodiments of the present invention.

[0122] Fig. 9A Steps S902 to S914 shown are the main process execution flow.

[0123] In step S902, the main process reads the local configuration file from the configuration center.

[0124] In step S904, a while(1) loop is executed.

[0125] In step S906, a configuration center is regularly requested to pull configurations.

[0126] In step S908, it is determined whether the configuration information has been changed. If yes, step S910 is executed; if no, step S912 is executed.

[0127] In step S910, the original process corresponding to the changed configuration is destroyed and a new process is created.

[0128] In step S912, it is determined whether the statistical process has been exited. If so, step S914 is executed; if not, step S904 is executed.

[0129] In step S914, the statistics process is started, and then the process returns to step S904.

[0130] Fig. 9B Steps S922 to S930 shown are the statistical process execution flow.

[0131] In step S922, a statistics process is created.

[0132] In step S924, it is determined whether there is currently readable data. If yes, step S926 is executed; if not, step S924 is executed.

[0133] In step S926, the data is analyzed and counted.

[0134] In step S928, the statistical results are written.

[0135] In step S930, it is determined whether a Kill signal is received. If yes, the process ends; if no, it returns to step S924.

[0136] Thus, dynamic expansion or contraction of the system can be achieved.

[0137] Fig.10 FIG. 2 is an exemplary structural diagram of a real-time data statistics device according to some other embodiments of the present invention. Fig.10 As shown, the data processing device 1000 of this embodiment includes: a memory 1010 and a processor 1020 coupled to the memory 1010 , and the processor 1020 is configured to execute the data processing method in any one of the aforementioned embodiments based on instructions stored in the memory 1010 .

[0138] The memory 1010 may include, for example, a system memory, a fixed non-volatile storage medium, etc. The system memory may store, for example, an operating system, an application program, a boot loader, and other programs.

[0139] Fig.11 1 is an exemplary structural diagram of a real-time data statistics device according to some further embodiments of the present invention. Fig.11As shown, the real-time data statistics device 1100 of this embodiment includes: a memory 1110 and a processor 1120, and may also include an input / output interface 1130, a network interface 1140, a storage interface 1150, etc. These interfaces 1130, 1140, 1150 and the memory 1110 and the processor 1120 may be connected, for example, via a bus 1160. Among them, the input / output interface 1130 provides a connection interface for input / output devices such as a display, a mouse, a keyboard, and a touch screen. The network interface 1140 provides a connection interface for various networked devices. The storage interface 1150 provides a connection interface for external storage devices such as SD cards and USB flash drives.

[0140] An embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, wherein the program implements any of the aforementioned real-time data statistics methods when executed by a processor.

[0141] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable non-transient storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0142] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0143] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0144] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0145] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A real-time data statistics device, comprising: The first-level statistical module is configured to perform statistics on the acquired raw data using a preset time granularity, generate intermediate statistical data including statistical items and statistical result fields in the raw data, and write the intermediate statistical data into the first-level cache unit; A secondary statistical module is configured to read intermediate statistical data in a plurality of primary cache units, and write intermediate statistical data with the same value of the statistical item into the same secondary cache unit; The third-level statistical module is configured to count the data in each second-level cache unit, generate final statistical data, and persistently store the final statistical data generated by each second-level cache unit.

2. The real-time data statistics device according to claim 1, wherein: The primary statistical module, the secondary statistical module, and the tertiary statistical module are executed in parallel.

3. The real-time data statistics device according to claim 1, wherein: The primary statistical module includes a plurality of primary statistical processes, each of which is configured to obtain raw data from a data source pre-associated with the primary statistical process; or, The secondary statistical module includes a plurality of secondary statistical processes, each of which is configured to read intermediate statistical data from a primary cache unit pre-associated with the secondary statistical process; or, The three-level statistical module includes multiple three-level statistical processes, each of which is configured to count the data in each second-level cache unit pre-associated with the three-level statistical process, and the number of the three-level statistical processes is equal to the number of the second-level cache units.

4. The real-time data statistics device according to claim 3 further comprises: The main process unit located in one or more of the first-level statistical module, the second-level statistical module, and the third-level statistical module is configured to read the configuration information of the configuration center, and create, monitor, rebuild, or destroy one or more of the first-level statistical processes of the first-level statistical module, the second-level statistical process of the second-level statistical module, and the third-level statistical process of the third-level statistical module according to the configuration information.

5. The real-time data statistics device according to claim 1, wherein: The first-level cache unit is of queue type; or, The secondary cache unit is of an ordered set type; the secondary statistics module is further configured to add a universal unique identifier field and value to the intermediate statistical data.

6. The real-time data statistics device according to claim 1, wherein: The first-level statistics module is further configured to write each intermediate statistical data into one of the plurality of first-level cache units in a random polling manner.

7. The real-time data statistics device according to claim 1, wherein: The secondary statistical module is further configured to calculate a hash value of a value of a statistical item of each intermediate statistical data, and write intermediate statistical data with the same calculated hash value into the same secondary cache unit.

8. The real-time data statistics device according to claim 1, further comprising one or more of a primary cache unit, a secondary cache unit, and a configuration center; in, The configuration center is configured to store configuration information of the primary statistical module, the secondary statistical module, and the tertiary statistical module.

9. The real-time data statistics device according to claim 8, wherein: The first-level cache unit and the second-level cache unit are nodes of the in-memory database Redis.

10. A real-time data statistics method, comprising: The first-level statistical module uses a preset time granularity to perform statistics on the acquired raw data, generates intermediate statistical data including statistical items and statistical result fields in the raw data, and writes the intermediate statistical data into the first-level cache unit; The secondary statistical module reads the intermediate statistical data in the plurality of primary cache units, and writes the intermediate statistical data with the same statistical item value into the same secondary cache unit; The third-level statistical module counts the data in each second-level cache unit, generates final statistical data, and persistently stores the final statistical data generated by each second-level cache unit.

11. The real-time data statistics method according to claim 10, wherein: The primary statistical module, the secondary statistical module, and the tertiary statistical module are executed in parallel.

12. The real-time data statistics method according to claim 10, wherein: The primary statistical module includes a plurality of primary statistical processes, each of which obtains raw data from a data source pre-associated with the primary statistical process; or, The secondary statistical module includes a plurality of secondary statistical processes, each of which reads intermediate statistical data from a primary cache unit pre-associated with the secondary statistical process; or, The three-level statistical module includes multiple three-level statistical processes, each of which counts the data in each second-level cache unit pre-associated with the three-level statistical process, and the number of the three-level statistical processes is equal to the number of the second-level cache units.

13. The real-time data statistics method according to claim 12, further comprising: The main process unit located in one or more of the first-level statistical module, the second-level statistical module, and the third-level statistical module is configured to read the configuration information of the configuration center, and create, monitor, rebuild, or destroy one or more of the first-level statistical processes of the first-level statistical module, the second-level statistical process of the second-level statistical module, and the third-level statistical process of the third-level statistical module according to the configuration information.

14. The real-time data statistics method according to claim 10, wherein: The first-level cache unit is of queue type; or, The secondary cache unit is of ordered set type; The real-time data statistics method further includes: a secondary statistics module adding a universal unique identification code field and value to the intermediate statistical data.

15. The real-time data statistics method according to claim 10, wherein: The first-level statistics module uses random polling to write each intermediate statistical data into one of the multiple first-level cache units.

16. The real-time data statistics method according to claim 10, wherein: The secondary statistical module calculates a hash value of a value of a statistical item of each intermediate statistical data, and writes intermediate statistical data having the same calculated hash value into the same secondary cache unit.

17. The real-time data statistics method according to claim 10, wherein: The first-level cache unit and the second-level cache unit are nodes of the in-memory database Redis.

18. A real-time data statistics device, comprising: Memory; as well as A processor coupled to the memory, wherein the processor is configured to execute the real-time data statistics method according to any one of claims 10 to 17 based on instructions stored in the memory.

19. A computer-readable storage medium having a computer program stored thereon, wherein when the program is executed by a processor, the real-time data statistics method according to any one of claims 10 to 17 is implemented.