Counting method, user base counting method, corresponding apparatus and electronic device

By generating a predetermined number of storage containers and dynamically updating the kmax value and harmonic parameters in the HyperLogLog algorithm, the performance bottleneck of the HyperLogLog algorithm in real-time scenarios is solved, achieving more efficient counting and user base statistics.

CN116450672BActive Publication Date: 2026-02-03TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210006919.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-05
Publication Date
2026-02-03
Estimated Expiration
2042-01-05

AI Technical Summary

Technical Problem

The existing HyperLogLog algorithm becomes a performance bottleneck in scenarios with very high real-time requirements, especially in scenarios with many writes and many reads, where it needs to traverse all storage containers for cumulative calculation, resulting in excessively long processing time.

Method used

By generating a predetermined number of storage containers, the preset total kmax value and harmonic parameters are dynamically updated in response to data writing. When reading, the updated parameters are used directly to determine the counting result, avoiding the accumulation process and optimizing the real-time statistical performance of the HyperLogLog algorithm.

Benefits of technology

It effectively reduces processing time and greatly improves the performance of the HyperLogLog algorithm in real-time counting scenarios, especially in scenarios with multiple writes and reads, where the processing time is reduced to less than 1/10 of the original.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116450672B_ABST
    Figure CN116450672B_ABST
Patent Text Reader

Abstract

The embodiment of the application provides a counting method, a user base counting method, corresponding devices and electronic equipment, relates to technical fields of big data, cloud computing, block chains and the like, and when the method counts based on target data by using a HyperLogLog algorithm, each time new target data is written, a preset total kmax value harmonic parameter is dynamically updated according to an old value and a new value of a storage container changed by writing, that is, a first kmax value and a second kmax value, when counting is read, the preset total kmax value harmonic parameter can be directly used to determine a counting result, an accumulation process is avoided, processing time is effectively reduced, and the performance of the HyperLogLog algorithm in a real-time counting scene is greatly improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing technology, and more specifically, to a counting method, a user base statistics method, and corresponding apparatus and electronic equipment. Background Technology

[0002] HyperLogLog, an advanced data structure in Redis (Remote Dictionary Server), is an algorithm used for cardinality counting. The advantage of HyperLogLog is that even with a very large number or size of input elements, the storage space required for computation remains fixed and small, a stark contrast to traditional counting methods where memory consumption increases with the number of input elements.

[0003] The current implementation of the HyperLogLog algorithm requires traversing all storage containers for each count iteration, involving an cumulative calculation process. For scenarios with low real-time requirements, such as calculating every 5 minutes, where data writes are frequent but count reads are infrequent, the existing HyperLogLog algorithm is not a bottleneck. However, for scenarios with very high real-time requirements, such as scenarios where a count needs to be read for every data write (i.e., scenarios with frequent writes and reads), this implementation becomes a performance bottleneck. Summary of the Invention

[0004] The purpose of this application is to solve the performance bottleneck problem of the current HyperLogLog algorithm.

[0005] According to one aspect of the embodiments of this application, a counting method is provided, the method comprising:

[0006] When using the HyperLogLog algorithm to count based on target data, a predetermined number of storage containers are generated. These storage containers are used to write the kmax value of the HyperLogLog algorithm corresponding to the target data.

[0007] In response to the writing of new target data, determine the target storage container corresponding to the new target data, and the first kmax value corresponding to the new target data;

[0008] Get the second kmax value in the current target storage container;

[0009] Update the preset total kmax value harmonic parameter based on the first kmax value and the second kmax value;

[0010] In response to the count of reads of the target data that has been written, the count result is determined based on the preset total kmax value harmonic parameter and the predetermined quantity.

[0011] In an optional implementation, it further includes:

[0012] Based on a predetermined quantity, the preset total kmax value and harmonic parameters are initialized.

[0013] In an optional implementation, updating the preset total kmax value harmonic parameter based on the first kmax value and the second kmax value includes:

[0014] If the first kmax value is greater than the second kmax value, then the preset total kmax value harmonic parameter is updated based on the first kmax value and the second kmax value.

[0015] In an optional implementation, updating the preset total kmax value harmonic parameter based on the first kmax value and the second kmax value includes:

[0016] Determine the difference between the first kmax value and the second kmax value;

[0017] Based on the difference value, update the preset total kmax value harmonic parameter.

[0018] In an optional implementation, updating the preset total kmax value harmonic parameter based on the first kmax value and the second kmax value includes:

[0019] The preset total kmax value harmonic parameter is updated based on the first and second kmax values ​​according to the following formula:

[0020]

[0021] Where presum is the preset total kmax value harmonic parameter, newkmax is the first kmax value, and oldkmax is the second kmax value.

[0022] In an optional implementation, the counting result is determined based on a preset total kmax value harmonic parameter and a predetermined quantity, including:

[0023] The counting result is determined based on the following formula, using a preset total kmax value harmonic parameter and a predetermined quantity:

[0024]

[0025] Where n is the counting result, constant is the correction constant, m is the predetermined quantity, and presum is the preset total kmax value harmonic parameter.

[0026] According to one aspect of the embodiments of this application, a user base statistics method is provided, the method comprising:

[0027] Obtain the identity identifiers of users who accessed the web pages to be analyzed;

[0028] Using identity identifiers as target data, the counting method provided in the embodiments of this application is used to determine the user base statistics of the webpage to be counted.

[0029] In an optional implementation, determining the target storage container corresponding to the new identity and the first kmax value corresponding to the new identity includes:

[0030] Perform a hash operation on the new identity identifier to obtain a bit string of the first predetermined length;

[0031] Based on the first second predetermined bit string in the first predetermined bit string, determine the target storage container corresponding to the new identity identifier;

[0032] In the remaining bits of the first predetermined bit string excluding the first second predetermined bit string, determine the bit position where 1 appears first to obtain the first kmax value corresponding to the new identity identifier.

[0033] According to another aspect of the embodiments of this application, a counting device is provided, the device comprising:

[0034] The generation module is used to generate a predetermined number of storage containers when using the HyperLogLog algorithm to count based on the target data. The storage containers are used to write the kmax value of the HyperLogLog algorithm corresponding to the target data.

[0035] The determination module is used to determine the target storage container corresponding to the new target data and the first kmax value corresponding to the new target data in response to the writing of new target data.

[0036] The acquisition module is used to obtain the second kmax value in the current target storage container;

[0037] The update module is used to update the preset total kmax value harmonic parameters based on the first kmax value and the second kmax value.

[0038] The counting module is used to count the number of reads of the target data that has been written, and determines the counting result based on the preset total kmax value harmonic parameter and the predetermined quantity.

[0039] In an optional implementation, the apparatus further includes: an initialization module, configured to:

[0040] Based on a predetermined quantity, the preset total kmax value and harmonic parameters are initialized.

[0041] In an optional implementation, when the update module is used to update the preset total kmax value harmonic parameter based on the first kmax value and the second kmax value, it is specifically used for:

[0042] If the first kmax value is greater than the second kmax value, then the preset total kmax value harmonic parameter is updated based on the first kmax value and the second kmax value.

[0043] In an optional implementation, when the update module is used to update the preset total kmax value harmonic parameter based on the first kmax value and the second kmax value, it is specifically used for:

[0044] Determine the difference between the first kmax value and the second kmax value;

[0045] Based on the difference value, update the preset total kmax value harmonic parameter.

[0046] In an optional implementation, when the update module is used to update the preset total kmax value harmonic parameter based on the first kmax value and the second kmax value, it is specifically used for:

[0047] The preset total kmax value harmonic parameter is updated based on the first and second kmax values ​​according to the following formula:

[0048]

[0049] Where presum is the preset total kmax value harmonic parameter, newkmax is the first kmax value, and oldkmax is the second kmax value.

[0050] In an optional implementation, when determining the counting result based on a preset total kmax value harmonic parameter and a predetermined quantity, the counting module is specifically used for:

[0051] The counting result is determined based on the following formula, using a preset total kmax value harmonic parameter and a predetermined quantity:

[0052]

[0053] Where n is the counting result, constant is the correction constant, m is the predetermined quantity, and presum is the preset total kmax value harmonic parameter.

[0054] According to another aspect of the embodiments of this application, a user base counting device is provided, the device comprising:

[0055] The identity identification acquisition module is used to obtain the identity identification of users who access the webpage to be analyzed;

[0056] The user base statistics module is used to determine the user base statistics result of the webpage to be counted by using identity identifiers as target data and employing the counting method provided in the embodiments of this application.

[0057] In an optional implementation, the user base statistics module, when determining the target storage container corresponding to the new identity and the first kmax value corresponding to the new identity, specifically performs the following:

[0058] Perform a hash operation on the new identity identifier to obtain a bit string of the first predetermined length;

[0059] Based on the first second predetermined bit string in the first predetermined bit string, determine the target storage container corresponding to the new identity identifier;

[0060] In the remaining bits of the first predetermined bit string excluding the first second predetermined bit string, determine the bit position where 1 appears first to obtain the first kmax value corresponding to the new identity identifier.

[0061] According to another aspect of the present application, an electronic device is provided, the electronic device including: a memory, a processor and a computer program stored in the memory, the processor executing the computer program to implement the steps of the counting method or the user base statistics method provided in the embodiments of the present application.

[0062] According to another aspect of the embodiments of this application, a computer-readable storage medium is provided, on which a computer program is stored, wherein when the computer program is executed by a processor, the steps of the counting method or the user base statistics method provided in the embodiments of this application are implemented.

[0063] According to another aspect of the embodiments of this application, a computer program product is provided, which includes a computer program that, when executed by a processor, implements the steps of the counting method or the user base statistics method provided in the embodiments of this application.

[0064] The counting method, user base statistics method, corresponding device, and electronic device provided in this application, when using the HyperLogLog algorithm to count based on target data, dynamically update the preset total kmax value harmonic parameter each time new target data is written, based on the old and new values ​​of a storage container that have been changed by the writing, namely the first kmax value and the second kmax value. When reading the count, the preset total kmax value harmonic parameter can be directly used to determine the counting result, avoiding the accumulation process, effectively reducing processing time, and greatly improving the performance of the HyperLogLog algorithm in real-time counting scenarios. Attached Figure Description

[0065] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments of this application will be briefly introduced below.

[0066] Figure 1 A flowchart illustrating a counting method provided in an embodiment of this application;

[0067] Figure 2 A flowchart illustrating a user base statistics method provided in an embodiment of this application;

[0068] Figure 3 This is a schematic diagram of the structure of a counting device provided in an embodiment of this application;

[0069] Figure 4 A schematic diagram of the structure of a user base counting device provided in an embodiment of this application;

[0070] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0071] The embodiments of this application are described below with reference to the accompanying drawings. It should be understood that the embodiments described below with reference to the accompanying drawings are exemplary descriptions for explaining the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions of the embodiments of this application.

[0072] Those skilled in the art will understand that, unless otherwise stated, the singular forms “a,” “an,” and “the” used herein may also include the plural forms. It should be further understood that the terms “comprising” and “including” as used in embodiments of this application mean that the corresponding feature can be implemented as the presented information, data, steps, elements, and / or components, but do not exclude implementation as other features, information, data, steps, operations, elements, components, and / or combinations thereof supported by the art. It should be understood that when we say that an element is “connected” or “coupled” to another element, the element can be directly connected or coupled to the other element, or it can mean that the element and the other element establish a connection relationship through an intermediate element. Furthermore, “connected” or “coupled” as used herein can include wireless connection or wireless coupling. The term “and / or” as used herein indicates at least one of the items defined by the term; for example, “A and / or B” can be implemented as “A,” or as “B,” or as “A and B.”

[0073] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.

[0074] First, let's introduce and explain several terms used in this application:

[0075] (1) HyperLogLog: Also known as HLL, it is an algorithm used for cardinality counting. In Redis, the HyperLogLog algorithm only requires 12KB of memory to calculate nearly 2^64 different cardins, which has a significant advantage in memory saving during counting.

[0076] (2) UV: Unique Visitor, representing the number of natural people who browse the webpage. In the embodiments of this application, it represents the number of users. Requests from the same user will be deduplicated and counted only once.

[0077] (3) Unique Key: A unique identifier for each user, meaning that different users have different keys.

[0078] (4) Cardinal counting: usually means counting the number of distinct elements in a set of elements.

[0079] (5) Fuse: The reference circuit fuse will immediately blow when the line current is too high to protect the entire circuit system. Similarly, in a computer system, when a module malfunctions, the module's service will be automatically stopped for a period of time until it returns to normal, preventing further damage.

[0080] Since the existing HyperLogLog algorithm implementation is not suitable for scenarios with very high real-time requirements, this application proposes a counting method, a user cardinality statistics method, a corresponding device and electronic equipment, and optimizes the real-time statistical performance of the HyperLogLog algorithm to make it suitable for scenarios with very high real-time requirements.

[0081] To make the optimization of the HyperLogLog algorithm in this application embodiment more intuitive, the principle of the HyperLogLog algorithm is introduced below through an example.

[0082] A coin only has two sides, heads and tails, and the probability of getting heads or tails each time you flip the coin is 1 / 2. Assuming a coin toss results in tails (0) and heads (1), the probability of tossing a 0001 sequence is: In other words, it would take about 16 rounds of coin tossing to get the sequence 0001 (4 tosses per round).

[0083] So, assuming we conduct n rounds of trials, stopping when the toss lands heads in each round, and recording the number of tosses in that round as k (e.g., k1 for the first round, kn for the nth round), where the largest value of k is denoted by kmax, then the probability of kmax occurring in any round is...

[0084] According to maximum likelihood estimation, the maximum number of throws in n rounds of trials is kmax. Therefore, the estimation relationship between n and kmax is:

[0085] n=2 kmax

[0086] However, this estimation has a relatively large error. To reduce the error, one method is to repeat the experiment multiple times. Multiple experiments will yield multiple kmax values, and finally, the average of the kmax values ​​is taken. This method is the implementation of the LogLog algorithm.

[0087] The estimation formula for the LogLog algorithm is as follows:

[0088]

[0089] Where n is the total number of tests, and m is the number of rounds of testing, i.e., m rounds of testing were conducted. The average value is the value of m rounds of trials, i.e., the average value of kmax. Constant is a correction constant, which varies depending on the value of m.

[0090] Furthermore, to make the estimation more accurate, the HyperLogLog algorithm is an optimization of the LogLog algorithm. The difference between the HyperLogLog algorithm and the LogLog algorithm is that the HyperLogLog algorithm uses the harmonic mean, which is the average of the reciprocals, instead of the mean. The harmonic mean reduces the influence of the maximum value on the average value compared to the mean.

[0091] The estimation formula for the HyperLogLog algorithm is as follows:

[0092]

[0093] Among them, DV hll Let n be the total count, and m be the number of rounds of testing, meaning that the same experiment is conducted for m rounds. The harmonic mean of m rounds of trials is used, that is, the kmax harmonic mean is used instead of the kma mean. constant is a correction constant, which varies depending on the value of m.

[0094] As can be seen from the HyperLogLog formula, the calculation involves a cumulative summation process, which can cause a performance bottleneck in scenarios with very high real-time requirements. To address this, the technical solution in this application proposes a real-time statistical performance optimization for the HyperLogLog algorithm.

[0095] The technical solutions of this application and their effects are described below through several exemplary embodiments. It should be noted that the following embodiments can be referenced, borrowed from, or combined with each other. Identical terms, similar features, and similar implementation steps in different embodiments will not be repeated.

[0096] This application provides a counting method, such as... Figure 1 As shown, the method includes:

[0097] Step S101: When using the HyperLogLog algorithm to count based on the target data, a predetermined number of storage containers are generated. The storage containers are used to write the kmax value of the HyperLogLog algorithm corresponding to the target data.

[0098] In this embodiment, the predetermined number of storage containers functions similarly to the number of rounds m in the aforementioned experiment, enabling more accurate estimations. In practical applications, the number of storage containers can also be referred to as the number of buckets.

[0099] In this embodiment, the storage container can be an array or other data storage formats. Taking an array as an example, this step can be understood as allocating an array of a predetermined size (e.g., size m), where each element records the kmax value of the HyperLogLog algorithm corresponding to the target data.

[0100] Step S102: In response to the writing of new target data, determine the target storage container corresponding to the new target data and the first kmax value corresponding to the new target data.

[0101] Whenever new target data is written during the HLL process, the new target data is associated with one of the storage containers. In this step, it is necessary to calculate which storage container the first kmax value corresponding to the new target data should be placed in. Many calculation methods can be used, and this embodiment does not specifically limit the calculation method employed. For example, a specific portion of the target data can be used as the index value of the storage container, or a modulo operation can be used on the target data.

[0102] Furthermore, any value can be converted into a bit string in a computer, which is a binary representation composed of 0s and 1s. In this step, the first kmax value corresponding to the new target data can be calculated based on this. Specifically, the target data is converted into a bit string, where 0s and 1s can be likened to heads and tails on a coin. The first kmax value corresponding to the new target data is determined based on the occurrence of 0s and 1s. As an example, the first kmax value corresponding to the new target data is determined by calculating the offset from a specific position in the bit string until the first 1 appears.

[0103] Step S103: Obtain the second kmax value in the current target storage container.

[0104] In this embodiment of the application, whenever new target data is written to the HLL process, changing the kmax value in the target storage container, the old kmax value of the target storage container before the change is read, i.e., the second kmax value. Correspondingly, the aforementioned first kmax value is the new kmax value of the target storage container after the change.

[0105] Step S104: Update the preset total kmax value harmonic parameter based on the first kmax value and the second kmax value.

[0106] The preset total kmax value harmonic parameter can be understood as a variable. In this embodiment, the preset total kmax value harmonic parameter is used to store a predetermined cumulative sum. That is, the preset total kmax value harmonic parameter can be equivalent to... Where m represents the number of storage containers.

[0107] Considering that each time new target data is written during the HLL process, only one storage container is written, meaning only the value of the target storage container changes, it's unnecessary to accumulate the values ​​of all storage containers. Instead, by saving the cumulative sum after the previous target data write and then adding the changes in the target storage container after the current target data write, a new cumulative sum can be directly obtained.

[0108] In this embodiment, this step can be performed when the first kmax value corresponding to the new target data is greater than the second kmax value corresponding to the target storage container associated with the new target data. That is, if the first kmax value is greater than the second kmax value, the preset total kmax value harmonic parameter is updated based on the first kmax value and the second kmax value. If the first kmax value is less than or equal to the second kmax value, the preset total kmax value harmonic parameter is not updated, and the previously updated preset total kmax value harmonic parameter can be directly used when reading the count.

[0109] In this embodiment, whenever new target data is written during the HLL process, and the first kmax value corresponding to the new target data is greater than the second kmax value corresponding to the target storage container associated with the new target data, the preset total kmax value harmonic parameter is dynamically updated. Specifically, the new total kmax value harmonic parameter is obtained by adding the first kmax value of the target storage container determined in step S102 and the second kmax value of the target storage container determined in step S103, i.e., the new kmax value and the old kmax value of the target storage container, to the preset total kmax value harmonic parameter. This new preset total kmax value harmonic parameter is the new cumulative sum.

[0110] Step S105: In response to the read count of the written target data, determine the count result based on the preset total kmax value harmonic parameter and the predetermined quantity.

[0111] In this embodiment of the application, whenever new target data is written in the HLL process, a counting process of reading the written target data can be performed. Alternatively, a counting process can be performed after multiple target data have been written. This embodiment of the application does not limit this.

[0112] In this embodiment of the application, for each reading of the target data that has been written, the counting result can be determined directly based on the preset total kmax value, the harmonic parameter and the predetermined quantity, thus avoiding the cumulative accumulation process.

[0113] In other words, the counting method provided in this application, when using the HyperLogLog algorithm to count based on target data, dynamically updates the preset total kmax value harmonic parameter each time new target data is written, based on the old and new values ​​of a storage container that has been changed by the writing, namely the first kmax value and the second kmax value. When reading the count, the preset total kmax value harmonic parameter can be directly used to determine the counting result, avoiding the accumulation process, effectively reducing processing time, and greatly improving the performance of the HyperLogLog algorithm in real-time counting scenarios.

[0114] This application provides a possible implementation method. The above technical solution may further include the step of: initializing the preset total kmax value harmonic parameter based on a predetermined quantity.

[0115] The formula for initializing the harmonic parameters of the preset total kmax value is as follows:

[0116] presum = m

[0117] Where m is the predetermined quantity, and presum is the preset total kmax value harmonic parameter.

[0118] In the embodiments of this application, considering that initially each storage container has a value of 0, presum is initialized to m, which is equivalent to the following initialization method. Directly initializing to m avoids the loop process and improves processing efficiency:

[0119]

[0120] In this embodiment of the application, a feasible implementation method is provided for step S104. Specifically, step S104 includes the following steps:

[0121] Step S1041: Determine the difference between the first kmax value and the second kmax value.

[0122] As described above, the HLL process writes only one storage container each time new target data is written. This means only the value of the target storage container changes, so there's no need to accumulate the values ​​of all storage containers. If the change in the target storage container after this data write—that is, the difference between the first and second kmax values—is determined, the preset total kmax value harmonic parameter can be updated.

[0123] Step S1042: Update the preset total kmax value harmonic parameter based on the difference value.

[0124] Specifically, by adding the preset total kmax value harmonic parameter updated after the last target data write to the difference between the first kmax value and the second kmax value determined by the current new target data write, the new preset total kmax value harmonic parameter can be directly obtained.

[0125] In this embodiment of the application, step S104 can be performed based on a formula. Specifically, the preset total kmax value harmonic parameter can be updated based on the first kmax value and the second kmax value according to the following formula:

[0126]

[0127] Where presum is the preset total kmax value harmonic parameter, newkmax is the first kmax value, and oldkmax is the second kmax value.

[0128] It's understandable that initially, presum = m. Starting from the first piece of target data written, each update of the preset total kmax value and harmonic parameters involves adding the current target data. The preset total kmax value harmonic parameter is equivalent to This allows for direct determination of the counting result based on the preset total kmax value and harmonic parameters, avoiding the cumulative stacking process.

[0129] In this embodiment of the application, the above counting method further includes the following steps: if the first kmax value is greater than the second kmax value, then the second kmax value in the current target storage container is updated to the first kmax value; if the first kmax value is less than or equal to the second kmax value, then the value in the target storage container is not updated, that is, the kmax value in the target storage container is kept at the maximum, so as to improve the reliability of the statistical results and ensure the correct processing of the next data write.

[0130] In this embodiment of the application, a feasible implementation method is provided for step S105. Specifically, step S105 includes the step of: determining the counting result based on the following formula, using a preset total kmax value harmonic parameter and a predetermined quantity:

[0131]

[0132] Where n is the counting result, constant is the correction constant, m is the predetermined quantity, and presum is the preset total kmax value harmonic parameter.

[0133] Since the preset total kmax value harmonic parameter is equivalent to This formula is equivalent to the estimation formula of the original HyperLogLog algorithm mentioned above.

[0134] The constant can vary depending on the value of m. In practical applications, those skilled in the art can set the constant according to the actual situation. In this embodiment, the value of constant is not specifically limited.

[0135] The counting method provided in this application optimizes the original HyperLogLog algorithm in the initialization stage, the target data writing stage, and the count reading stage. This avoids the accumulation process, effectively reduces processing time, and greatly improves the performance in real-time counting scenarios.

[0136] The counting method provided in this application can be applied to both real-time and non-real-time counting scenarios. It also enables the counting algorithm to avoid the accumulation process, effectively reduce processing time, and greatly improve counting performance.

[0137] In this embodiment of the application, the improved HyperLogLog probability base counting algorithm can be used for UV statistics.

[0138] Based on this, embodiments of this application provide a method for user base statistics, such as... Figure 2 As shown, the method includes:

[0139] Step S201: Obtain the identity identifier of the user who accessed the webpage to be analyzed;

[0140] When a user needs to access a webpage, they can generate a page access request on their terminal. This request can carry the user's identifier, which is the user's UniqueKey.

[0141] In this embodiment of the application, for the webpage to be counted, the system receives and responds to the page access request from the user requesting access, and obtains the identity identifier of the user accessing the webpage to be counted.

[0142] Step S202: Using the identity identifier as the target data, the counting method provided in the above embodiments is used to determine the user base statistics of the webpage to be counted.

[0143] When using the HyperLogLog algorithm to perform user base statistics based on identity identifiers, a predetermined number of storage containers are generated. These storage containers are used to write the kmax value corresponding to the HyperLogLog algorithm for each identity identifier. In response to the writing of a new identity identifier (i.e., a user initiates an access to the webpage to be counted; in this embodiment, it is not limited whether the user has previously accessed the webpage to be counted, as long as it is a newly initiated page access request, the identity identifier carried in the page access request can be treated as the new identity identifier), the target storage container corresponding to the new identity identifier and the first kmax value corresponding to the new identity identifier are determined. The second kmax value in the current target storage container is obtained. If the first kmax value is greater than the second kmax value, the preset total kmax value harmonic parameter is updated based on the first and second kmax values. In response to the read count of the written identity identifiers, the user base statistics result is determined based on the preset total kmax value harmonic parameter and the predetermined number.

[0144] In this embodiment of the application, the steps of determining the target storage container corresponding to the new identity identifier and the first kmax value corresponding to the new identity identifier may specifically include:

[0145] Step SA: Perform a hash operation on the new identity identifier to obtain a bit string of the first predetermined length;

[0146] As an example, the unique key is hashed into a 64-bit (first predetermined number of bits) bit string. In practical applications, those skilled in the art can set the hash function to generate the bit string of the first predetermined number of bits according to the actual situation. This application does not specifically limit the hash function used or the specific value of the first predetermined number of bits in this embodiment.

[0147] In other embodiments, other algorithms can be used to convert the new identity into a bit string of a first predetermined length, without using hash operations. For example, machine learning algorithms can also be used, but this application does not limit the specific implementation.

[0148] Step SB: Based on the first second predetermined bit string in the first predetermined bit string, determine the target storage container corresponding to the new identity identifier;

[0149] In this embodiment of the application, the converted bit string is divided into two segments, namely, the bit string of the first second predetermined number of bits and the remaining bit string.

[0150] The specific division method, i.e. the specific value of the second predetermined number of digits, can be set according to the actual situation, and this application embodiment does not impose specific limitations on it.

[0151] In this embodiment, the method of determining the target storage container based on the first second predetermined number of bit strings may include, but is not limited to, using the first second predetermined number of bit strings as the index value of the target storage container. Other methods may also be used to determine the target storage container based on the first second predetermined number of bit strings, and this embodiment does not limit the method.

[0152] In this embodiment of the application, the corresponding target storage container is determined by the user's identity identifier, which also achieves the effect of deduplication, that is, the user base is counted.

[0153] Step SC: In the remaining bits of the first predetermined bit string excluding the first second predetermined bit string, determine the bit position where 1 appears first, and obtain the first kmax value corresponding to the new identity identifier.

[0154] Specifically, in the remaining bit string, starting from the first bit, we can calculate until the first 1 appears, and use the value of the first 1 bit as the first kmax value corresponding to the new identity.

[0155] In this embodiment of the application, when the first kma value corresponding to the new identity is greater than the kma value already stored in the target storage container associated with the new identity, the value in the target storage container will be updated to the newly determined first kma. When the first kma value corresponding to the new identity is less than or equal to the kma value already stored in the target storage container associated with the new identity, the value in the target storage container will not be updated, that is, the kma value in the target storage container will be kept at its maximum to improve the reliability of the statistical results.

[0156] For other detailed implementation methods, please refer to the above description of the counting method; the embodiments of this application will not be repeated here.

[0157] To make the advantages of the user base statistics method provided in this application embodiment more apparent, the following two pseudocode snippets describe the differences between the user base statistics method provided in this application embodiment and existing related technologies.

[0158] The pseudocode for UV statistics in existing related technologies is as follows:

[0159]

[0160]

[0161] As can be seen, the pseudocode implementation of UV statistics in existing related technologies involves a for loop process (i.e., the cumulative summation process corresponding to the original HLL formula). Generally, m is taken as 2^15 (i.e., 32768), which is a relatively large loop and may become a performance bottleneck in scenarios with very high real-time requirements.

[0162] The pseudocode for UV statistics provided in this application embodiment is as follows:

[0163]

[0164]

[0165] Compared to existing related technologies where UV statistics require traversing a large loop for each read, which is very time-consuming, the improved user base statistics method in this application takes into account that only the value of a storage container changes each time data is written during the HLL process. Each write uses the cumulative sum saved from the previous write and the old kmax value of the corresponding storage container to calculate the change between the new and old kmax values, so as to dynamically update the cumulative sum. This eliminates the need to accumulate the values ​​of all storage containers, effectively reducing the time consumption and improving the efficiency of user base statistics.

[0166] The user base counting method provided in this application can be applied to circuit breaker systems. Circuit breaker systems require deduplication via unique keys to make real-time decisions on whether to trigger the circuit breaker based on UV statistics. Circuit breaker systems require real-time UV statistics to make circuit breaker decisions, placing very high demands on real-time performance; existing HLL algorithms are not suitable for this. The user base counting method provided in this application significantly optimizes real-time statistical performance and is better suited for scenarios with very high real-time requirements, such as circuit breaker systems.

[0167] In practical applications, the HLL algorithm requires holding a lock to perform read and write operations in a multi-threaded environment. After stress testing, the processing time for a single read counting process reached 200us before the improvement. After the improvement achieved through the technical solution of this application embodiment, the processing time for a single read counting process was reduced to less than 20us, becoming 1 / 10 or even lower than before, which greatly improved the performance of the HLL algorithm in real-time statistics (i.e., multiple writes and multiple reads) scenarios.

[0168] The counting method in this application embodiment can also be applied to many other scenarios that require counting. Some other application scenarios are listed below.

[0169] Scenario 1: Real-time statistics of registered users

[0170] (1) Obtain the user's registered identity and time information;

[0171] (2) Merge the identity identifier and time information to obtain merged information;

[0172] (3) Using the fused information as target data, the counting methods provided in the above embodiments are used to determine the statistical results of registered users.

[0173] Specifically, a predetermined number of storage containers are generated, which are used to write the kmax value of the HyperLogLog algorithm corresponding to the fusion information; in response to the writing of new fusion information, the target storage container corresponding to the fusion information and the first kmax value corresponding to the fusion information are determined; the second kmax value in the current target storage container is obtained; if the first kmax value is greater than the second kmax value, the preset total kmax value harmonic parameter is updated based on the first kmax value and the second kmax value; in response to the read count of the written fusion information, the registered user statistics result is determined based on the preset total kmax value harmonic parameter and the predetermined number.

[0174] For details on the implementation methods and the resulting optimization effects, please refer to the above description of the counting method. The embodiments of this application will not be repeated here.

[0175] Scenario 2: Real-time statistics of access IPs (Internet Protocol)

[0176] (1) Obtain the IP address of the webpage or client accessing the page to be analyzed;

[0177] (2) Using the IP address as the target data, the counting method provided in the above embodiments is used to determine the statistical result of the number of unique IP visits on the day.

[0178] Specifically, a predetermined number of storage containers are generated, which are used to write the kmax value of the HyperLogLog algorithm corresponding to the IP address; in response to the writing of a new IP address, the target storage container corresponding to the IP address and the first kmax value corresponding to the IP address are determined; the second kmax value in the current target storage container is obtained; if the first kmax value is greater than the second kmax value, the preset total kmax value harmonic parameter is updated based on the first kmax value and the second kmax value; in response to the read count of the written IP addresses, the daily unique IP access count statistics are determined based on the preset total kmax value harmonic parameter and the predetermined number.

[0179] For details on the implementation methods and the resulting optimization effects, please refer to the above description of the counting method. The embodiments of this application will not be repeated here.

[0180] Scenario 3: Real-time statistics of the number of different search terms on the same day

[0181] (1) Obtain the binary code corresponding to the terms searched by the user on that day;

[0182] (2) Using binary code as target data, the counting methods provided in the above embodiments are used to determine the number of different terms searched by the user on that day.

[0183] Specifically, a predetermined number of storage containers are generated, which are used to write the kmax value of the HyperLogLog algorithm corresponding to the binary code; in response to the writing of a new binary code, the target storage container corresponding to the binary code and the first kmax value corresponding to the binary code are determined; the second kmax value in the current target storage container is obtained; if the first kmax value is greater than the second kmax value, the preset total kmax value harmonic parameter is updated based on the first kmax value and the second kmax value; in response to the read count of the written binary code, the daily unique IP access count statistics are determined based on the preset total kmax value harmonic parameter and the predetermined number.

[0184] For details on the implementation methods and the resulting optimization effects, please refer to the above description of the counting method. The embodiments of this application will not be repeated here.

[0185] Those skilled in the art will understand that the above scenarios are merely examples, and appropriate variations based on these examples may also be applied to this application and should therefore be included within the scope of protection of this application.

[0186] In practical applications, the counting method or user base statistics method provided in this application can be executed by a computer device with computing capabilities, such as a terminal or server. The terminal can be a laptop, tablet, desktop computer, set-top box, smart speaker, mobile device (e.g., mobile phone, portable music player, personal digital assistant, portable gaming device, smartwatch, smart voice interaction device, vehicle terminal, etc.), smart home appliance (e.g., but not limited to smart TV), smart robot, or workshop equipment, but is not limited to these. The server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services.

[0187] Furthermore, the counting method or user base statistics method provided in the embodiments of this application can also be completed collaboratively by multiple computer devices or components with computing capabilities. For example, different computer devices or components may each complete a portion of the steps of the counting method or user base statistics method provided in the embodiments of this application.

[0188] As described above, the technical solutions provided in this application embodiment may be executed by a cloud server providing cloud computing services. Cloud computing refers to the delivery and usage model of IT infrastructure, meaning obtaining required resources through the network in an on-demand and easily scalable manner. In a broader sense, cloud computing refers to the delivery and usage model of services, meaning obtaining required services through the network in an on-demand and easily scalable manner. Such services can be IT and software-related, internet-related, or other services. Cloud computing is a product of the development and integration of traditional computer and network technologies such as grid computing, distributed computing, parallel computing, utility computing, network storage technologies, virtualization, and load balancing.

[0189] With the development of the internet, real-time data streams, and the diversification of connected devices, as well as the demands for search services, social networks, mobile commerce, and open collaboration, cloud computing has rapidly developed. Unlike previous parallel distributed computing, cloud computing will fundamentally revolutionize the entire internet model and enterprise management model.

[0190] Based on this, the technical solutions provided in this application may also involve big data technology. Big data refers to data sets that cannot be captured, managed, and processed using conventional software tools within a certain time frame. It represents massive, rapidly growing, and diverse information assets that require new processing models to achieve stronger decision-making, insight discovery, and process optimization capabilities. With the advent of the cloud era, big data has attracted increasing attention. Big data requires specialized technologies to effectively process large amounts of data within a tolerable time frame. Technologies suitable for big data include massively parallel processing databases, data mining, distributed file systems, distributed databases, cloud computing platforms, the Internet, and scalable storage systems.

[0191] Optionally, the data involved in the technical solutions provided in this application embodiment can be stored in a blockchain. Blockchain is a novel application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms. Essentially, a blockchain is a decentralized database, a chain of data blocks linked using cryptographic methods. Each data block contains information about a batch of network transactions, used to verify the validity of the information (anti-counterfeiting) and generate the next block. A blockchain can include a blockchain underlying platform, a platform product service layer, and an application service layer.

[0192] The underlying blockchain platform can include processing modules such as user management, basic services, smart contracts, and operational control. The user management module is responsible for managing the identity information of all blockchain participants, including maintaining public and private key generation (account management), key management, and maintaining the correspondence between user real identities and blockchain addresses (access management). Furthermore, under authorization, it monitors and audits transactions of certain real identities and provides risk control rule configuration (risk control audit). The basic services module is deployed on all blockchain node devices to verify the validity of business requests. After consensus is reached on valid requests, they are recorded in storage. For a new business request, the basic services first perform interface adaptation parsing and authentication (interface adaptation), and then encrypt the business information through a consensus algorithm (consensus algorithm). The encryption process ensures that the encrypted data is transmitted consistently and completely to the shared ledger (network communication) and recorded and stored. The smart contract module is responsible for contract registration, issuance, triggering, and execution. Developers can define contract logic using a programming language and publish it to the blockchain (contract registration). Based on the contract terms, the module calls keys or other events to trigger execution and complete the contract logic. It also provides functions for contract upgrades and cancellations. The operations control module is mainly responsible for deployment, configuration modification, contract settings, cloud adaptation, and real-time visualization of the product's running status during product release, such as alarms, network conditions, and node device health status.

[0193] The platform's product service layer provides the basic capabilities and implementation frameworks for typical applications. Developers can leverage these basic capabilities, along with the specific characteristics of their business needs, to implement blockchain-based business logic. The application service layer provides blockchain-based application services to business stakeholders.

[0194] Furthermore, the embodiments described above also involve machine learning (ML) algorithms. Machine learning is a multidisciplinary field involving probability theory, statistics, approximation theory, convex analysis, algorithm complexity theory, and many other disciplines. It specifically studies how computers can simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental way to endow computers with intelligence; its applications span all areas of artificial intelligence. Machine learning and deep learning typically include techniques such as artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and instructional learning.

[0195] Machine learning falls under the field of Artificial Intelligence (AI). AI utilizes digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceiving the environment, acquiring knowledge, and using that knowledge to achieve optimal results. In other words, AI is a comprehensive technology within computer science that attempts to understand the essence of intelligence and produce new intelligent machines that can react in a way similar to human intelligence. AI studies the design principles and implementation methods of various intelligent machines, enabling them to possess perception, reasoning, and decision-making capabilities.

[0196] With the research and advancement of artificial intelligence (AI) technology, AI is being studied and applied in various fields, such as smart homes, smart wearable devices, virtual assistants, smart speakers, smart marketing, autonomous driving, drones, robots, smart healthcare, smart customer service, vehicle networking, and intelligent transportation. It is believed that with the development of technology, AI will be applied in more fields and play an increasingly important role.

[0197] The technical solutions provided in this application can be applied to fields such as medical cloud, cloud gaming, cloud computing education (CCEDU), cloud social networking, and intelligent transportation. Specifically, in these scenarios, for situations requiring the statistical analysis of user base or online users, corresponding user identifiers can be obtained and used as target data. The aforementioned counting methods can then be employed for real-time or non-real-time counting. Furthermore, the counting results can be displayed or otherwise processed accordingly.

[0198] Medical cloud refers to a cloud platform for healthcare services created using cloud computing, mobile technology, multimedia, 4G communication, big data, and the Internet of Things, combined with medical technology. This platform enables the sharing of medical resources and expands the scope of medical services. Because of the application of cloud computing technology, medical cloud improves the efficiency of medical institutions and facilitates access to medical care for residents. Features such as hospital appointment booking and medical insurance are products of the integration of cloud computing and the medical field. Medical cloud also offers advantages such as data security, information sharing, dynamic expansion, and a global deployment.

[0199] Cloud gaming, also known as gaming on demand, is an online gaming technology based on cloud computing. It enables thin clients with relatively limited graphics processing and data processing capabilities to run high-quality games. In cloud gaming, the game does not reside on the player's terminal but runs on a cloud server. The cloud server renders the game scene as a video and audio stream, which is then transmitted to the player's terminal via the network. The player's terminal does not need powerful graphics processing and data processing capabilities; it only needs basic streaming media playback capabilities and the ability to receive player input commands and send them to the cloud server.

[0200] Cloud education refers to educational platform services based on cloud computing business models. On the cloud platform, all educational institutions, training institutions, enrollment service agencies, publicity agencies, industry associations, management agencies, industry media, legal structures, etc., are centrally integrated into a resource pool. These resources can be displayed and interacted with each other, communicate on demand, and reach agreements, thereby reducing education costs and improving efficiency.

[0201] Cloud-based social networking is a virtual social application model that integrates the Internet of Things, cloud computing, and mobile internet. Its purpose is to establish a well-known "resource-sharing relationship graph" to facilitate online social interaction. The main characteristic of cloud-based social networking is the unified integration and evaluation of a large amount of social resources, forming an effective resource pool to provide services to users on demand. The more users participate in sharing, the greater the value created.

[0202] Intelligent Traffic Systems (ITS), also known as Intelligent Transportation Systems, effectively integrate advanced science and technology (information technology, computer technology, data communication technology, sensor technology, electronic control technology, automatic control theory, operations research, artificial intelligence, etc.) into transportation, service control, and vehicle manufacturing. This strengthens the connection between vehicles, roads, and users, thereby forming a comprehensive transportation system that ensures safety, improves efficiency, enhances the environment, and saves energy.

[0203] This application provides a counting device, such as... Figure 3 As shown, the counting device 30 may include: a generation module 301, a determination module 302, an acquisition module 303, an update module 304, and a counting module 305, wherein,

[0204] The generation module 301 is used to generate a predetermined number of storage containers when counting based on target data using the HyperLogLog algorithm. The storage containers are used to write the kmax value of the HyperLogLog algorithm corresponding to the target data.

[0205] The determination module 302 is used to determine the target storage container corresponding to the new target data and the first kmax value corresponding to the new target data in response to the writing of new target data.

[0206] The acquisition module 303 is used to acquire the second kmax value in the current target storage container;

[0207] The update module 304 is used to update the preset total kmax value harmonic parameter based on the first kmax value and the second kmax value;

[0208] The counting module 305 is used to count the reads of the written target data and determine the counting result based on the preset total kmax value harmonic parameter and the predetermined quantity.

[0209] In an optional embodiment, the device further includes: an initialization module 306, configured to:

[0210] Based on a predetermined quantity, the preset total kmax value and harmonic parameters are initialized.

[0211] In an optional implementation, when updating the preset total kmax value harmonic parameter based on the first kmax value and the second kmax value, the update module 304 is specifically used for:

[0212] If the first kmax value is greater than the second kmax value, then the preset total kmax value harmonic parameter is updated based on the first kmax value and the second kmax value.

[0213] In an optional implementation, when updating the preset total kmax value harmonic parameter based on the first kmax value and the second kmax value, the update module 304 is specifically used for:

[0214] Determine the difference between the first kmax value and the second kmax value;

[0215] Based on the difference value, update the preset total kmax value harmonic parameter.

[0216] In an optional implementation, when updating the preset total kmax value harmonic parameter based on the first kmax value and the second kmax value, the update module 304 is specifically used for:

[0217] The preset total kmax value harmonic parameter is updated based on the first and second kmax values ​​according to the following formula:

[0218]

[0219] Where presum is the preset total kmax value harmonic parameter, newkmax is the first kmax value, and oldkmax is the second kmax value.

[0220] In an optional implementation, when determining the counting result based on a preset total kmax value harmonic parameter and a predetermined quantity, the counting module 305 is specifically used for:

[0221] The counting result is determined based on the following formula, using a preset total kmax value harmonic parameter and a predetermined quantity:

[0222]

[0223] Where n is the counting result, constant is the correction constant, m is the predetermined quantity, and presum is the preset total kmax value harmonic parameter.

[0224] The counting device provided in this application embodiment can execute the counting method provided in this application embodiment. The implementation principle is similar. The actions performed by each module in the counting device of each embodiment of this application correspond to the steps in the counting method of each embodiment of this application. For detailed functional descriptions of each module of the counting device, please refer to the descriptions in the corresponding methods shown above, which will not be repeated here.

[0225] The counting device provided in this application, when using the HyperLogLog algorithm to count based on target data, dynamically updates the preset total kmax value harmonic parameter each time new target data is written, based on the old and new values ​​of a storage container that have been changed by the writing, namely the first kmax value and the second kmax value. When reading the count, the preset total kmax value harmonic parameter can be directly used to determine the counting result, avoiding the accumulation process, effectively reducing processing time, and greatly improving the performance of the HyperLogLog algorithm in real-time counting scenarios.

[0226] The counting device provided in this application can be applied to both real-time and non-real-time counting scenarios. It also enables the counting algorithm to avoid the accumulation process, effectively reducing processing time and greatly improving counting performance.

[0227] This application also provides a user base counting device, such as... Figure 4 As shown, the user base counting device 40 may include: an identity verification module 401 and a user base counting module 402, wherein,

[0228] The identity identification acquisition module 401 is used to acquire the identity identification of users who access the webpage to be analyzed;

[0229] The user base statistics module 402 is used to determine the user base statistics result of the webpage to be counted by using the identity identifier as the target data and employing the counting method provided in the embodiments of this application.

[0230] The user base counting device provided in this application embodiment can execute the user base counting method provided in this application embodiment. The implementation principle is similar. The actions performed by each module in the user base counting device of each embodiment of this application correspond to the steps in the user base counting method of each embodiment of this application. For detailed functional descriptions of each module of the user base counting device, please refer to the descriptions in the corresponding methods shown above, which will not be repeated here.

[0231] The user base counting device provided in this application dynamically updates the cumulative sum by calculating the change between the new and old kmax values ​​each time data is written, based on the cumulative sum saved in the previous write and the old kmax value read from the corresponding storage container. This eliminates the need to accumulate the values ​​of all storage containers, effectively reducing time consumption and improving the efficiency of user base counting.

[0232] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules are not, in some cases, limiting the scope of the module itself.

[0233] As an example, the counting device or user base counting device provided in this application embodiment may be a computer program (including program code) running on a computer device. For example, the counting device or user base counting device may be a component or module of an application program; the counting device or user base counting device may be used to execute the corresponding content in the foregoing method embodiments.

[0234] In some embodiments, the counting device or user base counting device provided in this application can be implemented in a combination of hardware and software. As an example, the counting device or user base counting device provided in this application can be a processor in the form of a hardware decoding processor, which is programmed to execute the aforementioned method embodiments provided in this application. For example, the processor in the form of a hardware decoding processor can be one or more application-specific integrated circuits (ASICs), DSPs, programmable logic devices (PLDs), complex programmable logic devices (CPLDs), field-programmable gate arrays (FPGAs), or other electronic components.

[0235] Based on the same principles as the methods shown in the embodiments of this application, this application provides an electronic device, including a memory, a processor, and a computer program stored in the memory. The processor executes the computer program to implement the steps of the counting method or user base statistics method provided in the foregoing embodiments. Compared with related technologies, it can achieve the following: when using the HyperLogLog algorithm to count based on target data, each time new target data is written, the preset total kmax value harmonic parameter is dynamically updated according to the old value and new value of a storage container that has been changed by the writing, namely the first kmax value and the second kmax value. When reading the count, the preset total kmax value harmonic parameter can be directly used to determine the counting result, avoiding the accumulation process, effectively reducing processing time, and greatly improving the performance of the HyperLogLog algorithm in real-time counting scenarios.

[0236] In one alternative embodiment, an electronic device is provided, such as Figure 5 As shown, Figure 5 The illustrated electronic device 500 includes a processor 501 and a memory 503. The processor 501 and the memory 503 are connected, for example, via a bus 502. Optionally, the electronic device 500 may further include a transceiver 504, which can be used for data interaction between the electronic device and other electronic devices, such as sending and / or receiving data. It should be noted that in practical applications, the transceiver 504 is not limited to one type, and the structure of this electronic device 500 does not constitute a limitation on the embodiments of this application.

[0237] Processor 501 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. Processor 501 may also be a combination that implements computational functions, such as including one or more microprocessor combinations, a combination of a DSP and a microprocessor, etc.

[0238] Bus 502 may include a pathway for transmitting information between the aforementioned components. Bus 502 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. Bus 502 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 5 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.

[0239] The memory 503 may be ROM (Read Only Memory) or other types of static storage devices capable of storing static information and instructions, RAM (Random Access Memory) or other types of dynamic storage devices capable of storing information and instructions, or EEPROM (Electrically Erasable Programmable Read Only Memory), CD-ROM (Compact Disc Read Only Memory) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital universal optical discs, Blu-ray discs, etc.), magnetic disk storage media, other magnetic storage devices, or any other medium capable of carrying or storing computer programs and capable of being read by a computer, without limitation herein.

[0240] The memory 503 is used to store computer programs that execute the embodiments of this application, and the execution is controlled by the processor 501. The processor 501 is used to execute the computer programs stored in the memory 503 to implement the steps shown in the foregoing method embodiments.

[0241] Electronic devices include, but are not limited to, terminals and servers. Terminals can be laptops, tablets, desktop computers, set-top boxes, smart speakers, mobile devices (e.g., mobile phones, portable music players, personal digital assistants, portable gaming devices, smartwatches, smart voice interaction devices, in-vehicle terminals, etc.), smart home appliances (e.g., but not limited to smart TVs), smart robots, or workshop equipment, but are not limited to these. Servers can be independent physical servers, server clusters or distributed systems composed of multiple physical servers, or cloud servers providing cloud computing services.

[0242] This application provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it can implement the steps and corresponding content of the aforementioned method embodiments.

[0243] This application also provides a computer program product, including a computer program that, when executed by a processor, can implement the steps and corresponding content of the aforementioned method embodiments.

[0244] The aforementioned computer programs can be written in one or more programming languages, or a combination thereof. These programming languages ​​include object-oriented programming languages—such as Java, Smalltalk, and C++—as well as conventional procedural programming languages—such as C or similar languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or it can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0245] The terms "first," "second," "1," "2," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in a sequence other than that shown in the figures or text.

[0246] It should be understood that although arrows indicate various operation steps in the flowcharts of this application's embodiments, the order in which these steps are implemented is not limited to the order indicated by the arrows. Unless explicitly stated herein, in some implementation scenarios of this application's embodiments, the implementation steps in each flowchart can be executed in other orders as required. Furthermore, some or all steps in each flowchart, based on the actual implementation scenario, may include multiple sub-steps or multiple stages. Some or all of these sub-steps or stages can be executed at the same time, and each sub-step or stage can also be executed at different times. In scenarios where execution times differ, the execution order of these sub-steps or stages can be flexibly configured according to requirements, and this application's embodiments do not limit this.

[0247] The above are only optional implementation methods for some implementation scenarios of this application. It should be noted that for those skilled in the art, other similar implementation methods based on the technical concept of this application, without departing from the technical concept of this application, also fall within the protection scope of the embodiments of this application.

Claims

1. A counting method, characterized in that, include: When using the HyperLogLog algorithm to count based on target data, a predetermined number of storage containers are generated. These storage containers are used to write the kmax value of the HyperLogLog algorithm corresponding to the target data. In response to the writing of new target data, the target storage container corresponding to the new target data and the first kmax value corresponding to the new target data are determined. Get the second kmax value in the current target storage container; Update the preset total kmax value harmonic parameter based on the first kmax value and the second kmax value; In response to the count of reads of the written target data, the count result is determined based on the preset total kmax value harmonic parameter and the predetermined quantity; The step of updating the preset total kmax value harmonic parameter based on the first kmax value and the second kmax value includes: The difference between the first kmax value and the second kmax value is determined. The difference is determined based on the difference between the reciprocal of the first counting result and the reciprocal of the second counting result. The first counting result is a counting result estimated based on the first kmax value, and the second counting result is a counting result estimated based on the second kmax value. Based on the difference value, update the preset total kmax value harmonic parameter; The quotient of the predetermined quantity and the preset total kmax value harmonic parameter is used to characterize the harmonic average of the predetermined number of rounds of trials, and the counting result is determined based on the product of the harmonic average, the predetermined quantity and the correction constant.

2. The counting method according to claim 1, characterized in that, Also includes: Based on the predetermined quantity, the preset total kmax value harmonic parameter is initialized.

3. The counting method according to claim 1, characterized in that, The step of updating the preset total kmax value harmonic parameter based on the first kmax value and the second kmax value includes: If the first kmax value is greater than the second kmax value, then the preset total kmax value harmonic parameter is updated based on the first kmax value and the second kmax value.

4. The counting method according to claim 1, characterized in that, The step of updating the preset total kmax value harmonic parameter based on the first kmax value and the second kmax value includes: The preset total kmax value harmonic parameter is updated based on the first kmax value and the second kmax value according to the following formula: Wherein, presum is the preset total kmax value harmonic parameter, newkmax is the first kmax value, and oldkmax is the second kmax value.

5. The counting method according to any one of claims 1-4, characterized in that, Based on the preset total kmax value harmonic parameter and the predetermined quantity, the counting result is determined, including: The counting result is determined according to the following formula, based on the preset total kmax value harmonic parameter and the predetermined quantity: Where n is the counting result, constant is the correction constant, m is the predetermined quantity, and presum is the preset total kmax value harmonic parameter.

6. A method for user base statistics, characterized in that, include: Obtain the identity identifiers of users who accessed the web pages to be analyzed; Using the identity identifier as target data, the counting method described in any one of claims 1-5 is used to determine the user base statistics of the webpage to be counted.

7. The user base statistics method according to claim 6, characterized in that, Determine the target storage container corresponding to the new identity, and the first kmax value corresponding to the new identity, including: Perform a hash operation on the new identity identifier to obtain a bit string of a first predetermined length; Based on the first second predetermined bit string in the first predetermined bit string, determine the target storage container corresponding to the new identity identifier; In the remaining bits of the first predetermined bit string excluding the first second predetermined bit string, determine the bit position where 1 appears first to obtain the first kmax value corresponding to the new identity identifier.

8. A counting device, characterized in that, include: The generation module is used to generate a predetermined number of storage containers when counting based on target data using the HyperLogLog algorithm. The storage containers are used to write the kmax value of the HyperLogLog algorithm corresponding to the target data. A determination module is used to determine, in response to the writing of new target data, the target storage container corresponding to the new target data and the first kmax value corresponding to the new target data; The acquisition module is used to obtain the second kmax value in the current target storage container; The update module is used to update the preset total kmax value harmonic parameter based on the first kmax value and the second kmax value; The counting module is used to count the reads of the written target data and determine the counting result based on the preset total kmax value harmonic parameter and the predetermined quantity. Specifically, when the update module is used to update the preset total kmax value harmonic parameter based on the first kmax value and the second kmax value, it is used for: The difference between the first kmax value and the second kmax value is determined. The difference is determined based on the difference between the reciprocal of the first counting result and the reciprocal of the second counting result. The first counting result is a counting result estimated based on the first kmax value, and the second counting result is a counting result estimated based on the second kmax value. Based on the difference value, update the preset total kmax value harmonic parameter; The quotient of the predetermined quantity and the preset total kmax value harmonic parameter is used to characterize the harmonic average of the predetermined number of rounds of trials, and the counting result is determined based on the product of the harmonic average, the predetermined quantity and the correction constant.

9. The counting device according to claim 8, characterized in that, The device further includes: An initialization module is used to initialize the preset total kmax value harmonic parameters based on the predetermined quantity.

10. The counting device according to claim 8, characterized in that, When the update module is used to update the preset total kmax value harmonic parameter based on the first kmax value and the second kmax value, it is specifically used for: If the first kmax value is greater than the second kmax value, then the preset total kmax value harmonic parameter is updated based on the first kmax value and the second kmax value.

11. The counting device according to claim 8, characterized in that, When the update module is used to update the preset total kmax value harmonic parameter based on the first kmax value and the second kmax value, it is specifically used for: The preset total kmax value harmonic parameter is updated based on the first kmax value and the second kmax value according to the following formula: Wherein, presum is the preset total kmax value harmonic parameter, newkmax is the first kmax value, and oldkmax is the second kmax value.

12. The counting device according to any one of claims 8-11, characterized in that, When the counting module is used to determine the counting result based on the preset total kmax value harmonic parameter and the predetermined quantity, it is specifically used for: The counting result is determined according to the following formula, based on the preset total kmax value harmonic parameter and the predetermined quantity: Where n is the counting result, constant is the correction constant, m is the predetermined quantity, and presum is the preset total kmax value harmonic parameter.

13. A user base counting device, characterized in that, include: The identity identification acquisition module is used to obtain the identity identification of users who access the webpage to be analyzed; The user base statistics module is used to determine the user base statistics result of the webpage to be counted by using the identity identifier as target data and employing the counting method described in any one of claims 1-5.

14. The user base counting device according to claim 13, characterized in that, The user base statistics module, when determining the target storage container corresponding to the new identity and the first kmax value corresponding to the new identity, is specifically used for: Perform a hash operation on the new identity identifier to obtain a bit string of a first predetermined length; Based on the first second predetermined bit string in the first predetermined bit string, determine the target storage container corresponding to the new identity identifier; In the remaining bits of the first predetermined bit string excluding the first second predetermined bit string, determine the bit position where 1 appears first to obtain the first kmax value corresponding to the new identity identifier.

15. An electronic device comprising a memory, a processor, and a computer program stored in the memory, characterized in that, The processor executes the computer program to implement the steps of the method according to any one of claims 1-7.

16. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1-7.

17. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1-7.

Citation Information

Patent Citations

  • Counting method and counter

    CN107798036A

  • Big data cardinal number estimation method and system, server and storage medium

    CN110955685A