Method and apparatus for estimating cardinality based on dynamic interval expansion, and readable medium

By constructing a counter array with dynamic range expansion and using leading zeros in hash values, the problem of insufficient accuracy of existing cardinality estimation methods in large-scale datasets is solved, achieving high-accuracy cardinality estimation in various counting ranges, and supporting dynamic range expansion and high throughput.

CN118035237BActive Publication Date: 2026-11-24XIAMEN UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410166966.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-02-06
Publication Date
2026-11-24
Estimated Expiration
2044-02-06

AI Technical Summary

Technical Problem

Existing cardinality estimation methods struggle to provide high accuracy across various count ranges when dealing with large-scale datasets, especially when the cardinality is small. Furthermore, existing techniques suffer from high memory overhead and slow processing speed.

Method used

A cardinality estimation method based on dynamic range expansion is adopted. By constructing a counter array consisting of m z-bit counters, the threshold and counter value of the counter array are dynamically adjusted by utilizing the number of leading zeros in the hash value and sampling techniques to achieve dynamic range expansion. Furthermore, the counter update and query are optimized through lazy sampling and rolling record mechanisms.

Benefits of technology

It achieves high-precision cardinality estimation across different counting ranges, supports dynamic range expansion, meets the bandwidth requirements of modern links, and is theoretically capable of counting infinitely large numbers with controllable errors within a reasonable range, achieving higher throughput than existing technologies.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118035237B_ABST
    Figure CN118035237B_ABST
Patent Text Reader

Abstract

This invention discloses a cardinality estimation method, apparatus, and readable medium based on dynamic interval expansion, comprising: constructing a counter array consisting of m z-bit counters; during the update process, acquiring data packets, calculating the hash value of the data packets and counting the number of leading zeros in their hash values; when the number of leading zeros in the hash value of a data packet is greater than or equal to a variable threshold r, the data packet is determined to be a sampled data packet; determining the counter corresponding to the sampled data packet in the counter array; when its value is 0, incrementing the value n of the counter with non-zero values ​​by 1; updating the value of the counter corresponding to the sampled data packet; when the value n is greater than or equal to a fixed threshold v, performing the next round of operation, incrementing the variable threshold r by 1; determining whether to decrement the value of each counter by 1 based on its value; querying the estimated cardinality of the currently recorded data based on the values ​​of m, n, and r, which can improve the accuracy across various counting ranges.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of cardinality estimation, and more specifically to a cardinality estimation method, apparatus, and readable medium based on dynamic interval expansion. Background Technology

[0002] In today's data-driven world, the ability to process and analyze massive amounts of information is crucial. Cardinality counting, also known as uniqueness estimation, aims to determine the number of unique or distinctive items in a data stream. The ability to count unique items is vital in many fields. Specifically, in the database domain, cardinality statistics aid in data profiling, business intelligence, and query optimization. For example, by estimating the cardinality of a column or combination of columns, query optimizers can make informed decisions about the most efficient query execution plan. In the networking domain, uniqueness counting can also provide valuable information for search engine advertising, anomaly detection, and resource allocation. For instance, by counting the number of different source hosts connected to a target host, potential sources of distributed denial-of-service (DDoS) attacks can be identified.

[0003] However, cardinality statistics faces unique challenges compared to traditional counting methods because it requires identifying and eliminating duplicates. This introduces additional processing and memory overhead to track previously observed items, ensuring accurate counting of unique items. Furthermore, cardinality statistics needs to achieve high-performance updates and queries within a limited memory footprint. For example, modern high-speed networks may handle millions of streams simultaneously with line speeds of 40 Gbps. To keep up with such high processing speeds, the throughput of data structure updates used for cardinality statistics must be fast enough to prevent packet loss. Simultaneously, in some cases, it is necessary to query the data structure as each item arrives to obtain an accurate estimate (e.g., checking if a packet originated from a DDoS attack), meaning query performance must match the line speed requirements.

[0004] Performing 100% accurate cardinality statistics without sacrificing accuracy is often inefficient and resource-intensive, especially when dealing with large datasets or data streams. One approach is to use a bitmap, where each item is represented by a corresponding bit to ensure no hash collisions. However, this approach requires the bitmap size to be equal to the range of values ​​in the itemset, which can be impractical for datasets with large value ranges. Similarly, algorithms that rely on sorting to eliminate duplicates can have very high time complexity, exacerbating the performance efficiency challenges. Furthermore, the volume of data continues to grow exponentially. For example, top users of PowerDrill (a Google data analytics tool) spent six hours performing cardinality statistics on approximately 525 trillion cells during a (hypothetical) full scan, and the scale of data currently being processed is expected to be even larger. Therefore, the need for more efficient and scalable technical statistical algorithms is becoming increasingly critical.

[0005] Many approximate cardinality statistics methods have been proposed to address the challenges of processing large datasets or data streams from an algorithmic perspective. These methods aim to provide approximate estimates with low memory overhead and fast processing time while maintaining reasonable accuracy. However, existing cardinality statistics algorithms cannot provide accurate estimates for a wide range of counting ranges. Based on their core methods, state-of-the-art cardinality statistics algorithms can be categorized into three classes:

[0006] 1. Bitmap-based methods: These methods, such as Linear Counting, offer high accuracy over small counting ranges. However, Linear Counting has a limited counting range because its maximum counting capacity is linearly related to memory size. To calculate the cardinality of large datasets, Linear Counting needs to allocate memory based on prior knowledge of the total cardinality. For example, if using Linear Counting to count the number of flows from each source address in a modern network, memory usage could reach 10GB due to the potential for millions of concurrent flows. Even though MultiResolution Bitmap incorporates sampling techniques into Linear Counting to extend the counting range, it still faces the same limitations.

[0007] 2. Leading Zero-Based Methods: These methods utilize the number of leading zeros in the hash result of the monitored item. A typical example is HyperLogLog. HyperLogLog provides a large counting range (e.g., higher than...). However, its accuracy decreases when the actual cardinality to be counted is small. Furthermore, HyperLogLog's query throughput decreases relatively as the amount of allocated memory increases.

[0008] 3. Ordinal Statistical Approaches: These methods, such as K-minimum-value, support accurate cardinality estimation by recording the k-th smallest hash value across all monitored items. However, they face similar challenges to leading-zero-based methods.

[0009] In summary, no cardinality estimation method currently exists that can consistently provide high accuracy across a wide range of counts. It suffers from difficulties handling large datasets or experiences a decline in accuracy when the cardinality is small. Summary of the Invention

[0010] In view of the aforementioned technical problems, the purpose of the embodiments of this application is to propose a cardinality estimation method, apparatus, and readable medium based on dynamic interval expansion to solve the technical problems mentioned in the background section above, so as to adapt to different counting ranges under various deployment scenarios.

[0011] In a first aspect, the present invention provides a cardinality estimation method based on dynamic interval expansion, comprising the following steps:

[0012] Construct a counter array consisting of m z-bit counters, where z ≥ 2;

[0013] During the update process, data packets are acquired, their hash values ​​are calculated, and the number of leading zeros in their hash values ​​is counted. If the number of leading zeros in the hash value of a data packet is greater than or equal to the variable threshold r, then the data packet is determined to be a sampled data packet. The counter corresponding to the sampled data packet is determined in the counter array. If the value of the counter corresponding to the sampled data packet is determined to be 0, then the value of the number n of non-zero counters in the counter array is incremented by 1. The values ​​of the variable threshold r and the number n are initially 0.

[0014] The value of the counter corresponding to the sampled data packet is updated based on the number of leading zeros in the hash value of the data packet and the value of the counter corresponding to the sampled data packet. In response to the determination that the value of the number n is greater than or equal to the fixed threshold v, the next round of operation is executed. In the next round of operation, the variable threshold r is incremented by 1, and it is determined whether to decrement it by 1 based on the value of each counter in the counter array.

[0015] Query the estimated cardinality of the currently recorded number based on the values ​​of m, n, and r.

[0016] Preferably, the m z-bit counters in the counter array are s[0], s[1], ..., s[m-1], and the value of each counter is 0, 1, 2, ... One of them.

[0017] Preferably, the counter corresponding to the sampled data packet is determined in the counter array, specifically including:

[0018] The sampled data packet x is input into the hash function to obtain a value g(x) in the range [0, m-1], and s[g(x)] is the counter corresponding to the sampled data packet.

[0019] As a preferred option, it also includes:

[0020] In response to the determination that the value of the counter corresponding to the sampled data packet is not 0, the value of n, the number of counters with non-zero values ​​in the counter array, remains unchanged;

[0021] The update process ends when the number of leading zeros in the hash value of a data packet is less than a variable threshold r, or when the number of leading zeros n is less than a fixed threshold v.

[0022] Preferably, the value of the counter corresponding to the sampled data packet is updated based on the number of leading zeros in the hash value of the data packet and the value of the counter corresponding to the sampled data packet, specifically including:

[0023] Let l be the number of leading zeros in the hash value of the data packet. In response to determining that l ≥ s[g(x)] + r - 1, the counter s[g(x)] corresponding to the sampled data packet is updated to l - r + 1. If l - r + 1 > 1, then the value of the counter s[g(x)] is updated to l - r + 1. Then the value of the counter s[g(x)] corresponding to the sampled data packet is... ;

[0024] In response to the determination that l < s[g(x)] + r - 1, the value of the counter s[g(x)] corresponding to the sampled data packet remains unchanged.

[0025] Preferably, the method involves determining whether to decrement each counter by 1 based on the value of each counter in the counter array, specifically including:

[0026] If the value of one of the counters s[i] in the counter array is equal to Then, with a probability of 1 / 2, the value of s[i] is reduced by 1;

[0027] If the value of one of the counters s[i] in the counter array is less than If the value is greater than 0, then directly subtract 1 from the value of s[i].

[0028] If the value of one of the counters s[i] in the counter array is equal to 0, then the value of s[i] remains unchanged.

[0029] Preferably, the estimated cardinality currently recorded is... .

[0030] Secondly, the present invention provides a cardinality estimation device based on dynamic interval expansion, comprising:

[0031] The array building block is configured as a counter array consisting of m z-bit counters, where z ≥ 2;

[0032] The sampling module is configured to, during the update process, acquire data packets, calculate the hash value of the data packets and count the number of leading zeros in their hash values. In response to determining that the number of leading zeros in the hash value of a data packet is greater than or equal to a variable threshold r, the data packet is determined to be a sampled data packet. The counter corresponding to the sampled data packet is determined in the counter array. In response to determining that the value of the counter corresponding to the sampled data packet is 0, the value of the number n of non-zero counters in the counter array is incremented by 1. The values ​​of the variable threshold r and the number n are initially 0.

[0033] The update module is configured to update the value of the counter corresponding to the sampled data packet based on the number of leading zeros in the hash value of the data packet and the value of the counter corresponding to the sampled data packet. In response to determining that the value of the number n is greater than or equal to the fixed threshold v, the next round of operation is executed. In the next round of operation, the variable threshold r is incremented by 1, and it is determined whether to decrement it by 1 based on the value of each counter in the counter array.

[0034] The query module is configured to query the estimated cardinality of the currently recorded data based on the values ​​of m, n, and r.

[0035] Thirdly, the present invention provides an electronic device including one or more processors; and a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any implementation of the first aspect.

[0036] Fourthly, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method as described in any of the implementations of the first aspect.

[0037] Compared with the prior art, the present invention has the following beneficial effects:

[0038] (1) The cardinality estimation method based on dynamic range expansion proposed in this invention adopts a cardinality statistics mechanism that supports dynamic range expansion. Its counting range will dynamically increase as the observed cardinality increases. Therefore, it is not necessary to know in advance the size of the cardinality of the dataset and data stream to be counted, and the counting range will be dynamically expanded to an appropriate level according to the size of the specific cardinality. And it can ensure that the same level of accuracy is maintained in different technical ranges.

[0039] (2) The cardinality estimation method based on dynamic range expansion proposed in this invention can theoretically count an infinitely large number using only a 2-bit counter, and the DREX data structure is also based on an array of 2-bit counters to realize the aforementioned dynamic range expansion mechanism. In addition, DREX can support intersection and union operations.

[0040] (3) The cardinality estimation method based on dynamic interval expansion proposed in this invention has theoretically proven that its error can be effectively controlled within a reasonable range, and the error level is the same across different technical ranges. Experimentally, it has been proven that DREX has higher accuracy than the most advanced cardinality statistics techniques on different datasets and across different technical ranges, and its update and query throughput can also meet the bandwidth requirements of modern links. Attached Figure Description

[0041] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0042] Figure 1 This is a flowchart illustrating the cardinality estimation method based on dynamic interval expansion according to an embodiment of this application;

[0043] Figure 2 A schematic diagram of the data structure of the cardinality estimation method based on dynamic interval expansion, as an embodiment of this application;

[0044] Figure 3 A schematic diagram illustrating an example of a cardinality estimation method based on dynamic interval expansion, as exemplified by an embodiment of this application;

[0045] Figure 4 This is a schematic diagram of the state-of-the-art cardinality statistics technique based on the cardinality estimation method with dynamic interval expansion, which is an embodiment of this application.

[0046] Figure 5 This is a schematic diagram of the baseline method in the cardinality estimation method based on dynamic interval expansion, as described in an embodiment of this application.

[0047] Figure 6 The cardinality estimation method based on dynamic interval expansion in the embodiments of this application , and The relationship between them;

[0048] Figures 7-13The graph shows the relative error results of the cardinality estimation method based on dynamic interval expansion based on the embodiments of this application and the most advanced cardinality statistics techniques under CAIDA-19A, CAIDA-16A, CAIDA-18A, CAIDA-18B, CAIDA-16B, CAIDA-19B, and MAWI.

[0049] Figure 14 The graph shows the relative error between the cardinality estimation method based on dynamic interval expansion in the embodiments of this application and the state-of-the-art cardinality statistics techniques on a small dataset.

[0050] Figure 15 The graph shows the update speed of the cardinality estimation method based on dynamic interval expansion in the embodiments of this application compared with the current state-of-the-art cardinality statistics techniques.

[0051] Figure 16 The graph shows the query speed of the cardinality estimation method based on dynamic interval expansion, which is an embodiment of this application, compared with the most advanced cardinality statistics techniques.

[0052] Figure 17 The cardinality estimation method based on dynamic interval expansion, as an embodiment of this application. The result graph shows the impact of the selected value on accuracy;

[0053] Figure 18 This is a schematic diagram of a cardinality estimation device based on dynamic interval expansion, as an embodiment of this application. Detailed Implementation

[0054] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this invention, and not all of them. Based on the embodiments of this invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this invention.

[0055] Figure 1 An embodiment of this application provides a cardinality estimation method based on dynamic interval expansion, comprising the following steps:

[0056] S1 is a counter array consisting of m z-bit counters, where z ≥ 2.

[0057] In a specific embodiment, the m z-bit counters in the counter array are s[0], s[1], ..., s[m-1], and the value of each counter is 0, 1, 2, ... One of them.

[0058] refer to Figure 2In this embodiment, z=2 is used as an example for illustration. First, a counter array s consisting of m 2-bit counters needs to be constructed and maintained. The m 2-bit counters are: s[0], s[1], ..., s[m-1]. Each counter has only 2 bits, meaning it can store only four values: 0, 1, 2, and 3. Additionally, variable n is used as the number of non-zero counter values ​​in the counter array s, i.e., to count how many counters in the counter array s have non-zero values. Variable r is used to record a threshold related to leading zeros. v is used to record a threshold related to n (v≤n). For example, v=n. All 2-bit counters, as well as variables r and n, are initialized to 0. The value of v can be set to a value less than or equal to m, where m represents the number of 2-bit counters. For example, v=m or v=0.9m. v is a threshold related to counters with values ​​greater than 0. In the update process, when n is greater than or equal to v, the next round of operation is triggered.

[0059] S2, during the update process, acquire data packets, calculate the hash value of the data packets and count the number of leading zeros in their hash values. In response to determining that the number of leading zeros in the hash value of the data packets is greater than or equal to the variable threshold r, the data packet is determined to be a sampled data packet. The counter corresponding to the sampled data packet is determined in the counter array. In response to determining that the value of the counter corresponding to the sampled data packet is 0, the value of the number n of counters in the counter array that are not 0 is incremented by 1. The values ​​of the variable threshold r and the number n are initially 0.

[0060] In a specific embodiment, determining the counter corresponding to the sampled data packet in the counter array specifically includes:

[0061] The sampled data packet x is input into the hash function to obtain a value g(x) in the range [0, m-1], and s[g(x)] is the counter corresponding to the sampled data packet.

[0062] In specific embodiments, it also includes:

[0063] In response to the determination that the value of the counter corresponding to the sampled data packet is not 0, the value of n, the number of counters with non-zero values ​​in the counter array, remains unchanged;

[0064] The update process ends when the number of leading zeros in the hash value of a data packet is less than a variable threshold r, or when the number of leading zeros n is less than a fixed threshold v.

[0065] Specifically, Table 1 describes the DREX update process. Each item Hash into a binary string (A binary string is a random string containing only 0s and 1s; for example, a 16-bit binary string could be 1110010110001011), and calculate the length of the leading zeros, denoted as l. If Greater than or equal to If so, continue with the following steps. Function Randomly and uniformly Hash to 0 An integer between 0 and m (the function g(x) can be any hash function; for example, with x as input, g(x) calculates a value, and the result is modulo m, resulting in a value between 0 and m-1). If The corresponding counter value is initially 0, then... Increase by 1. s[i] represents the value of the i-th counter in the array, and s[g(x)] represents the value of the g(x)-th counter in the array. If The length of the leading zeros of the record is greater than or equal to the length of the record (i.e. In the section introducing the rolling record, it is mentioned that the value of s[i] is given by s[i] = Min(l-r+1, 3). Assuming s[i] = l-r+1, we can deduce that l = s[i] + r-1), then the counter value will be overwritten. It's important to note that, due to the limited number of bits (only 2), the maximum value recorded in the counter is capped at 3. Once... If the counter array is saturated, then proceed to the next round of operations.

[0066] Table 1

[0067]

[0068] The specific update process is as follows:

[0069] 1. When each data packet x arrives, first calculate the number of leading zeros in its hash value and denote it as l. For example, if the hash value of x1 is 00001111000001, then the number of leading zeros is 4 (l=4).

[0070] The reason for leading zeros in the count is: according to mathematical expectation, in the binary string of a random hash... The item has l leading zeros. Therefore, the number of leading zeros can be used to determine whether the current data packet has been sampled.

[0071] 2. Determine if the number of leading zeros l in data packet x is greater than or equal to r, where the initial value of r is 0;

[0072] If so, continue with the following steps (equivalent to data packet x being sampled).

[0073] If not, then end the update (equivalent to data packet x not being sampled).

[0074] 3. The sampled data packet x is hashed again using a hash function (i.e., g(x)). g(x) is a value in the range [0, m-1] generated based on the input x, and s[g(x)] is the counter corresponding to the sampled data packet x.

[0075] 4. Check if the value of the counter (s[g(x)]) corresponding to the sampled data packet x is 0;

[0076] If so, then the value of n is incremented by 1, because n records how many counters in the counter array s have non-zero values. If the value of s[g(x)] is 0, and the value recorded in s[g(x)] in step 5 is definitely greater than 0, then there is an extra counter with a non-zero value in the counter array, so the value of n is incremented by 1.

[0077] If not, no action will be taken.

[0078] S3, update the value of the counter corresponding to the sampled data packet according to the number of leading zeros of the hash value of the data packet and the value of the counter corresponding to the sampled data packet. In response to the determination that the value of the number n is greater than or equal to the fixed threshold v, execute the next round of operation. In the next round of operation, increment the variable threshold r by 1, and determine whether to decrement it by 1 according to the value of each counter in the counter array.

[0079] In a specific embodiment, the value of the counter corresponding to the sampled data packet is updated based on the number of leading zeros in the hash value of the data packet and the value of the counter corresponding to the sampled data packet. Specifically, this includes:

[0080] Let l be the number of leading zeros in the hash value of the data packet. In response to determining that l ≥ s[g(x)] + r - 1, the value of the counter s[g(x)] corresponding to the sampled data packet is updated to l - r + 1. If l - r + 1 > 3, the value of the counter s[g(x)] corresponding to the sampled data packet is 3.

[0081] In response to the determination that l < s[g(x)] + r - 1, the value of the counter s[g(x)] corresponding to the sampled data packet remains unchanged.

[0082] In a specific embodiment, determining whether to decrement by 1 based on the value of each counter specifically includes:

[0083] If the value of one of the counters s[i] in the counter array is equal to Then, with a probability of 1 / 2, the value of s[i] is reduced by 1;

[0084] If the value of one of the counters s[i] in the counter array is less than and greater than 0, directly decrement the value of s[i] by 1;

[0085] If the value of one of the counters s[i] in the counter array is equal to 0, the value of s[i] remains unchanged.

[0086] Specifically, the update process further includes:

[0087] 5. Compare the magnitude relationship between the number l of leading zeros of the sampled data packet x and the value of the counter (s[g(x)]) corresponding to the sampled data packet x:

[0088] If l ≥ s[g(x)] + r - 1, update the value of the counter s[g(x)] to l - r + 1; if l - r + 1 > 3, record the value of s[g(x)] as 3, because the counter has only 2 bits and can only record up to 3. That is, before the sampling is actually performed, each data packet is pre-associated with a sampling probability (i.e., the value of the counter).

[0089] If l < s[g(x)] + r - 1, no operation is performed.

[0090] 6. Check whether the current value of n reaches the fixed threshold v;

[0091] If yes, execute the next round of operation;

[0092] If no, end the update process.

[0093] Because the recording range of the counter is limited, imagine that when the values of all counters in the counter array are 3, no more data can be recorded even if more data comes in, and at this time, it is in a saturated state. Therefore, n ≥ v is used as an indicator that the counter array is about to reach a saturated state.

[0094] Table 2 describes the details of entering the next round of operation. First, is incremented by 1. Then, the algorithm traverses all counters and checks their values. The values of all counters, i.e., s[0], s[1], ..., s[m-1], are checked; if the value is 3, it is decremented by 1 with a probability of 1 / 2. Otherwise, if 0 < s[i] < 3, the value of the counter is directly decremented by 1. In addition, the algorithm continuously updates the value. (If the value of a counter (e.g., s[i]) is decremented to 0, the value of n is updated in real time (n represents the number of counters with a value greater than 0)).

[0095] Table 2

[0096]

[0097] The next round of operations proceeds as follows: When this operation is required (i.e., n ≥ v), it indicates that the counter is saturated (meaning the current counter can no longer record more data). The next round of operations then proceeds as follows:

[0098] 1. Increment the value of r by 1, which means the sampling probability becomes 1 / 2 of the original.

[0099] Initially, r=0, meaning all data packets can update their corresponding counters. When r=1, only data packets with a leading zero count l greater than or equal to 1 can update their corresponding counters; these packets are expected to be half the total number. This process continues as r increases.

[0100] 2. Check the value of each counter in the counter array, i.e., s[0], s[1], ..., s[m-1]. For a certain counter s[i], if its value is:

[0101] a) If it equals 3, then subtract 1 from s[i] with a probability of 1 / 2.

[0102] b) If the value is less than 3 but greater than 0, subtract 1 directly.

[0103] c) equals 0, remains unchanged.

[0104] When it is necessary to remove items that do not meet the sampling probability, this can be done by decrementing the counter value by 1. Furthermore, reducing the counter value allows the counter to have more cardinality.

[0105] The two steps above embody the idea of ​​rolling record. Since each counter is 2 bits in size, it can only record 4 numbers (0, 1, 2, 3). 0 is used to indicate that the counter has not been recorded by the data packet, leaving only 3 numbers: 1, 2, and 3. The number 1 corresponds to the case where the number of leading zeros in the data packet is l = r, 2 corresponds to l = r + 1, and 3 corresponds to the case where l ≥ r + 2. When r = 0, 1, 2, and 3 correspond to l = 0, 1, and 2 respectively. When r = 1, 1, 2, and 3 correspond to l = 1, 2, and 3. It can be seen that as r increases, the value of the leading zeros corresponding to the counter value continuously increases.

[0106] S4, query the estimated value of the cardinality currently recorded based on the values ​​of m, n, and r.

[0107] In a specific embodiment, the estimated value of the currently recorded cardinality is... .

[0108] Specifically, check , and The value is then determined using the formula. Calculate the estimated value.

[0109] refer to Figure 3 The embodiments of this application provide some examples to illustrate operational details. Assuming... , .

[0110] Example 1: When data packets Upon arrival, calculate Length of leading zeros .because Continue calculating Hash location .because The original value was 0, so it was directly set to 0. Set as In addition, Increase by 1.

[0111] Example 2: The corresponding counter value is greater than 0. Because... ,use Overwrite the original counter value. Note that, due to... It can only record the value of the counter as 3.

[0112] Example 3: When calculating of At that time, it was discovered The value is lower than the original counter value of 2. Therefore, the counter value is not updated.

[0113] Example 4: First calculate of .because The update process has ended.

[0114] Example 5: When When it occurs, the corresponding counter The value was set from 0 to 3, therefore Increase from 7 to 8. Since the values ​​of all counters are greater than 0 (i.e., ... Then, proceed to the next round of operations.

[0115] Proceed to the next round: Iterate through the value of each counter. Counter The values ​​of all of them are less than 3, so their counter values ​​are decremented by 1. The value of is 3, so according to the probability of 1 / 2, Subtract 1, and It remains unchanged.

[0116] Query: If you want to update After obtaining the estimated value, we get... .

[0117] The cardinality estimation method based on dynamic interval expansion proposed in the embodiments of this application supports union and intersection operations.

[0118] Union: Table 3 illustrates the detailed process of the union operation. The algorithm is illustrated with two examples. , As input. Then, Set as and The larger one. If According to Set the value of the counter for I. However, if ,but The value recorded in the middle should be greater than Big, because The leading zeros recorded in the middle are longer. The situation follows a similar process. Finally, query... The estimated value.

[0119] Table 3

[0120]

[0121] Intersection: The intersection is calculated using the inclusion-exclusion principle. Assume that for... , The intersection of two instances is calculated by... To obtain an estimate of the intersection.

[0122] Although a 2-bit counter array is used as an example in the embodiments of this application, the size of the counter can be generalized to [other applications]. Position, among which The only difference between the different counter sizes is the recording range. (Using...) A bit counter, the counting capacity can be expanded to... Row 7 in Table 1 has now become... .

[0123] Although larger counters can record longer leading zero lengths, embodiments of this application suggest that a 2-bit counter is sufficient to achieve high accuracy, or even better. The reason is:

[0124] (i) With the same amount of memory, a larger counter leads to a smaller counter array length, which exacerbates hash collisions and reduces accuracy.

[0125] (ii) Using a rolling recording mechanism, a 2-bit counter is sufficient to record leading zeros of any length. To better illustrate these reasons, relevant experiments were conducted, and the results show that the DREX version with the 2-bit counter consistently achieves the highest accuracy.

[0126] The following description compares the cardinality estimation method based on dynamic interval expansion proposed in the embodiments of this application with other existing methods.

[0127] Given a dataset The goal is to compute the dataset. The number of unique items in the text is expressed as follows: It means that, among them , Represents the dataset A single item in the [database]. To efficiently estimate the cardinality. ,refer to Figure 4 Existing counting methods can be mainly divided into three categories:

[0128] (i) Bitmap-based methods, using a size of A bitmap or a combination of multiple bitmaps;

[0129] (ii) Maintaining a method based on leading zeros. indivual Bit counter, the length of leading zeros in the hash value of a record. ;

[0130] (iii) Based on the method of sequential statistics, track the first Small observed hash value .

[0131] These methods are typically built upon a hash function. Based on this, the function determines the bits / counter to be hashed or generates a hash value for a given item. The specific details of these three counting methods are described below:

[0132] (i) Bitmap-based method: Linear Counting (LC) utilizes a size of A bitmap is used to count distinct items. Each input item is hashed to... One of the units digits; if the corresponding bit is initially 0, it is set to 1. To obtain an estimate of the radix, the number of bits in the bitmap that are not set to 1 is calculated and represented as... The estimated base is From this formula, we can deduce that the maximum counting range of LC is... (When all bits in the bitmap are set to 1). This also shows that the memory required by LC increases linearly with the cardinality to be counted. Therefore, LC is not suitable for processing datasets with large cardinality.

[0133] A MultiResolution Bitmap (MRB) consists of multiple bitmaps, each with a different sampling probability. Assume the MRB has... Each bitmap is represented as follows: .forward Each bitmap in the bitmap has The last bitmap has... Position. Based on the paper's recommendations, with... The sampling probability for the first Individual image ( The update is performed. For each input item, the MRB selects based on the sampling probability. Update one bitmap at a time and set the corresponding bit to 1. If the number of bits set in a bitmap exceeds a predefined threshold, the bitmap is considered saturated. During a query, the MRB iterates from the first bitmap to the last and finds the first unsaturated bitmap. This bitmap then serves as the base bitmap, represented as... (Assuming it is the first) (each bitmap). Then calculate separately. The number of bits that are not set to 1, and represented as Then you can... This formula calculates the estimated base.

[0134] Self-morphing Bitmap (SMB) adjusts its sampling probability based on the number of unique items observed so far. It maintains a bitmap of length... The bitmap and three parameters: This indicates the number of bits that are set to 1 in the current round; Indicates the current round number; It is the threshold used to determine whether to proceed to the next round. SMB uses... and The state begins. All items in the data stream are hashed to a random bit in the bitmap; if the hashed bit is initially 0, it is set to 1, and... Increase by 1. Once Reaching the threshold (in ,For example SMB will pass through Add 1 and Reset to 0 to proceed to the next round. In the next round... In the middle, the sampling probability of the bitmap is set to Ultimately, it can be achieved through the formula. The estimated cardinality is obtained, where S is the cardinality for different... The adjustment factor array.

[0135] The maximum count range of MRB is The maximum counting range for SMB is Furthermore, the configuration of MRB and SMB is closely related to the estimated cardinality of the dataset. When dealing with large datasets, the cardinality can be increased by adjusting the MRB. Values ​​were adapted to accommodate a larger counting range, but due to The value will therefore become relatively small, potentially leading to reduced accuracy over a smaller count range. Similarly, SMB faces the same problem in balancing accuracy and dataset cardinality.

[0136] (ii) Leading-zero-based method: HyperLogLog (HLL) is an improved version of the classic cardinality statistics methods FM and LogLog, which share the same design philosophy. HLL utilizes the mathematical property of leading zeros in hash functions to estimate the cardinality of a dataset, where the hash result is infinitely close to a random model. Let... It is a hash function that maps an item to a random binary string. According to mathematical expectation, approximately... The item has in its hash result The pattern. This pattern indicates that the hash result is... It starts with a series of consecutive zeros, followed by a 1. Therefore, This indicates the length of leading zeros in the hash result.

[0137] HLL Maintenance An integer counter is used to record the length of leading zeros. Specifically, each item... Hash to One of the counters, the process used In The HLL then calculates the length of the leading zeros in the remaining bits of the hash value. and will With Item The values ​​recorded in the corresponding counters are compared. If the original value is smaller, then... Cover it.

[0138] Cardinality estimation for HLL involves calculating the harmonic mean of all counters and applying bias correction to improve the accuracy of the estimation. Let... It is the first The value of each counter can be obtained through... We obtain the cardinality estimate, where It depends on The correction constant. Unlike LC, MRB, and SMB, HLL offers a larger counting range, reaching... On the other hand, while HLL is accurate over a large range of counts, it is less accurate on small cardinality datasets.

[0139] HyperLogLog++ (HLLP) further improves the estimation accuracy of HLL on small cardinality by combining empirical bias correction and sparse representation. However, it makes adjustment decisions based on predefined thresholds rather than the patterns of the actual dataset, which may lead to a loss of accuracy.

[0140] (iii) Methods based on ordinal statistics: The design philosophy of K-Minimum-Value (KMV) is that if Each item is uniformly and randomly hashed to a number between 0 and 1, and the expected distance between two adjacent hash values ​​is approximately... Therefore, the first The expectation of a small hash value is Then, it can be done through Estimate .

[0141] KMV maintains a sorted list that tracks the observed current... The smallest hash value. When a new item... Upon arrival, it is hashed as ,in KMV checks whether to... Insert into the sorted list to maintain its position in the list. The minimum value. To obtain the estimated cardinality, KMV retrieves the th minimum value from the sorted list. Minimum value and return .

[0142] Note that the above estimation is biased. To address this bias, Beyer et al. proposed a KMV estimation correction, which... This revised estimate proved to be unbiased, thus providing a more accurate estimate of the cardinality. The unbiased estimate was obtained by... Subtracting 1 from the numerator to adjust the numerator provides a correction to reduce estimation bias. Assuming KMV uses a 32-bit counter in the sorting list, the maximum count range is... However, KMV estimates are less accurate when dealing with small cardinality.

[0143] As mentioned above, LC exhibits excellent performance, including significant accuracy and performance efficiency, but it incurs linear memory consumption and only supports a small counting range. To overcome this limitation, embodiments of this application propose a baseline method that dynamically expands the counting range of LC while maintaining low memory overhead. The baseline method works as follows: when LC reaches saturation (reaching its maximum counting range, denoted as LC), When the baseline method increases the range size to twice its original size, its counting range will automatically expand. Here, we assume that the baseline method increases the range size to twice its original size (i.e., Therefore, the counting range dynamically changes from... Increase to Then to , And so on. The counting range increases with the cardinality of the observed items, thus enabling an approximately infinite counting range within a finite space.

[0144] To implement this baseline method, two basic techniques are utilized: adaptive sampling and bit reclamation.

[0145] (1) Adaptive Sampling: The update process begins from an initial state with a sampling probability of 1 (meaning all items are counted). When the bitmap saturates (i.e., all bits are set to 1 or the number of bits set to 1 reaches a predefined threshold), it reaches its maximum counting range and cannot be used for further counting. Therefore, the current sampling probability is halved (i.e., reduced from 1 to 1 / 2). When LC is updated with a sampling probability of 1 / 2, the counting range of LC expands to twice its original size. Increase to .

[0146] (2) Bit Recovery: Simply reducing the sampling probability is insufficient for continued counting after saturation, because it is also necessary to recover the 1 bits in the bitmap to 0 bits to accommodate more items for counting. Furthermore, it is essential to ensure that the estimated cardinality remains consistent before and after the reduction in sampling probability to avoid loss of accuracy. To address these two issues, the equations are solved... To perform bit reclamation, where This indicates the number of 1-bit bits that need to be recycled. Then, randomly select from within the bitmap. Each bit set to 1 is recycled, and the bitmap is updated with a sampling probability of 1 / 2.

[0147] Repeat the two techniques described above each time the bitmap saturates. Figure 5 This process is described. Assume the bitmap has 8 bits, and the current sampling rate is 1 / 4. Since all 8 bits are set to 1, 5 bits are randomly selected for recycling, and the sampling probability is adjusted to 1 / 8 to expand the counting range from... Expand to When querying, assume the current sampling probability is... The number of bits not set to 1 in the bitmap is 'a' represents the number of bits that need to be set to 0 each time the bitmap is saturated, and 'U' represents the number of bits in the bitmap that are set to 0 each time the bitmap is queried. Therefore, the estimated cardinality is... This is equivalent to The dataset is sampled with a probability of LC and the bitmap is updated using LC.

[0148] However, the baseline method introduces significant errors because it cannot distinguish duplicates. For example, suppose the sampling probability is 1 / 4, and an item x is hashed to the second bit and then set to 1. After the sampling probability is adjusted to 1 / 8, the second bit is reset to 0. However, a duplicate item x is sampled, and the second bit is set to 1 again. In this case, x is counted repeatedly, leading to an overestimation of the cardinality. Therefore, the embodiments of this application implement dynamic range expansion based on the baseline method and provide a guarantee of high accuracy. The cardinality estimation method based on dynamic range expansion (DREX) proposed in the embodiments of this application is based on three core technologies: lazy sampling, rolling record, and counter retrieval. Lazy sampling is based on the principle of adaptive sampling, but each bit in LC is expanded into a multi-bit counter to maintain more sampling states. Rolling record continuously rolls the counting range of each counter, enabling the counter to count larger values ​​using only 2 bits. Counter retrieval extends the bit retrieval idea in the baseline method. The details are described below:

[0149] Lazy sampling: Due to the limitations of bitmap data structures in baseline methods in terms of accurate counting, DREX maintains a data structure of size 1. An array of counters, where each counter Contains multiple bits, such as Figure 2 As shown. Here, a multi-bit counter ( Figure 2 The two bits in the middle serve the same purpose as the bits in the baseline method. Furthermore, DREX uses a... Bit-based cyclic counter This is used to store the current sampling probability. Finally, the number of counters with a value of 0 is calculated to estimate the cardinality.

[0150] DREX uses the mathematical property of leading zeros in random binary strings for sampling, similar to the leading zero-based methods described above. Based on mathematical expectation, the binary string of a random hash... The project has A leading zero. If we use probability... Sampling is equivalent to selecting only those with... Select items with leading zeros, or only select items with leading zeros greater than 1. The item. Loop counter. A threshold for leading zeros is stored in DREX; items below this threshold will not be sampled.

[0151] DREX samples items in a lazy manner. It pre-associates each item with a sampling probability before actually performing the sampling. Specifically, the sampling probability assigned to an item is... ,in This is the length of the leading zeros corresponding to the item. By using multi-bit counters instead of single-bit counters, DREX is able to maintain the sampling state of items and adjust them accordingly. Each multi-bit counter... Record the largest it observes When the counter array is like a bit Figure 1 When the sample is in a saturated state, DREX uses a loop counter to... Incrementing by 1 halves the sampling probability. Then, DREX removes all items from the counter array whose associated sampling probability is higher than the adjusted sampling probability. Specifically, it sets the counter value to no more than [a certain value]. The counter is reset to 0. Once an item is removed from DREX, subsequent duplicates in the same stream are no longer sampled by DREX because their corresponding leading zero lengths are less than 0. In this way, DREX reduces the error caused by repeated counting in the baseline method.

[0152] Rolling Recording: Expanding each bit into a multi-bit counter increases memory overhead. To reduce memory overhead, DREX fixes each counter at 2 bits and uses a rolling method to record the maximum value (l) observed by each counter. That is, each time... When adding, DREX will also update the data stored in the database. The offset in. The counting range will change as The counter scrolls forward as the number of entries increases. Since a 2-bit counter has only four counting states, with state 00 indicating no entries, the remaining three states 01, 10, and 11 represent offsets 0, 1, and 2, respectively. Therefore, DREX actually... The information recorded in the middle is When the offset is greater than 2, Set its own state to 11, which means recording the offset in an approximate way. The value is determined by Given, such as Figure 6 As shown.

[0153] Counter reclamation: When most of the counters in the DREX have values ​​greater than 0, it indicates that some operation is needed to prevent them from reaching their maximum counting capacity (similar to bitmap saturation in the baseline method). This application refers to such an operation as counter reclamation. First, the... Increase by 1 (i.e., now) This allows for the recording of larger amounts of data. This expands the counting range of the embodiments of this application. Thereafter, only Only items that are specified can update the counter array. Because... There are two possibilities:

[0154] (i) Sometimes, .because 1 has been added. The value should be reduced by 1 accordingly.

[0155] (ii) When At that time, it was impossible to distinguish. (The counter value should remain unchanged) and (The counter value should be subtracted by 1) In these two cases, such as Figure 6 As shown. However, due to expectations ,because and Therefore, for each counter with a value of 3, subtract 1 with a 1 / 2 probability.

[0156] How to obtain the estimate: Treat each 2-bit counter as one bit in Linear Counting. If the counter value... If the value is greater than 0, it is considered a bit set to 1 in LC. This is because the counter for values ​​greater than 0 is... Project updates, the "bits" in DREX The probability is set to 1. Ultimately, through... Obtain an estimate of the cardinality, where This refers to the number of non-zero counters in the DREX. The update process also shows that the count range of the DREX depends only on the record. The size of the counter. Used for recording. of Bit counters will support Maximum counting capacity.

[0157] Table 4 summarizes the properties of the cardinality estimation method based on dynamic range expansion (DREX) proposed in this application and the existing different counting methods in terms of counting range, update time and query time.

[0158] Table 4

[0159]

[0160] Statistical range: The upper limit of the statistical range for LC, MRB, and SMB is limited by the number of bits in the bitmap (i.e., ) limitations. Conversely, HLL, KMV, and DREX are not limited by memory constraints. Specifically, the maximum statistical range using the 32-bit counter KMV is [missing information]. By using Bit counters, HLL can implement The statistical range. Similarly, DREX can be defined by using a Bit counter to implement The counting range.

[0161] Update Time: Update time complexity is quantified by considering the total number of hash calculations and heap operations involved. LC requires only one hash calculation, while MRB and HLL require two. SMB and DREX require one base hash calculation, plus an additional hash calculation based on the current sampling rate. The decision involves an additional hash calculation. It's important to note that KMV involves a hash calculation and a potential heap adjustment operation.

[0162] Query time: Although LC and MRB require iterating through all bits to return an estimate of the cardinality, the query time can be reduced to a minimum by maintaining an additional variable to record the number of set bits. Similarly, SMB, KMV, and DREX can obtain the estimated cardinality from the currently maintained variables, thereby achieving... The query time. However, HLL needs to check the values ​​of all counters, resulting in the need for... The query time.

[0163] The following comparison of DREX performance with Linear Counting (LC), MultiResolution Bitmap (MRB), K MinimumValue (KMV), Self-morphing Bitmap (SMB), HyperLogLog (HLL), and HyperLogLog++ (HLLP) is performed using various datasets.

[0164] (1) Experimental setup

[0165] Test platform: The experiment was conducted on a server running Ubuntu 18.04.6. The server was equipped with a sixteen-core Intel i7-10700 2.90GHz CPU and 32GB of RAM.

[0166] Datasets: The datasets used in the experiments include:

[0167] CAIDA: It contains anonymized tracing data collected from the backbone links. We selected the datasets 16A, 16B, 18A, 18B, 19A, and 19B, which contain 41 million, 88 million, 79 million, 281 million, 122 million, and 284 million different IPv4 data streams, respectively.

[0168] MAWI: It contains daily tracking data along the transit link from the widest point to the upstream ISP. Data collected between February 1, 2017 and February 10, 2017 was selected, totaling 109 million distinct IPv4 data streams.

[0169] UNIV1, UNIV2: Data collected from universities. Their total base numbers are 557,000 and 192,000 respectively.

[0170] ENT: Data collected from within the company. Total base is 1 million.

[0171] Retail: It contains an anonymized basket of retail market data from an anonymous retail store in Belgium. The total base is 16,470.

[0172] Kosarak: It contains clickstream data from anonymized Hungarian online news portals. The total base is 41,270.

[0173] Webdocs: It consists of a set of crawled web HTML documents. The total base is 5 million.

[0174] Algorithm parameters: fixed in DREX For SMB, the settings should be configured according to the recommendations in the original paper. For MRB, let It should be noted that because HLLP requires at least 16 counters, it will not produce results in 32-bit and 64-bit memory environments.

[0175] (2) Accuracy under large-scale datasets

[0176] The counting range is divided into four sub-ranges: Range 1 ( - ), Range 2 ( - ), range 3 ( - ) and range 4 ( - The number of bits allocated within each counting range is from... Increase to The average relative error was measured for each counting range. To ensure the reliability of the results, 10 replicate experiments were conducted with different hash seeds, and their average results were calculated. See [link to results]. Figures 7 to 13 As shown in the figure, similar trends exist in the results across different datasets. This is assuming sufficient memory is allocated (e.g., within range 1). arrive LC exhibits the highest accuracy (in bits). However, within a large counting range (i.e., 2 to 4 bits), it struggles to provide accurate estimates because LC easily saturates (all bits are set to 1). The accuracy of MRB and SMB is also negatively affected by saturation. KMV, along with HLL, HLLP, and DREX, provides a larger counting range, but KMV has lower accuracy, especially when memory is limited (e.g., less than 1000 bits). HLLP improves the accuracy of HLL in small memory scenarios, while their accuracy is similar when memory is large. In most cases, DREX achieves the lowest relative error, especially when memory size is small (i.e.,...). arrive When the memory size is between and When the memory is between 32 bits, DREX's mean relative error is lower than HLLP (which performs best among all state-of-the-art methods) by 10.5%, 14.9%, 30.0%, 15.8%, 41.3%, 25.6%, and 25.4% in 16A, 16B, 18A, 18B, 19A, 19B, and mawi, respectively. DREX also has the lowest mean relative error across all datasets when the memory is 32 bits or 64 bits.

[0177] (3) Accuracy in small datasets

[0178] The number of bits allocated from Increase to The average relative error was observed over the entire counting range, and 100 repeated experiments were conducted, with the hash seed changed accordingly to obtain the average relative error. Results are shown below. Figure 14 For small datasets, LC, MRB, and SMB perform better because they require only a small amount of memory to cover the entire count range. However, when the allocated memory is small (i.e., (Below 32 bits), DREX still outperforms state-of-the-art methods in most cases. Furthermore, when sufficient memory is allocated, DREX's accuracy is comparable to other methods. Compared to HLL, KM, LC, MRB, and SMB, DREX's mean relative error is 6.3%, 81.7%, 82.2%, 55.3%, and 63.3% lower, respectively. Although DREX's mean relative error is 4.5% higher than HLLP, HLLP cannot operate with 32-bit or 64-bit memory.

[0179] (4) Update speed

[0180] This application also demonstrates the update throughput of various methods on CAIDA-16A, and results for other datasets are omitted due to similarity of results. In the experiments, the allocated memory size was fixed, and the cardinality to be counted was varied to observe the number of packets processed per second (MPPS).

[0181] like Figure 15 As shown, LC consistently exhibits higher throughput because it only requires one hash calculation for each incoming item. KMV has the highest throughput when memory is limited or the cardinality to be counted is large because it triggers fewer heap operations. DREX and SMB can both adaptively reduce their sampling probabilities, so their throughput increases with the cardinality to be counted. However, when the cardinality is small, DREX updates slightly slower than SMB. When the cardinality is large or memory is limited, DREX outperforms SMB. Furthermore, HLL and HLLP always require two hash calculations, resulting in relatively lower throughput. Compared to HLLP, DREX has an average update throughput that is 5.5% higher, but 8.8% lower than MRB and SMB.

[0182] (5) Query speed

[0183] This application uses the CAIDA-19A dataset to measure query throughput. Similar trends were observed in other datasets, so results from those datasets are omitted. Memory size from Increase to It is worth noting that because KMV relies primarily on division operations during the query process, its query speed reaches up to 600 MPPS (higher than other methods), therefore the results of KMV are not shown in the figure.

[0184] according to Figure 16 DREX, LC, MRB, and SMB exhibit comparable query throughput because they all require logarithmic operations. Among them, LC achieves the highest average query throughput because it does not involve exponential operations. In some cases (e.g.) Figure 16 (b) In the case of bits, the logarithmic calculation (terms) are omitted because SMB has reached saturation. (With zero), SMB achieved a query speed of 200 MPPS. In other cases, DREX's average query throughput was 1.01 times higher than SMB. Furthermore, HLL and HLLP exhibited the lowest query throughput, and their throughput decreased with increasing memory size because their query time complexity was zero. Overall, DREX's average query throughput is 4.09 times, 4.13 times, and 1.95 times higher than HLL, HLLP, and MRB, respectively.

[0185] (6) The effect of the value of q on accuracy

[0186] To demonstrate that a 2-bit counter can produce optimal results, this application further evaluated accuracy and parameters. The relationship between them. Specifically, keeping the total memory constant, while... The value of is varied from 2 to 5, and the relative error is observed for each configuration. This experiment was conducted using the CAIDA-19A dataset; similar results were obtained for other datasets.

[0187] Figure 17 The display shows that when At this time, the relative error is at its lowest in most cases, especially when allocated memory is limited. With The increase in value, The reduction in the number of bit counters leads to a significant decrease in accuracy. On average, relative error ratio , and They were 16.6%, 21.9%, and 40.2% lower, respectively.

[0188] In summary: While LC, MRB, and SMB offer high accuracy within their counting ranges, they require significant memory to deliver accurate results when counting datasets with large cardinality. On the other hand, HLL and HLLP are slow to query and can lead to packet loss in network scenarios where estimates need to be queried for each packet. KMV offers high update and query speeds but falls short of the other methods in terms of accuracy. In contrast, DREX demonstrates high accuracy across a wide range of configurations and datasets while maintaining query and update speeds comparable to MRB, SMB, and LC.

[0189] The following is a theoretical analysis of the cardinality estimation method based on dynamic interval expansion proposed in the embodiments of this application, to prove that both the relative error and standard error of DREX have upper bounds.

[0190] when At that time, the counter value is changed with a 1 / 2 probability. Subtract 1. It has now been proven that this operation does not affect accuracy.

[0191] Lemma 1: According to expectation, for The operation of the counter has no impact on accuracy.

[0192] Proof: When At that time, this means And the counter should remain unchanged, or And the counter should be decremented by 1. Because There are four possibilities:

[0193] (i) And it remains unchanged correctly.

[0194] (ii) And it incorrectly subtracted 1.

[0195] (iii) And correctly subtract 1.

[0196] (iv) And it incorrectly remains unchanged.

[0197] This application has and . because This application has .when or When this happens, it means an error has occurred during the counter retrieval process. However, and They are also complementary, meaning their errors can cancel each other out. A quarter of the counters with a value of 3 are incorrectly decremented by 1, while a quarter of the counters with a value of 3 that should have been decremented remain unchanged. Therefore, operations on the counters with a value of 3 are expected not to affect accuracy.

[0198] Lemma 2: In cardinality At that time, variable The value is equal to a certain value The probability is .

[0199] Proof: After proving that... After ensuring that the relevant operations do not affect accuracy, this application can treat the 2-bit counter as a complete integer counter (i.e., with an infinite number of bits). In this case, This is equivalent to all counters having values ​​no less than 1. This situation is equivalent to the method described in the paper. The problem involves several non-independent samplers, where each sampler has a sampling probability of 1 / 2. Subsequently, the lemma was proved.

[0200] Theorem 1: Assumption And the base number is The upper bound of the relative error of DREX is .

[0201] Proof: This application provides proof based on the analysis of Linear Counting. When hour, The probability of it being non-zero is .when hour, The probability of it being non-zero is In accepting After n distinct terms, the probability that the counter value remains zero is Record this event as And let the number of counters with non-zero values ​​be . Therefore, we have:

[0202] (1)

[0203] (2)

[0204] make ,but

[0205] (3)

[0206] (4)

[0207] Estimated base Then we set , ,have:

[0208] (5)

[0209] As discussed in the paper, this application truncates the terms after the second term in Formula 5, resulting in:

[0210] (6)

[0211] therefore,

[0212] (7)

[0213] The theorem is proved.

[0214] Theorem 2: Assumption And the base number is , The upper bound of the standard deviation is .

[0215] Proof: The standard error of the algorithm is... The standard deviation. Formula 5 is truncated after the second term, therefore:

[0216] (8)

[0217] in Then we get:

[0218] (9)

[0219] therefore, The standard deviation is:

[0220] (10)

[0221] Q.E.D.

[0222] The steps S1-S4 above do not necessarily represent the order of the steps, but are represented by step symbols. The order of the steps can be adjusted.

[0223] Further reference Figure 18 As an implementation of the methods shown in the above figures, this application provides an embodiment of a cardinality estimation device based on dynamic interval expansion, which is similar to... Figure 2 Corresponding to the method embodiments shown, this device can be specifically applied to various electronic devices.

[0224] This application provides a cardinality estimation device based on dynamic interval expansion, comprising:

[0225] Array construction module 1 is configured as a counter array consisting of m z-bit counters, where z≥2;

[0226] Sampling module 2 is configured to, during the update process, acquire data packets, calculate the hash value of the data packets and count the number of leading zeros in the hash value. In response to determining that the number of leading zeros in the hash value of the data packet is greater than or equal to the variable threshold r, the data packet is determined to be a sampled data packet. The counter corresponding to the sampled data packet is determined in the counter array. In response to determining that the value of the counter corresponding to the sampled data packet is 0, the value of the number n of counters with non-zero values ​​in the counter array is incremented by 1. The values ​​of the variable threshold r and the number n are initially 0.

[0227] Update module 3 is configured to update the value of the counter corresponding to the sampled data packet based on the number of leading zeros in the hash value of the data packet and the value of the counter corresponding to the sampled data packet. In response to the determination that the value of the number n is greater than or equal to the fixed threshold v, the next round of operation is executed. In the next round of operation, the variable threshold r is incremented by 1, and it is determined whether to decrement it by 1 based on the value of each counter in the counter array.

[0228] Query module 4 is configured to query the estimated value of the cardinality currently recorded based on the values ​​of m, n, and r.

[0229] The above description is merely a preferred embodiment of this application and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of the invention involved in this application is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described inventive concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features with similar functions disclosed in this application.

Claims

1. A cardinality estimation method based on dynamic interval expansion, characterized in that, Includes the following steps: Construct a counter array consisting of m z-bit counters, where z≥2, and the counter array is used to record the number of unique items in the network data stream with limited memory; During the update process, data packets in the network data stream are acquired, the hash value of the data packets is calculated, and the number of leading zeros in the hash value is counted. In response to determining that the number of leading zeros in the hash value of the data packets is greater than or equal to the variable threshold r, the data packet is determined to be a sampled data packet. The counter corresponding to the sampled data packet is determined in the counter array. In response to determining that the value of the counter corresponding to the sampled data packet is 0, the value of the number n of counters with non-zero values ​​in the counter array is incremented by 1. The values ​​of the variable threshold r and the number n are initially 0. The value of the counter corresponding to the sampled data packet is updated based on the number of leading zeros in the hash value of the data packet and the value of the counter corresponding to the sampled data packet, specifically including: Let l be the number of leading zeros in the hash value of the data packet. In response to determining that l ≥ s[g(x)] + r - 1, the value of the counter s[g(x)] corresponding to the sampled data packet is updated to l - r + 1. If l - r + 1 > 1, then the value of the counter s[g(x)] is updated to l - r + 1. The value of the counter s[g(x)] corresponding to the sampled data packet is then... ; In response to determining that l < s[g(x)] + r - 1, the value of the counter s[g(x)] corresponding to the sampled data packet remains unchanged. In response to determining that the value of the number n is greater than or equal to the fixed threshold v, the next round of operation is executed. In the next round of operation, the variable threshold r is incremented by 1, and it is determined whether to decrement by 1 based on the value of each counter in the counter array. Specifically, this includes: If the value of one of the counters s[i] in the counter array is equal to Then, with a probability of 1 / 2, the value of s[i] is reduced by 1; If the value of one of the counters s[i] in the counter array is less than If the value is greater than 0, then directly decrement the value of s[i] by 1, and check if s[i] has been reduced to 0. If so, decrement n by 1. If the value of one of the counters s[i] in the counter array is equal to 0, then the value of s[i] remains unchanged; The estimated cardinality of the currently recorded data can be queried based on the values ​​of m, n, and r, so as to dynamically expand the counting range and perform cardinality statistics on network data streams with limited memory.

2. The cardinality estimation method based on dynamic interval expansion according to claim 1, characterized in that, The counter array contains m z-bit counters, s[0], s[1], ..., s[m-1], with values ​​of 0, 1, 2, ..., . One of them.

3. The cardinality estimation method based on dynamic interval expansion according to claim 1, characterized in that, The step of determining the counter corresponding to the sampled data packet in the counter array specifically includes: The sampled data packet x is input into a hash function to obtain a value g(x) in the range [0, m-1], and s[g(x)] is the counter corresponding to the sampled data packet.

4. The cardinality estimation method based on dynamic interval expansion according to claim 1, characterized in that, Also includes: In response to determining that the value of the counter corresponding to the sampled data packet is not 0, the value of n, the number of counters in the counter array with non-zero values, remains unchanged; The update process ends when the number of leading zeros in the hash value of the data packet is less than a variable threshold r, or when the number n is less than a fixed threshold v.

5. The cardinality estimation method based on dynamic interval expansion according to claim 1, characterized in that, The estimated value of the currently recorded cardinality is .

6. A cardinality estimation device based on dynamic interval expansion, characterized in that, include: The array construction module is configured as a counter array consisting of m z-bit counters, where z≥2, and the counter array is used to record the number of unique items in the network data stream with limited memory. The sampling module is configured to, during the update process, acquire data packets from the network data stream, calculate the hash value of the data packets and count the number of leading zeros in their hash values. In response to determining that the number of leading zeros in the hash value of the data packets is greater than or equal to a variable threshold r, the data packet is determined to be a sampled data packet. The counter corresponding to the sampled data packet is determined in the counter array. In response to determining that the value of the counter corresponding to the sampled data packet is 0, the value of the number n of non-zero counters in the counter array is incremented by 1. The variable threshold r and the number n are initially set to 0. The update module is configured to update the value of the counter corresponding to the sampled data packet based on the number of leading zeros in the hash value of the data packet and the value of the counter corresponding to the sampled data packet, specifically including: Let l be the number of leading zeros in the hash value of the data packet. In response to determining that l ≥ s[g(x)] + r - 1, the value of the counter s[g(x)] corresponding to the sampled data packet is updated to l - r + 1. If l - r + 1 > 1, then the value of the counter s[g(x)] is updated to l - r + 1. The value of the counter s[g(x)] corresponding to the sampled data packet is then... ; In response to determining that l < s[g(x)] + r - 1, the value of the counter s[g(x)] corresponding to the sampled data packet remains unchanged. In response to determining that the value of the number n is greater than or equal to the fixed threshold v, the next round of operation is executed. In the next round of operation, the variable threshold r is incremented by 1, and it is determined whether to decrement by 1 based on the value of each counter in the counter array. Specifically, this includes: If the value of one of the counters s[i] in the counter array is equal to Then, with a probability of 1 / 2, the value of s[i] is reduced by 1; If the value of one of the counters s[i] in the counter array is less than If the value is greater than 0, then directly decrement the value of s[i] by 1, and check if s[i] has been reduced to 0. If so, decrement n by 1. If the value of one of the counters s[i] in the counter array is equal to 0, then the value of s[i] remains unchanged; The query module is configured to query the estimated cardinality of the currently recorded data based on the values ​​of m, n, and r, so as to dynamically expand the counting range and perform cardinality statistics on the network data stream within limited memory.

7. An electronic device, comprising: One or more processors; Storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any one of claims 1-5.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1-5.