Real-time billing method and device

Through the combination of message queue and rolling window, cloud service data can be obtained and processed in real time, which solves the problems of low billing accuracy and high delay of traditional billing methods under high concurrency, and achieves more efficient billing processing.

CN118264491BActive Publication Date: 2024-10-01BAIRONG ZHIXIN (BEIJING) TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410351987.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-03-26
Publication Date
2024-10-01
Estimated Expiration
2044-03-26

AI Technical Summary

Technical Problem

The traditional batch-based cloud service billing method leads to log loss and delay under high concurrency conditions, thereby reducing billing accuracy and efficiency and increasing delay.

Method used

The combination of message queue and rolling window is used to obtain service data in real time, and at the end of the billing cycle, the preset billing indicator data is used to calculate the billing volume and generate billing data to avoid losses and delays caused by file collection of logs.

Benefits of technology

Improve billing accuracy and efficiency under high concurrency conditions, reduce delays, and achieve more efficient billing processing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118264491B_ABST
    Figure CN118264491B_ABST
Patent Text Reader

Abstract

The present invention discloses a real-time billing method and device, which relates to the technical field of cloud service billing processing, and its main purpose is to improve billing accuracy and billing efficiency and reduce latency under high concurrency conditions. The technical solution of the present invention is at least: obtaining at least one service data of at least one account from a message queue in real time; for any target account of the at least one account, allocating at least one service data of the target account to at least one rolling window corresponding to the target account; when reaching the billing cycle of each target window, using pre-designed billing indicator data, determining the billing amount of the billing indicator corresponding to the target business; based on the billing amount and pre-designed billing rules, determining the billing data of the target account corresponding to the target business. The present invention is used for cloud service billing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of cloud service billing processing, and in particular to a real-time billing method and device. Background Art

[0002] With the development of cloud computing technology, cloud services have gradually become the norm for inter-enterprise services. Cloud services have the characteristics of large request volumes and complex and diverse products. Therefore, most cloud service providers choose to make the billing module independent and implement billing through log analysis. With the development of business, traditional batch-based billing services can hardly meet business needs. Therefore, billing methods based on stream processing and real-time computing have developed rapidly.

[0003] The relevant scheme provides a typical batch-based billing method, including: obtaining service data corresponding to a target account, that is, obtaining a historical usage log of the target service, parsing the historical usage log, and obtaining service data corresponding to the target account; the service data includes billing indicator data of each billing indicator in at least one billing indicator corresponding to the target service; obtaining the billing rules of the target account for the target service; and generating billing data corresponding to the service data according to the billing rules and the billing indicator data of each billing indicator.

[0004] However, the above billing method collects logs in a file format, which may lead to log loss and delay when the concurrency is high, further leading to problems such as low billing accuracy, high latency, and low billing efficiency. Summary of the invention

[0005] In view of the above problems, the present invention provides a real-time billing method and device, the main purpose of which is to improve billing accuracy and billing efficiency and reduce latency under high concurrency conditions.

[0006] In order to solve the above technical problems, the present invention proposes the following solutions:

[0007] In a first aspect, the present invention provides a real-time charging method, comprising:

[0008] Acquire at least one service data of at least one account from a message queue in real time; wherein the one service data is data generated when the account requests a service once;

[0009] For any target account of the at least one account, at least one service data of the target account is allocated to at least one rolling window corresponding to the target account; wherein, for any target window of the at least one rolling window, the service data allocated to the target window corresponds to the same service of the same target account, and the window size of the target window corresponds to the billing period of the service;

[0010] When the billing cycle of each target window is reached, the billing amount of the billing indicator corresponding to the target service is determined using the pre-designed billing indicator data;

[0011] Based on the billing amount and the pre-designed billing rule, billing data of the target account corresponding to the target service is determined.

[0012] In a second aspect, the invention provides a real-time charging device, comprising:

[0013] An acquisition unit, configured to acquire at least one service data of at least one account from a message queue in real time; wherein the one service data is data generated when the account requests a service once;

[0014] an allocating unit, configured to allocate, for any target account of the at least one account, at least one of the service data of the target account to at least one rolling window corresponding to the target account; wherein, for any target window of the at least one rolling window, the service data allocated to the target window corresponds to the same service of the same target account, and the window size of the target window corresponds to the billing period of the service;

[0015] A first calculation unit, configured to determine a billing amount of a billing indicator corresponding to a target service by using pre-designed billing indicator data when the billing cycle of each target window is reached;

[0016] The second calculation unit is used to determine the billing data of the target account corresponding to the target business based on the billing amount and the pre-designed billing rule.

[0017] In order to achieve the above object, according to a third aspect of the present invention, a storage medium is provided, wherein the storage medium includes a stored program, wherein when the program is running, the device where the storage medium is located is controlled to execute the real-time billing method described in the first aspect.

[0018] In order to achieve the above-mentioned purpose, according to the fourth aspect of the present invention, an electronic device is provided, comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, all or part of the steps of the real-time billing device as described in the second aspect are implemented.

[0019] In order to achieve the above-mentioned object, according to a fifth aspect of the present invention, there is provided a computer program product, comprising a computer program / instruction, which, when executed by a processor, implements the steps of the real-time billing method described in the first aspect.

[0020] By means of the above technical scheme, the real-time billing method and device provided by the present invention is that the current collection of logs in a file manner will lead to the loss and delay of logs in the case of high concurrency, further leading to problems such as low billing accuracy, high delay, and low billing efficiency. To this end, the present invention obtains at least one service data of at least one account from a message queue in real time; wherein the one service data is the data generated by the account requesting a service once; for any target account of the at least one account, at least one service data of the target account is allocated to at least one rolling window corresponding to the target account; wherein, for any target window of the at least one rolling window, the service data allocated to the target window corresponds to the same service of the same target account, and the window size of the target window corresponds to the billing cycle of the service; when the billing cycle of each target window is reached, the pre-designed billing indicator data is used to determine the billing amount of the billing indicator corresponding to the target service; based on the billing amount and the pre-designed billing rules, the billing data of the target account corresponding to the target service is determined. In the case of high concurrency, the billing accuracy and billing efficiency are improved and the delay is reduced.

[0021] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented according to the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present invention. Moreover, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:

[0023] Figure 1 A flow chart of a real-time charging method provided by an embodiment of the present invention is shown;

[0024] Figure 2 Another flow chart of a real-time charging method provided by an embodiment of the present invention is shown;

[0025] Figure 3 A system structure diagram corresponding to a real-time charging method provided by an embodiment of the present invention is shown;

[0026] Figure 4 A block diagram showing a composition of a real-time charging device provided by an embodiment of the present invention is shown;

[0027] Figure 5 A block diagram showing the composition of another real-time charging device provided by an embodiment of the present invention is shown. DETAILED DESCRIPTION

[0028] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.

[0029] Terminology explanation:

[0030] CDC is the abbreviation of Change Data Capture, which is used to monitor and capture database changes (including insertion, update and deletion of data or data tables), record these changes in the order in which they occur, and write them into the message middleware for other services to subscribe and consume.

[0031] At present, the file-based log collection will cause log loss and delay when the concurrency is high, which will further lead to problems such as low billing accuracy, high latency, and low billing efficiency. The inventors came up with the idea of ​​using a message queue with a rolling window to collect service data in real time for real-time billing, in order to overcome the above problems.

[0032] To this end, an embodiment of the present invention provides a real-time billing method, by which the billing accuracy and billing efficiency are improved and the delay is reduced under high concurrency conditions. The specific execution steps are as follows: Figure 1 As shown, the execution subject is an electronic device, which at least includes S100-S400.

[0033] S100. Obtain at least one service data of at least one account from a message queue in real time.

[0034] The one-time service data is data generated when the account requests a service once; for example, account identification, product name, hit status, etc., which is not specifically limited in this embodiment.

[0035] The service data of the message queue is updated synchronously with the service data of the database; the account refers to an authorized customer's account that can use the cloud service.

[0036] In the SaaS cloud service scenario, there are many types of billing, and different corporate customers hope that the service provider can provide a billing method that is beneficial to their own business. For example: Customer A hopes to provide tiered billing, Customer B needs annual billing, Customer C hopes to provide multi-product package billing, etc. In any of these billing methods, how to calculate the billing amount is the key. After obtaining the billing amount, combined with price information, it is very convenient to calculate the billing amount. And the corresponding annual billing, tiered billing, package billing, etc. can all be easily calculated.

[0037] The data of the business system is stored in the database of each business. Due to differences in business forms, there may be different types of databases. For example, system A uses MySQL database, system B uses Oracle database, and system C uses SQLServer database.

[0038] Normally, the business system will provide authorized customers with access to provide services. Specifically, the customer carries his account number as the unique identifier of the customer to access the business system. Carrying keywords and service lists to query the corresponding services in the form of http requests, after the query is successful, the query results are obtained through the http protocol; then the customer's request is recorded in the database of each business system to form service data. Service data can be recorded in the form of a log table.

[0039] Then, the service data added in the corresponding business system, such as the incremental data in the log table, is sent to the message queue Pulsar. When updated service data appears in the message queue, the service data is obtained as the data source for subsequent billing.

[0040] S200. For any target account of the at least one account, allocate at least one service data of the target account to at least one rolling window corresponding to the target account.

[0041] For any target window of the at least one rolling window, the service data allocated to the target window corresponds to the same service of the same target account, and the window size of the target window corresponds to the billing period of the service.

[0042] There is a time sequence in the process of obtaining the service data of the target account from step S100, and the service data is allocated to the corresponding rolling window according to the time sequence of acquisition. Each rolling window only puts the service data of the same business of one target account, so that when calculating the service data in the rolling window, it is calculated for the same business of one target account, which can facilitate subsequent statistics.

[0043] For example: assuming that the target account is customer A, the corresponding rolling window is rolling window A, the same service is service A, and the window size of the target window "rolling window A" corresponds to the billing period of the service "service A" of 30 seconds. This means that rolling window A adds n service data of service A of customer A within 30 seconds, and after 30 seconds, calculations are started based on these n service data.

[0044] S300: When the billing cycle of each target window is reached, the billing amount of the billing indicator corresponding to the target service is determined using pre-designed billing indicator data.

[0045] Among them, the pre-designed billing indicator data refers to the billing configuration data converted from the business system based on the contract information signed with the customer, including at least account identification, billing indicator number, service list, billing category, statistical type, etc., which is not specifically limited in this embodiment.

[0046] After step S200, the service data acquired has been placed in a scrolling window in real time, and then the calculation of the service data that meets the billing conditions is started according to the calculation cycle. The calculation cycle can be set according to business needs, for example, it can be set according to the response speed / real-time required by the business. In one embodiment, for services that require timely response (i.e., services with high real-time performance), the billing cycle can be set to seconds, and for services with low real-time performance, the billing cycle can be set to minutes. The advantage of this setting is that it does not waste computing resources, but also ensures timely response calculations and improves the calculation speed.

[0047] The account identifier is obtained through the service data in the rolling window, and then the corresponding pre-designed fee indicator data is obtained based on the account identifier. Since the billing conditions of the service have been clarified in the pre-designed fee indicator data by setting the service name and statistical type, such as the service name is A, and the statistical type is B "only billing service data in the hit state", the billing condition is that service A needs to be billed when it is in the hit state. Therefore, based on the service name and statistical type, it can be determined which service data in the rolling window need to be billed and which do not, and the number of service data that need to be billed is counted to obtain the billing amount.

[0048] S400: Determine the billing data of the target account corresponding to the target service based on the billing amount and the pre-designed billing rule.

[0049] After obtaining the billing amount from step S300, the billing data of the target account corresponding to the target business, i.e., the billing amount, is calculated according to the pre-designed billing rules. The pre-designed billing rules include billing type and unit price information. The billing type can be tiered billing, monthly billing, etc., which is not specifically limited in this embodiment.

[0050] Based on the above Figure 1It can be seen from the implementation method that the present invention provides a real-time billing method, by obtaining at least one service data of at least one account from a message queue in real time; wherein the one service data is the data generated by the account requesting a service once; for any target account of the at least one account, at least one service data of the target account is allocated to at least one rolling window corresponding to the target account; wherein, for any target window of the at least one rolling window, the service data allocated to the target window corresponds to the same business of the same target account, and the window size of the target window corresponds to the billing cycle of the business; the real-time allocation of service data in this step can avoid the problem of log loss and delay caused by the existing technology of collecting logs in a file manner under high concurrency conditions; when reaching the billing cycle of each target window, the pre-designed billing indicator data is used to determine the billing amount of the billing indicator corresponding to the target business; based on the billing amount and the pre-designed billing rules, the billing data of the target account corresponding to the target business is determined, which can improve the billing efficiency in high-concurrency and massive log scenarios and achieve more efficient billing.

[0051] In order to determine the billing amount, the method step S300 provided in the embodiment of the present application includes S301-S302.

[0052] S301. Based on the target account and target business corresponding to the target window, query the pre-designed billing index data table to obtain the corresponding billing index and statistical type.

[0053] The pre-designed charging indicator data table includes the corresponding relationship between the account, the charging indicator, the service and the statistical type, and the statistical type is charging only for the hit status or charging for any status.

[0054] S302: Based on the statistical type, count the number of service data that need to be billed in the corresponding target window, and determine the billing amount of the billing indicator of the target account corresponding to the target service.

[0055] For example: rolling window A has three service data of service A of customer A, namely service data No. 1 (hit status type is hit), service data No. 2 (hit status type is miss) and service data No. 3 (hit status type is hit status). Assuming that the statistical type of the A billing indicator of service A in the corresponding pre-designed billing indicator data is "only hit status billing", that is, the service data "service data No. 1" and "service data No. 3" of the hit status are calculated, and the service data "service data No. 3" of the miss status is not calculated, then the result calculated by the rolling window is that the billing amount of customer A's A billing indicator is 2.

[0056] In this embodiment, the billing amount of the billing indicator of the target business corresponding to the target account can be calculated by cooperating with the rolling window and the pre-designed billing indicator data table.

[0057] Since customers have different billing requirements, some require deduplication billing, while others do not. In order to meet the diversity of customer needs, a specific billing method is provided to achieve fast billing. Therefore, the method step S400 provided in the embodiment of the present application is as follows: Figure 2 As shown, including S401-S405.

[0058] S401. Store the billing amount in the corresponding pre-designed billing table of the target database.

[0059] The pre-designed billing table includes at least an account identifier, a billing indicator number, a service unique identifier, a billing amount and a billing date, wherein the corresponding relationship formed by the account identifier, the billing indicator number and the service unique identifier is unique.

[0060] The target database has the characteristic that write operations do not block reads. During calculation, data is also served externally in real time without affecting the availability of online services.

[0061] After the billing amount is obtained in step S300, when writing the billing amount into the TiDB database, it is necessary to determine whether the billing amount corresponding to the target account with the account ID, billing indicator number, and service unique ID as the primary key exists in the target database. If so, it is updated in the corresponding pre-designed fee table to increase the billing amount; if not, the account ID, billing indicator number, service unique ID, billing date, and billing amount of the target account are written into the pre-designed fee table.

[0062] Since the data corresponding to the account identifier, the billing indicator number, the service unique identifier and the billing date are not allowed to be repeated, it can be ensured that the record of a billing indicator for a service with an account identifier in the target database will not be repeated, thereby ensuring the accuracy of billing.

[0063] S402: When the billing indicator is deduplication billing, the corresponding deduplication billing amount is obtained based on a pre-designed billing table.

[0064] It should be noted that the pre-designed fee rules at least include deduplication billing and non-deduplication billing.

[0065] When the billing indicator is deduplication billing, based on the pre-designed billing table obtained in step S401, a preset deduplication SQL statement can be used to obtain the corresponding deduplication billing amount.

[0066] For example: Preset deduplication SQL statement: select count(1)from billing table where account = "specified account" and jf_id = "specified jf_id" and jf_date = "specified date".

[0067] S403: Calculate the target account's billing data based on the deduplicated billing amount. After obtaining the billing amount in step S402, the billing unit price can be used to calculate the target account's billing data, ie, the billing amount.

[0068] S404: When the billing indicator is non-deduplicated billing, the corresponding non-deduplicated billing amount is obtained based on the pre-designed billing table.

[0069] When the billing indicator is non-deduplicated billing, based on the pre-designed billing table obtained in step S401, a preset non-deduplicated SQL statement can be used to obtain the corresponding deduplicated billing amount.

[0070] For example: Preset non-deduplication SQL statement: select sum(jf_sum)from billing table where account = "specified account" and jf_id = "specified jf_id" and jf_date = "specified date".

[0071] S405: Calculate the billing data of the target account based on the non-deduplicated billing amount.

[0072] After obtaining the billing amount in step S404, the billing unit price may be used to calculate the billing data of the target account, ie, the billing amount.

[0073] This embodiment ensures smooth reading by storing the billing amount in the target database; and sets up a pre-designed billing table to ensure the uniqueness of the data and reduce the possibility of billing errors; and through preset deduplication SQL statements and preset non-deduplication SQL statements, deduplication data and non-deduplication data can be obtained, realizing deduplication billing and non-deduplication billing to meet the diversity of customer billing needs.

[0074] Furthermore, the method step S301 provided in the embodiment of the present application is refined and expanded, and the step S301 includes S3011-S3013.

[0075] S3011. Obtain the account ID, business name, and hit status of the target account from the service data of the target window.

[0076] The hit status type includes hit and miss, which can be represented by a numerical value, for example, a hit status type "1" represents a hit, and a hit status type "2" represents a miss.

[0077] S3012. Obtain the corresponding pre-design fee indicator data table based on the account identifier.

[0078] The pre-design fee indicator data in the pre-design fee indicator data table at least includes an account identifier, a billing indicator number, a service list and a statistical type.

[0079] After the account identifier is obtained in step S3011, the account identifier is used to retrieve a pre-set pre-design fee indicator data table that also includes the account identifier.

[0080] S3013. Based on the business name corresponding to the target account, traverse the business list corresponding to the pre-designed billing indicator data table to obtain the billing indicator number and statistical type corresponding to the business name.

[0081] The statistical type is whether only the hit status is charged or any status is charged; it can be represented by a numerical value, for example: statistical type "1" means only the hit status is charged; statistical type "2" means any status is charged.

[0082] After obtaining the service name corresponding to the target account from step S3011, traverse the product list corresponding to the pre-designed fee indicator data, which product list includes at least one service name, find the service name of the target account, and then obtain its corresponding billing indicator number and statistical type.

[0083] This embodiment can utilize the information of the service data in the target window and the pre-designed billing index data table to obtain the billing index and statistical type corresponding to the target account, which are used for subsequent calculation of the billing amount of the target account corresponding to the billing index.

[0084] Furthermore, the method step S302 provided in the embodiment of the present application is refined and expanded, and the step S302 includes S3021-S3022.

[0085] S3021. Based on the statistical type, filter out service data that meets the billing conditions in the corresponding target window.

[0086] For example, if the statistical type is "1", which means that only the hit status is charged, the service data with the hit status as hit in the target window is filtered out, and the service data is the service data that meets the billing conditions.

[0087] S3022: Based on the account identifier, the billing indicator number, the service name, and the service data that meets the billing conditions of the target account, obtain the billing amount of the billing indicator corresponding to the service of the target account.

[0088] After obtaining the service data meeting the billing conditions in step 3021, the billing amount of the billing indicator of the service corresponding to the target account is obtained according to the account ID, billing indicator number, service name and service data meeting the billing conditions of the target account.

[0089] For example: the target account's account ID is "111", the billing indicator number is "aaa", the business name is "A service", and the service data that meets the billing conditions are "Service Data No. 1" and "Service Data No. 2". Assuming that the customer corresponding to the account ID "111" is customer A, and the billing indicator corresponding to the billing indicator number "aaa" is indicator A, then the result is that the billing amount of indicator A of customer A's service is 2.

[0090] This embodiment can use the statistical type to filter out the service data that needs to be billed in the target window, calculate the number of times, and determine the number of times as the billing amount for subsequent calculation of the billing data of the target account.

[0091] In order to avoid duplicate calculation errors, it is necessary to ensure that each service data appears only once in the scrolling window. Therefore, the method step S200 provided in the embodiment of the present application includes S201-S202.

[0092] S201. Build a data queue based on the service data of the target account according to preset rules.

[0093] The preset rule may be a rule set according to chronological order.

[0094] In order to centrally store the service data generated by the same account, it is convenient to call the service data for calculation and improve the billing speed. Based on the preset hash partition of the message queue, the account ID of the target account is used as the partition key to call the hash function to generate the corresponding hash value; the service data corresponding to the target account is added to the corresponding preset hash partition using the hash value. This process ensures that the service data of the same target account are allocated to the same partition to achieve the order of the message. In this way, the service data generated by different business systems will be partitioned by the target account and written to the message queue Pulsar in sequence, which is convenient for subsequent retrieval and use, and improves billing efficiency.

[0095] S202: Allocate each service data in the data queue to a corresponding target window in sequence according to the service type.

[0096] The billing period of the target window is set according to the response speed required by the corresponding service data, and the target windows do not overlap.

[0097] For example, the service data of business A of account A is allocated to the corresponding window A in chronological order.

[0098] This embodiment can achieve real-time distribution of service data of the same business of the same account to the same rolling window.

[0099] In addition, with the further development of SaaS cloud services, the timeliness requirements for SaaS service billing have further increased. Most customers hope that when the fees reach a certain threshold, an early warning mechanism will be triggered to remind customers. For some customers with low credit, the business also hopes to take certain blocking measures after their account balance is exhausted, such as closing the call permission to avoid losses to the cloud service company. Therefore, the traditional batch-based billing method has great limitations. Therefore, the method provided in the embodiment of the present application, after step S400, also includes the following steps:

[0100] S500: Calculate the remaining storage amount based on the storage amount and the billing amount of the target account.

[0101] S600: When the remaining stored amount meets the first preset condition, an alarm message is sent to the customer corresponding to the target account.

[0102] For example, if the first preset condition is 500 yuan, then when the remaining amount in the customer's account is less than 500 yuan, the alarm mechanism is triggered, and the customer is notified through the contact information reserved by the customer to replenish the amount. For example, email or text message, etc., are not specifically limited in this embodiment.

[0103] S700: When the remaining stored amount meets the second preset condition, the use authority of the customer corresponding to the target account is closed.

[0104] For example, if the second preset condition is 0 yuan, then when the remaining balance in the customer's account is 0 yuan, the customer's usage rights will be closed to avoid losses.

[0105] This embodiment can set warning conditions and blocking conditions based on the actually calculated billing amount combined with the customer's remaining storage amount, timely remind customers to recharge and control customer permissions to reduce risks.

[0106] In order to better explain the solution provided in the embodiments of the present application, the following examples are given.

[0107] like Figure 3As shown, the present invention includes a business system, a message queue, a real-time computing subsystem and a billing system, wherein the business system includes three types of databases, namely, system A uses a MySQL database, system B uses an Oracle database, and system C uses a SQL Server database; the real-time computing subsystem includes a flink-source component, a Flink computing component, and a flink-sink component; the billing system uses a TiDB database. Among them, the business system will be provided to authorized customers for access to provide services. The message queue is provided with a preset hash partition for storing service data of the same account; the storage principle is to use the account number as the partition key to call the hash function to generate the corresponding hash value, and use the hash value to add the service data corresponding to the account to the corresponding preset hash partition.

[0108] The specific steps are as follows:

[0109] (1) User A sends a request for access to a service to the business system via an HTTP request through a terminal device. The request includes the user's account number as the unique identifier of the user. The request also carries key and products, thereby querying the corresponding service in the business system. After the query is successful, user A obtains the query result through the terminal device.

[0110] In the database of the business system, the user's request is recorded, and the request behavior corresponding to the user's account number is recorded in log table A, as shown in Table 1. The main fields of the log table are as follows:

[0111] Table 1

[0112]

[0113]

[0114] (2) The business system uses the account number account in log table A as the partition key to call the hash function to generate a hash value in real time, and writes the target field information in log table A into the hash partition of the message queue Pulsar according to the hash value to obtain log table A-1. The target field information is shown in Table 2.

[0115] Table 2

[0116]

[0117] (3) The real-time computing subsystem adds the log table A-1 recorded in the hash partition of the message queue Pulsar to the data queue in chronological order, and then allocates the log table A-1 to the corresponding rolling window A according to the business type. The billing period of the rolling window A is n seconds.

[0118] It should be noted that within n seconds, there may be multiple service data of user A stored in the rolling window A, for example: log table A-1, log table A-2...log table An.

[0119] (4) The real-time computing subsystem obtains the account number account of user A, business A, and the hit status status of each log table in the rolling window A from the log tables A-1, A-2, ..., An in the rolling window A.

[0120] (5) The real-time calculation subsystem obtains the pre-design fee indicator data table corresponding to user A based on the account number account, as shown in Table 3.

[0121] Table 3

[0122]

[0123] (6) The real-time calculation subsystem traverses the service list corresponding to the pre-designed fee indicator data table based on service A, and obtains the billing indicator number jf_id and the statistical type status_type corresponding to service A. For example, if the billing indicator number is billing indicator 1, the corresponding statistical type is 1, which means that the fee is calculated only when the status is 1.

[0124] (7) Based on the statistical type status_type, the real-time computing subsystem selects m log tables with status 1 from the log tables A-1, A-2, ..., An corresponding to the rolling window A, where m is the billing amount of billing indicator 1 of service A of user A.

[0125] (8) The real-time computing subsystem adds the billing amount to the output log table (as shown in Table 4), and stores the billing amount in the corresponding pre-designed fee table of the target database based on the output log table. The pre-designed fee table at least includes an account number, a billing indicator number, a service unique identifier, a billing amount and a billing date, wherein the corresponding relationship formed by the account number, the billing indicator number and the service unique identifier is unique; the pre-designed fee rules at least include deduplication billing and non-deduplication billing.

[0126] Write the data in Table 4 to the corresponding pre-designed billing table of the target database; the specific writing process is: in the target database, the billing table storing billing data uses four fields, account, jf_id, key, and jf_date, as the joint primary key, and the data corresponding to the primary key is not allowed to be repeated. First, perform the insert operation. If the insert fails, it means that the account, jf_id, and key data in Table 4 exist in the TiDB database, then update the jf_sum value in the corresponding billing table, that is, add the value of the jf_sum field of the data inserted this time to the jf_sum field of the corresponding data in the database.

[0127] As shown in Table 4, the following fields are included:

[0128] Table 4

[0129]

[0130] (9) Through the above operations, the pre-designed billing table can conveniently count the billing amount after deduplication and the billing amount without deduplication.

[0131] The billing system can use the following SQL to query the deduplication amount of a billing indicator:

[0132] select count(1)from billing table where account = "specified account" and jf_id = "specified jf_id" and jf_date = "specified date";

[0133] The billing system can use the following SQL to query the non-deduplicated billing amount of a billing indicator:

[0134] select sum(jf_sum)from billing table where account = "specified account" and jf_id = "specified jf_id" and jf_date = "specified date";

[0135] (10) After obtaining the billing amount, the billing system can quickly obtain the specific amount of the billing indicator based on the billing unit price information.

[0136] (11) The billing system calculates the difference between the billed amount and the remaining balance in the customer's account, and compares it with the preset alarm amount of X yuan and the amount of Y yuan for closing permissions. When the difference is less than X yuan, it means that the account balance is insufficient and an alarm is issued to the customer; when the difference is less than Y yuan, the account permissions are closed.

[0137] The method provided in the embodiment of the present application mainly solves the problems of low billing accuracy and high latency in traditional batch billing in SaaS cloud service scenarios. It realizes flexible billing methods and supports deduplication. It improves the efficiency of billing in high-concurrency and massive log scenarios and realizes more efficient billing. And based on the timeliness of billing, it realizes accurate cost warning and blocking measures.

[0138] Furthermore, as a response to the above Figure 1 In order to realize the method shown in the figure, the embodiment of the present invention also provides a real-time charging device for Figure 1 The device embodiment corresponds to the aforementioned method embodiment. For ease of reading, this device embodiment will not repeat the details of the aforementioned method embodiment one by one, but it should be clear that the device in this embodiment can correspond to all the contents of the aforementioned method embodiment. Figure 4 As shown, the device comprises:

[0139] The acquisition unit 31 is used to acquire at least one service data of at least one account from the message queue in real time; wherein the one service data is data generated when the account requests a service once;

[0140] an allocating unit 32, configured to allocate, for any target account of the at least one account, at least one of the service data of the target account obtained from the acquiring unit 31 to at least one rolling window corresponding to the target account; wherein, for any target window of the at least one rolling window, the service data allocated to the target window corresponds to the same service of the same target account, and the window size of the target window corresponds to the billing period of the service;

[0141] A first calculation unit 33 is used to determine the billing amount of the billing indicator corresponding to the target service by using the pre-designed billing indicator data when the billing cycle of each target window obtained from the allocation unit 32 is reached;

[0142] The second calculation unit 34 is used to determine the billing data of the target account corresponding to the target service based on the billing amount obtained from the first calculation unit 33 and the pre-designed billing rule.

[0143] Furthermore, as a response to the above Figure 2 In order to realize the method shown in the figure, the embodiment of the present invention also provides another real-time charging device for Figure 2 The device embodiment corresponds to the aforementioned method embodiment. For ease of reading, this device embodiment will not repeat the details of the aforementioned method embodiment one by one, but it should be clear that the device in this embodiment can correspond to all the contents of the aforementioned method embodiment. Figure 5As shown, the device comprises:

[0144] The acquisition unit 31 is used to acquire at least one service data of at least one account from the message queue in real time; wherein the one service data is data generated when the account requests a service once;

[0145] an allocating unit 32, configured to allocate, for any target account of the at least one account, at least one of the service data of the target account obtained from the acquiring unit 31 to at least one rolling window corresponding to the target account; wherein, for any target window of the at least one rolling window, the service data allocated to the target window corresponds to the same service of the same target account, and the window size of the target window corresponds to the billing period of the service;

[0146] A first calculation unit 33 is used to determine the billing amount of the billing indicator corresponding to the target service by using the pre-designed billing indicator data when the billing cycle of each target window obtained from the allocation unit 32 is reached;

[0147] A second calculation unit 34 is used to determine the billing data of the target account corresponding to the target service based on the billing amount obtained from the first calculation unit 33 and the pre-designed billing rule;

[0148] Furthermore, the first calculation unit 33 includes:

[0149] A query module 331 is used to query the pre-designed billing index data table based on the target account and the target business corresponding to the target window, and obtain the corresponding billing index and statistical type;

[0150] The statistical module 332 is used to count the number of service data that need to be billed in the corresponding target window based on the statistical type obtained from the query module 331, and determine the billing amount of the billing indicator of the target account corresponding to the target service.

[0151] Furthermore, the pre-designed charging rules include at least deduplication charging and non-deduplication charging, and the second calculation unit 34 includes:

[0152] The storage module 341 is used to store the billing amount in a corresponding pre-designed fee table of the target database, wherein the pre-designed fee table at least includes an account identifier, a billing index number, a service unique identifier, a billing amount and a billing date, wherein the corresponding relationship formed by the account identifier, the billing index number and the service unique identifier is unique;

[0153] A first acquisition module 342 is used to acquire a corresponding deduplication billing amount based on the pre-designed billing table obtained from the storage module 341 when the billing indicator is deduplication billing;

[0154] The first calculation module 343 is used to calculate the billing data of the target account based on the deduplicated billing amount obtained from the first acquisition module 342.

[0155] A second acquisition module 344 is used to acquire a corresponding non-deduplication billing amount based on the pre-designed billing table obtained from the storage module 341 when the billing indicator is non-deduplication billing;

[0156] The second calculation module 345 is used to calculate the billing data of the target account based on the non-deduplicated billing amount obtained from the second acquisition module 344.

[0157] Furthermore, the query module 331 includes:

[0158] The first acquisition submodule 3311 is used to acquire the account identifier, service name and hit status of the target account from the service data of the target window; wherein the hit status includes hit and miss;

[0159] The second acquisition submodule 3312 is used to acquire the corresponding pre-design fee indicator data table based on the account identifier obtained from the first acquisition submodule 3311; wherein the pre-design fee indicator data at least includes the account identifier, the billing indicator number, the service list, and the statistical type;

[0160] The third acquisition submodule 3313 is used to traverse the business list corresponding to the pre-designed fee indicator data table obtained from the second acquisition submodule 3312 based on the business name corresponding to the target account, and obtain the billing indicator number and statistical type corresponding to the business name.

[0161] Furthermore, the statistical module 332 includes:

[0162] A screening submodule 3321, configured to screen out service data meeting the billing conditions in the corresponding target window based on the statistical type;

[0163] The calculation submodule 3322 is used to obtain the billing amount of the billing indicator of the target account corresponding to the service based on the account identifier of the target account, the billing indicator number, the service name and the service data that meets the billing conditions obtained from the screening submodule 3321.

[0164] Furthermore, the allocation unit 32 includes:

[0165] A construction module 321 is used to construct a data queue according to a preset rule based on the service data of the target account;

[0166] The allocation module 322 is used to allocate each service data in the data queue obtained from the construction module 321 to the corresponding target window in turn according to the business type; wherein the billing period of the target window is set according to the response speed required by the corresponding service data, and the target windows do not overlap.

[0167] Furthermore, an embodiment of the present invention further provides a processor, the processor is used to run a program, wherein the program executes the above Figure 1-2 Real-time billing method described in .

[0168] Furthermore, an embodiment of the present invention further provides a storage medium, wherein the storage medium is used to store a computer program, wherein when the computer program is running, the device where the storage medium is located is controlled to execute the above Figure 1-2 Real-time billing method described in .

[0169] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0170] It is understandable that the related features in the above methods and devices can be referenced to each other. In addition, the "first", "second" and the like in the above embodiments are used to distinguish the embodiments, but do not represent the advantages and disadvantages of the embodiments.

[0171] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0172] The algorithm and display provided herein are not inherently related to any particular computer, virtual system or other device. Various general purpose systems can also be used together with the teachings based on this. According to the above description, it is obvious that the structure required for constructing such systems. In addition, the present invention is not directed to any specific programming language either. It should be understood that various programming languages ​​can be utilized to realize the content of the present invention described herein, and the description of the above specific languages ​​is for disclosing the best mode of the present invention.

[0173] In addition, the memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.

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

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

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

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

[0178] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0179] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0180] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.

[0181] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

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

[0183] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.

Claims

1. A real-time billing method, characterized in that: The method comprises: Acquire at least one service data of at least one account from a message queue in real time; wherein the one service data is data generated when the account requests a service once; For any target account of the at least one account, at least one service data of the target account is allocated to at least one rolling window corresponding to the target account; wherein, for any target window of the at least one rolling window, the service data allocated to the target window corresponds to the same service of the same target account, and the window size of the target window corresponds to the billing period of the service; When the billing cycle of each target window is reached, the billing amount of the billing indicator corresponding to the target service is determined using the pre-designed billing indicator data; Based on the billing amount and the pre-designed billing rule, billing data of the target account corresponding to the target service is determined.

2. The method according to claim 1, characterized in that When the billing cycle of each target window is reached, determining the billing amount of the billing indicator corresponding to the target service by using the pre-designed billing indicator data includes: Based on the target account and the target business corresponding to the target window, query the pre-designed billing index data table to obtain the corresponding billing index and statistical type; Based on the statistical type, the number of service data that needs to be billed in the target window is counted to determine the billing amount of the billing indicator of the target account corresponding to the target service.

3. The method according to claim 2, characterized in that The pre-designed fee rules at least include deduplication billing and non-deduplication billing; The determining, based on the billing amount and the pre-designed billing rule, billing data of the target account corresponding to the target service includes: The billing amount is stored in a corresponding pre-designed fee table of the target database, wherein the pre-designed fee table includes at least an account identifier, a billing index number, a service unique identifier, a billing amount, and a billing date, wherein the corresponding relationship formed by the account identifier, the billing index number, and the service unique identifier is unique; When the billing indicator is deduplication billing, the corresponding deduplication billing amount is obtained based on the pre-designed billing table; Based on the deduplicated billing amount, the billing data of the target account is calculated.

4. The method according to claim 3, characterized in that After storing the billing amount in a corresponding pre-designed billing table of the target database, the method further includes: When the billing indicator is non-deduplicated billing, the corresponding non-deduplicated billing amount is obtained based on the pre-designed billing table; Based on the non-deduplicated billing amount, the billing data of the target account is calculated.

5. The method according to any one of claims 2 to 4, characterized in that: The querying of the pre-designed charging index data table based on the target account and the target business corresponding to the target window to obtain the corresponding charging index and statistical type includes: Acquire the account identifier, service name and hit status of the target account from the service data of the target window; wherein the hit status includes hit and miss; Obtaining a corresponding pre-design fee indicator data table based on the account identifier; wherein the pre-design fee indicator data at least includes an account identifier, a billing indicator number, a service list, and a statistical type; Based on the service name corresponding to the target account, the service list corresponding to the pre-designed billing indicator data table is traversed to obtain the billing indicator number and statistical type corresponding to the service name.

6. The method according to claim 5, characterized in that The counting, based on the statistical type, of the number of service data that needs to be billed in the corresponding target window, and determining the billing amount of the billing indicator of the target account corresponding to the service includes: Based on the statistical type, filtering out service data that meets the billing conditions in the corresponding target window; Based on the account identifier of the target account, the billing indicator number, the service name and the service data that meets the billing conditions, the billing amount of the billing indicator of the service corresponding to the target account is obtained.

7. The method according to claim 6, characterized in that The allocating, for any target account of the at least one account, at least one service data of the target account to at least one rolling window corresponding to the target account, comprises: Based on the service data of the target account, a data queue is constructed according to preset rules; Each service data in the data queue is sequentially allocated to the corresponding target window according to the business type; wherein the billing period of the target window is set according to the response speed required by the corresponding service data, and the target windows do not overlap.

8. A real-time billing device, characterized in that: include: An acquisition unit, configured to acquire at least one service data of at least one account from a message queue in real time; wherein the one service data is data generated when the account requests a service once; an allocating unit, configured to allocate, for any target account of the at least one account, at least one of the service data of the target account to at least one rolling window corresponding to the target account; wherein, for any target window of the at least one rolling window, the service data allocated to the target window corresponds to the same service of the same target account, and the window size of the target window corresponds to the billing cycle of the service; a first calculating unit, configured to determine the billing amount of the billing indicator corresponding to the target service by using the pre-designed billing indicator data when the billing cycle of each target window is reached; The second calculation unit is used to determine the billing data of the target account corresponding to the target business based on the billing amount and the pre-designed billing rule.

9. A storage medium comprising a stored program, characterized in that: When the program is running, the device where the storage medium is located is controlled to execute the real-time billing method according to any one of claims 1 to 7.

10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the real-time charging method according to any one of claims 1 to 7 is implemented.

11. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the method described in any one of claims 1 to 7 are implemented.