Charging method and device, electronic equipment and storage medium
By managing the billing model's cache in the billing server and setting expiration times and thread locking mechanisms, the problem of excessive memory consumption in the billing platform was solved, improving billing efficiency and stability.
Patent Information
- Application Number
- CN202210479909.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-05
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2042-05-05
AI Technical Summary
In high-concurrency scenarios, the existing billing platform consumes too much memory, affecting billing efficiency and stability. Furthermore, the cached data is insufficient to support billing needs at any time, requiring frequent updates.
By executing the billing method in the billing server, using a thread locking mechanism to manage the cache, setting the expiration time of the billing model, and updating and deleting cached data under certain conditions, frequent database access is avoided.
It implements an efficient cache billing model, reduces memory usage, improves billing efficiency and stability, and ensures that billing needs in most scenarios do not require frequent cache updates.
Smart Images

Figure CN117057791B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to billing methods, apparatus, electronic devices and storage media. Background Technology
[0002] In scenarios where transactions are completed through intermediary platforms such as clearing and settlement platforms, institutions connecting to these platforms typically need to pay a certain transaction fee. Specifically, the fee can be calculated per transaction by the billing platform within the intermediary platform. The billing rules may not be static; for example, the fee rate may fluctuate, and the rate used on one day may differ from the rate used on the next.
[0003] In high-concurrency scenarios, the configuration information required for billing, such as billing rules, can be formatted into data and cached in memory, leveraging the high speed of memory access to improve billing efficiency. However, since transaction processing takes time and there are needs for retrospective billing, the cached data is insufficient to support billing needs at any time, requiring frequent cache updates, which affects billing efficiency and stability. Summary of the Invention
[0004] This application provides a billing method, apparatus, electronic device, and storage medium to at least partially solve the problem of excessive memory consumption of the billing platform by existing billing methods.
[0005] The embodiments of this application adopt the following technical solutions:
[0006] In a first aspect, embodiments of this application provide a billing method executed by a billing server, comprising: determining a first time period starting from the current time when a first update condition is met; determining a billing rule matching the first time period from a database; generating a first billing model according to the determined billing rule; and using the first time period as the billing time period of the first billing model; writing the first billing model into a computing model cache and configuring an expiration time for the first billing model in the computing model cache, so that the first billing model is deleted from the computing model cache when the expiration time is met; determining a computing model matching the billing time period and the time attribute from the computing model cache according to the time attribute of the billing request, and processing the billing request using the determined billing model.
[0007] In some embodiments, the method further includes: if the time attribute of the billing request does not match the billing time period of each billing model in the computing model cache, then determining a second time period based on the time attribute, determining a billing rule matching the second time period from the database, generating a second billing model based on the determined billing rule, and using the second time period as the billing time period of the second billing model; writing the second billing model into the computing model cache, and configuring an expiration time for the second billing model in the computing model cache.
[0008] In some embodiments, the write and delete operations are performed using threads; the method further includes locking the computation model cache to prevent other threads from performing write and / or delete operations on the computation model cache while a thread is performing write and / or delete operations on the computation model cache.
[0009] In some embodiments, the first update condition includes: the current time reaches the update time; the method further includes: periodically updating the update time using a preset update period; the computing model cache is configured with a storage limit parameter, and the expiration time is less than the product of the storage limit parameter and the preset update period.
[0010] In some embodiments, the method further includes: obtaining a target time period when a second update condition is met; and deleting billing models in the calculation model cache whose billing time periods are outside the target time period.
[0011] In some embodiments, the method further includes: if the step of determining the billing rule matching the first time period from the database fails, calculating the retry time of the step according to the exponential backoff algorithm, and re-executing the step when the retry time is reached.
[0012] In some embodiments, the method further includes: if the number of execution failures reaches a preset threshold, then copying the billing model in the calculation model cache whose billing time period is closest to the first time period, and modifying the billing time period of the copied billing model to the first time period to obtain the first billing model.
[0013] Secondly, embodiments of this application also provide a billing device applied to a billing server for implementing any of the methods described above.
[0014] In some embodiments, the apparatus includes: a determining unit, configured to determine a first time period starting from the current time when a first update condition is met; a model generating unit, configured to determine a billing rule matching the first time period from a database, generate a first billing model according to the determined billing rule, and use the first time period as the billing time period of the first billing model; a cache updating unit, configured to write the first billing model into a computing model cache, configure an expiration time for the first billing model in the computing model cache, and delete the first billing model from the computing model cache when the expiration time is met; and a billing unit, configured to determine a computing model matching the billing time period and the time attribute from the computing model cache according to the time attribute of the billing request, and process the billing request using the determined billing model.
[0015] In some embodiments, the determining unit is further configured to determine a second time period based on the time attribute if the time attribute of the billing request does not match the billing time period of each billing model in the computing model cache; the model generating unit is further configured to determine the billing rule matching the second time period from the database, generate a second billing model based on the determined billing rule, and use the second time period as the billing time period of the second billing model; the cache updating unit is further configured to write the second billing model into the computing model cache and configure the expiration time of the second billing model in the computing model cache.
[0016] In some embodiments, the cache update unit is configured to utilize threads to perform write and delete operations; while a thread is performing write and / or delete operations on the computation model cache, the computation model cache is locked to prevent other threads from performing write and / or delete operations on the computation model cache.
[0017] In some embodiments, the first update condition includes: the current time has reached the update time; a cache update unit is used to periodically update the update time using a preset update period; the computing model cache is configured with a storage limit parameter, and the expiration time is less than the product of the storage limit parameter and the preset update period.
[0018] In some embodiments, the cache update unit is configured to obtain the target time period when the second update condition is met; and delete the billing models in the calculation model cache whose billing time period is outside the target time period.
[0019] In some embodiments, the determining unit is further configured to, if the step of determining a billing rule matching the first time period from the database fails, calculate the retry time of the step according to the exponential backoff algorithm, and re-execute the step when the retry time is reached.
[0020] In some embodiments, the cache update unit is further configured to, if the number of execution failures reaches a preset threshold, copy the billing model in the calculation model cache area whose billing time period is closest to the first time period, and modify the billing time period of the copied billing model to the first time period to obtain the first billing model.
[0021] Thirdly, embodiments of this application also provide an electronic device, the electronic device including: a processor; and a memory arranged to store computer-executable instructions, which, when executed, cause the processor to perform any of the methods described above.
[0022] Fourthly, embodiments of this application also provide a computer-readable storage medium that stores one or more programs, which, when executed by an electronic device including multiple applications, cause the electronic device to perform any of the methods described above.
[0023] The above-mentioned at least one technical solution adopted in the embodiments of this application can achieve the following beneficial effects: multiple billing models can be cached, and the billing time period of each billing model can be used to process the billing request with the corresponding time attribute. When performing billing, the billing model in the cache can be used directly without frequent access to the database, thus ensuring billing efficiency. In addition, by setting an expiration time, more billing models can be cached, which can also guarantee the billing needs in most scenarios without frequent cache updates and without worrying about excessive memory consumption by the billing models. Attached Figure Description
[0024] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0025] Figure 1 This is a schematic diagram illustrating a scenario where billing is performed using a billing platform, as provided in the embodiments of this specification.
[0026] Figure 2 This specification provides a schematic diagram illustrating a billing process performed using a billing platform, as shown in the embodiments of this specification.
[0027] Figure 3 A schematic diagram of a billing process provided for an embodiment of this specification;
[0028] Figure 4 This is a schematic diagram illustrating the billing process of a billing platform provided in the embodiments of this specification;
[0029] Figure 5 This is a schematic diagram illustrating the process of determining the billing module corresponding to a first time period using an embodiment of this specification;
[0030] Figure 6 This is a schematic diagram of a billing device structure provided in an embodiment of this specification;
[0031] Figure 7 This is a schematic diagram of the structure of an electronic device according to an embodiment of this application. Detailed Implementation
[0032] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0033] The technical solutions provided by the various embodiments of this application are described in detail below with reference to the accompanying drawings.
[0034] The billing methods provided in this manual can be executed by a billing server, which can be a component of a billing platform. The billing platform is used to determine transaction fees and can also provide other services such as transfer and clearing.
[0035] like Figure 1 As shown, Institution A sends its generated transaction 1 to the billing platform, which then outputs the corresponding transaction fee 1. Similarly, the billing platform can also be used to determine the transaction fees for transactions generated by Institution B and Institution C. In real-time billing scenarios, each transaction can correspond to one billing request. In retrospective billing scenarios, multiple transactions within the same billing period can correspond to one billing request.
[0036] The billing platform may include a billing device, a database, and a cache (memory). Specifically, the billing device executes the billing methods provided in this specification. The database, also known as a billing database, is used to store the data required for billing execution. For example, in... Figure 2 The billing platform shown contains several pre-defined billing features and several billing methods stored in the database.
[0037] In an optional embodiment of this specification, both the billing preset features and the billing method are preset data. The billing preset features are used to distinguish transactions from different dimensions. Specifically, the billing preset features may indicate at least one of the following: the institution corresponding to the transaction, the type of transaction (e.g., payment transaction, transfer transaction, etc.), and the amount of resources corresponding to the transaction (e.g., the amount of money involved in the transaction, etc.).
[0038] Billing methods can be used to determine how a transaction should be billed based on its characteristics. For example, Institution A may have historically agreed with a billing platform that if a transaction contains pre-defined billing characteristic 1 (transaction type is a payment transaction) and a transaction contains pre-defined billing characteristic 2 (the amount of resources corresponding to the transaction is within a certain range), then billing method 1 (a transaction fee of 1% of the resources corresponding to the transaction) will be used. Figure 2 As shown.
[0039] In addition, there are situations where Institution A has reached other agreements with the billing platform (e.g., the transaction includes pre-set billing feature 2 and pre-set billing feature m); there are also other institutions besides Institution A (e.g., Institution B, such as...). Figure 1 (As shown) In cases where an agreement is reached with the billing platform, the applicable billing method may not be unique within a certain time period.
[0040] In this specification, the cache is used to store the billing model used when performing billing. The billing model in this specification is the smallest unit stored in the cache for performing billing. The billing model corresponds to a time range, such as... Figure 2 As shown, each of billing models 1 to n corresponds to a time range. In this specification, this time range is referred to as the billing period. Each billing model can process billing requests whose time attributes match their billing period. For example, billing model 1 corresponds to time range 1, meaning that billing model 1 is used to bill transactions executed within time range 1.
[0041] Furthermore, a billing model can include several billing rules (e.g., such as...). Figure 2 As shown, billing model n contains billing rules 1 to q, and each billing rule corresponds to a billing method (e.g., ...). Figure 2 As shown, billing rule 1 corresponds to billing method 1.
[0042] The computing model cache can be a region within the billing platform's memory. Other regions within the billing platform's memory, besides the computing model cache, can cache data while other services are being executed. In an optional embodiment, the capacity of the computing model cache can be adaptively adjusted based on the data volume of the billing models during online use, but a capacity limit is typically set, usually determined by the total number of computing models.
[0043] For example, in Figure 2 In the scenario shown, the billing device generates a billing model n and stores it in the computational model cache. For example, in... Figure 2In the scenario shown, the billing device deletes billing model 1 from the calculation model cache, thus removing the storage space occupied by billing model 1 from the calculation model cache. This frees up memory space and avoids wasting it.
[0044] Furthermore, in this specification, the number of billing models stored in the calculation model cache is multiple. Different billing models process transactions belonging to different time periods. For example, in... Figure 2 In the example shown, the calculation model cache stores n-1 billing models before the current time. Among them, billing model 1 corresponds to time range 1 (that is, billing model 1 is used to determine the transaction fees corresponding to transactions executed within time range 1), billing model 2 corresponds to time range 2, and so on.
[0045] Based on the aforementioned billing platform architecture and related concepts, this specification explains the billing process performed by the billing device. For example... Figure 3 As shown, the process includes one or more of the following steps.
[0046] S310: If the first update condition is met, determine the first time period starting from the current time.
[0047] The first update condition in this specification is used to determine whether a billing model should be added to the computing model cache at the current moment. If the preset first update condition is met, it is determined that a billing model can be added to the computing model cache.
[0048] In an optional embodiment of this specification, the first update condition indicates the time at which a billing model is added to the computing model cache (e.g., the time indicated by the first update condition could be 8:00 AM daily, which can be referred to as the update time). The judgment process for the first update condition can be as follows: determine whether the current time matches at least one time indicated by the first update condition (e.g., determine whether the current time is 8:00 AM). If yes, determine a first time period starting from the current time and perform the judgment again. If no, perform the judgment again until the result of the judgment is yes.
[0049] In some embodiments, the first update condition includes: the current time has reached the update time; the method further includes: periodically updating the update time using a preset update period; the computing model cache is configured with a storage limit parameter, and the expiration time is less than the product of the storage limit parameter and the preset update period. For example, if the storage limit parameter is 16 and the update period is 1 day, then the expiration time will not exceed 16 days.
[0050] The first time period in this specification is a future time range, such as... Figure 2As shown, the first time period is located after the current moment on the timeline. This specification does not limit the length of the first time period; it can be determined based on actual business needs. In an optional embodiment of this specification, the length of the first time period is determined by a first update condition. Specifically, when the preset first update condition is met, the time interval between the current moment and the next moment shown in the first update condition that meets the preset first update condition is the length of the first time period determined in this instance.
[0051] In one optional embodiment of this specification, the duration of the first time period is one day.
[0052] S320: Determine the billing rules that match the first time period from the database, generate the first billing model based on the determined billing rules, and use the first time period as the billing period of the first billing model.
[0053] As can be seen from the foregoing, the organization using the billing platform described in this manual may not be the only one. Even within the same organization, the billing method using the billing platform described in this manual may not be unique. Therefore, the billing rules determined in this step can be multiple, such as... Figure 2 As shown.
[0054] In an optional embodiment of this specification, the process of determining the billing rules matching the first time period may include: identifying each pre-stored billing preset feature in the database that matches the first time period; then, for each identified billing preset feature, determining the billing method stored in the database corresponding to that billing preset feature; and finally, based on each billing preset feature, each billing method, and the correspondence between the billing preset features and the billing methods, obtaining the billing rules matching the time range of the first time period.
[0055] like Figure 2 In the example shown, the billing device identifies the following pre-defined billing features in the database that match the first time period: pre-defined billing feature 1 (e.g., pre-defined billing feature 1 indicates the identifier of institution A), pre-defined billing feature 2 (e.g., pre-defined billing feature 2 indicates the transaction type is a payment transaction), and pre-defined billing feature m (e.g., pre-defined billing feature m indicates the identifier of institution B). This indicates that historically, the billing platform has reached an agreement with institutions A and B regarding the fees charged for payment transactions.
[0056] If the pre-defined billing features 3 to m stored in the database do not match the first time period, they will not be considered within the first time period. Therefore, the billing rules determined based on the first time period are relatively concise and do not involve information unrelated to the first time period. Consequently, the billing model determined based on the billing rules in subsequent steps is also relatively concise and will not consume excessive memory.
[0057] In the agreement, the billing platform and institution A determine billing method 1 for payment transactions, and the billing platform and institution B determine billing method p for payment transactions. Figure 2 As shown. In Figure 2 In addition, the billing device also determines billing rule 2 and other billing rules based on the data in the database, which will not be elaborated here.
[0058] In such Figure 2 In the example shown, after obtaining billing rules 1 to q, the billing device can generate a billing model n based on billing rules 1 to q (for example, encapsulate billing rules 1 to q to obtain billing model n), which is then used as a new billing model.
[0059] The billing model for this salary is used to determine the transaction fees for transactions executed within a time range n (i.e., the first time period).
[0060] As can be seen, the billing model in this specification can show the first time period, the billing rules, and the correspondence between the first time period and the billing rules.
[0061] S330: Write the first billing model to the computing model cache and configure an expiration time for the first billing model in the computing model cache so that the first billing model can be deleted from the computing model cache if the expiration time is met.
[0062] After obtaining the new billing model (i.e., billing model n), the new billing model can be stored in the computing model cache area to update the computing model cache area.
[0063] Therefore, this specification determines the moment when a new billing model is added as the current moment. Since the new billing model corresponds to the first time period (a future time period), as time progresses, when the current moment enters the time range defined by the first time period, the new billing model can be directly applied to execute billing for transactions received that match the first time period. This eliminates the need to determine the matching billing model after the current moment enters the time range defined by the first time period, thus avoiding the situation where the billing platform receives transactions corresponding to the first time period before a matching billing model has been determined, and consequently avoiding delays in billing execution.
[0064] Based on this, if the time range of the billing models stored in the calculation model cache is close to the current time, then the models in the calculation model cache are more likely to be adopted when executing billing, thus avoiding billing methods with a lower probability of adoption and thus avoiding the occupation of memory space.
[0065] Furthermore, the process of updating the computational model cache is performed under the control of the billing device according to the first update condition. This avoids the use of memory space by billing methods generated at the current time based on data in the database, whose corresponding time range is far from the current time. Compared to the First In First Out (FIFO) update method, the billing process in this specification can avoid the situation where, under limited memory space, billing methods generated at the current time with corresponding time ranges far from the current time (which have a lower probability of being used and are used less frequently) are "squeezed out" of the computational model cache by billing methods generated in the past with corresponding time ranges closer to the current time (which have a higher probability of being used and are used more frequently).
[0066] Furthermore, by setting expiration times, memory waste caused by long-term caching of billing models is avoided. For example, in retrospective billing scenarios, it may be necessary to write all billing models whose billing period matches that of the past month into the computational model cache for retrospective billing of historical transactions; however, after the retrospective billing ends, these billing models no longer need to be retained in the computational model cache. Flexible configuration of expiration times can save memory.
[0067] S340: Based on the time attribute of the billing request, determine the calculation model that matches the billing time period and time attribute from the calculation model cache, and process the billing request using the determined billing model.
[0068] In this specification, a billing model that matches the transaction in terms of time frame is defined as a billing model whose corresponding time frame includes the moment the transaction is executed. For example... Figure 2 In the example shown, institution A sends transaction 1 to the billing platform (specifically, institution A sends transaction 1 to the billing device). If the time when transaction 1 is executed falls within the time range corresponding to billing model 2, then billing model 2 matches transaction 1.
[0069] In an optional embodiment of this specification, the billing device may first determine the timestamp of the received transaction. Then, based on the timestamp of the received transaction, it searches the time ranges of each billing model in the calculation model cache to obtain the time range matching the timestamp. Next, the billing model to which the time range matching the timestamp belongs is determined as the billing model that matches the transaction in terms of time range. The transaction fee is determined using the billing model that matches the transaction in terms of time range.
[0070] In such Figure 2 In the example shown, billing model 2 matches transaction 1, so the billing device can obtain the transaction fee 1 of transaction 1 based on billing model 2.
[0071] Optionally, after the billing device receives the transaction fee 1, it sends the transaction fee 1 to institution A, such as... Figure 2 As shown, this is to enable institution A to pay a handling fee of 1.
[0072] Since the billing model in this specification illustrates the billing rules, the billing device can obtain the transaction fee 1 for transaction 1 based on the billing rules shown in billing model 2. Therefore, when performing billing using the billing process described in this specification, the billing model in the calculation model cache can be used directly, without frequent database access.
[0073] In some embodiments, the method further includes: if the time attribute of the billing request does not match the billing time period of each billing model in the computing model cache, then determining a second time period based on the time attribute, determining a billing rule matching the second time period from the database, generating a second billing model based on the determined billing rule, and using the second time period as the billing time period of the second billing model; writing the second billing model into the computing model cache, and configuring an expiration time for the second billing model in the computing model cache.
[0074] For example, in addition to periodically updating the cache, the cache can be updated in real time when the cache's computational model is insufficient to support billing requirements.
[0075] For example, in Figure 2 In the scenario shown, if the billing device cannot determine a billing model matching transaction 1 in the cache, it identifies transaction 1 as the target transaction. Then, it determines the individual billing characteristics of the target transaction. Based on the pre-defined billing characteristics and billing methods in the database that match the individual billing characteristics of the target transaction, it determines the billing rules matching the target transaction. Next, based on the billing rules matching the target transaction, it determines the billing model matching the target transaction, which is then added as a new billing model. The transaction fee for the target transaction can then be determined based on this new billing model.
[0076] In some embodiments, the method further includes: obtaining a target time period if a second update condition is met; and deleting billing models in the cache whose billing time periods are outside the target time period.
[0077] This avoids the need to remove the billing model required for real-time billing, thus ensuring the stability of real-time transactions.
[0078] The process of deleting the billing model can be as follows: when the preset second update condition is met, determine a second time period with the current time as the endpoint and whose time range is in the historical period (for example, the second time period is as follows). Figure 2(As shown). Then, among the various billing models in the cache, the billing model generated during the time period outside the first and second time periods is determined (as shown). Figure 2 The billing model shown is 1), which is the billing model to be deleted. Delete the billing model to be deleted to free up cache space.
[0079] The second update condition in this specification is used to determine whether a portion of the billing model in the cache should be deleted at the current moment.
[0080] In an optional embodiment of this specification, the second update condition indicates the time at which the billing model is added to the cache (e.g., the time indicated by the second update condition could be 6:00 AM on the 1st of each month). The determination process for the second update condition could then be: determining whether the current time matches at least one time indicated by the second update condition (e.g., determining whether the current time is 6:00 AM on the 1st of the month). If yes, then determining a second time period ending at the current time, and performing the determination again. If no, then performing the determination again until the result of the determination is yes.
[0081] The second time period in this instruction manual refers to a historical time range, such as... Figure 2 As shown, the second time period is located before the current moment on the timeline. This specification does not limit the length of the second time period; it can be determined based on actual business needs. In an optional embodiment of this specification, the length of the second time period is determined by a second update condition. Specifically, when a preset second update condition is met, the duration between the current moment and the previous moment that met the preset second update condition, as shown in the second update condition, is the length of the second time period determined in this instance.
[0082] Because the execution time of the target transaction is far from the current time, the time range of the billing model corresponding to the target transaction is outside the second time period. Therefore, when deleting billing models in the cache, the billing model corresponding to the target transaction is more likely to be deleted. Since the probability of the billing model corresponding to the target transaction being used is low, the process in this specification can clean up infrequently used billing models in the cache based on the usage probability of the billing model represented by the second time period, further avoiding cache occupation.
[0083] In one optional embodiment of this specification, the duration of the second time period is 16 days.
[0084] In some embodiments, the write and delete operations are performed using threads; the method further includes locking the computation model cache to prevent other threads from performing write and / or delete operations on the computation model cache while a thread is performing write and / or delete operations on the computation model cache.
[0085] In high-concurrency scenarios, billing requests can be processed in parallel using concurrent threads, and the stability of high concurrency can be ensured by locking the computing model cache.
[0086] As the foregoing has shown, the billing rules corresponding to a billing model may not be unique. For example... Figure 2 As shown, the billing rules corresponding to billing model n are billing rules 1 to billing rules q. Similarly, billing model 2 can also correspond to multiple billing rules. In this case, the billing device needs to select the billing rule used to determine the transaction fee of transaction 1 from the billing rules corresponding to billing model 2.
[0087] Specifically, the process can be as follows: For a transaction sent by an institution, determine the individual billing characteristics of the transaction. Then, based on the determined individual billing characteristics, search among the various preset billing characteristics included in the billing rules corresponding to the transaction to obtain the preset billing characteristics that match the individual billing characteristics. Finally, use the billing method corresponding to the preset billing characteristics that match the individual billing characteristics to determine the transaction fee.
[0088] In this specification, the billing individual characteristics may correspond to the aforementioned pre-defined billing characteristics. In an optional embodiment, the billing individual characteristics may include: the institution corresponding to the transaction (in... Figure 2 In the example shown, the institution corresponding to transaction 1 is institution A), the type of the transaction, and the amount of resources corresponding to the transaction, at least one of these.
[0089] When Transaction 1 has multiple billing characteristics, only billing rules that match any one of the billing characteristics of Transaction 1 can be used to determine the transaction fee. For example, such as... Figure 4 As shown, after receiving transaction 1 from institution A, the billing device determines billing individual characteristics 1 to 1r of transaction 1. It also determines that the time range corresponding to billing model 2 in the cache matches the execution time of transaction 1, and uses billing model 2 as the model corresponding to transaction 1. Then, the billing device determines the pre-defined billing characteristics (i.e., the pre-defined billing features) corresponding to each billing individual characteristic of transaction 1 and the billing rule 2' of billing model 2. Figure 4 If the billing preset features 1' to 1' shown match, then the billing method 1' corresponding to billing rule 2' is used to determine the transaction fee of transaction 1.
[0090] In some embodiments, the method further includes: if the step of determining a billing rule matching the first time period from the database fails, calculating the retry time for that step according to an exponential backoff algorithm, and re-executing the step when the retry time is reached. In some embodiments, the maximum number of retries is set to 3. This reduces the impact of database service timeouts and downtime.
[0091] In some embodiments, the method further includes: if the number of execution failures reaches a preset threshold, then copying the billing model in the cache whose billing time period is closest to the first time period, and modifying the billing time period of the copied billing model to the first time period to obtain the first billing model.
[0092] In real-world online billing scenarios, situations may arise where the database lacks sufficient data to generate a billing model (the number of consecutive failures of a billing rule is determined based on the database data, reaching a preset threshold, which can be set according to actual business needs). For example, institution A and the billing platform may not have reached an agreement on a specific time period. In such cases, to ensure normal transaction billing, the billing model with the closest time frame to the current time can be generated from the cached billing models and used as the billing model for that first time period. To ensure that this billing model can also be used to bill transactions within the original time period, it can be implemented by copying the billing model and changing the billing time period; alternatively, the billing time period of the billing model can be modified.
[0093] For example, such as Figure 5 As shown, the billing device determines, based on the data in the database, that the number of consecutive failures of the billing rule reaches a preset threshold, and then determines the billing model n-1 as the billing model corresponding to the first time period (time range n) and the original billing time period (time range n-1).
[0094] As can be seen, using the billing process described in this specification, the time range corresponding to each billing model stored in the cache is relatively close to the current time. This means that such a billing model is more likely to be used during billing. Therefore, billing for transactions can be achieved through operations such as reading from the cache, without frequent database reads. Furthermore, when transactions such as the target transaction occur, whose execution time is far from the current time and have a low probability of occurrence, data can be read from the database for the target transaction to ensure that billing for that transaction can be performed. This means that the billing process described in this specification not only effectively avoids cache breakdown and memory thrashing, but also ensures that all transactions received by the billing platform can be effectively billed.
[0095] Furthermore, based on the same idea, embodiments of this specification also provide corresponding... Figure 3 The billing apparatus shown in the diagram is applied to a billing server in a billing platform, which, as previously described, may also include a database and memory.
[0096] In some embodiments, the apparatus includes: a determining unit 610, configured to determine a first time period starting from the current time when a first update condition is met; a model generating unit 620, configured to determine a billing rule matching the first time period from a database, generate a first billing model according to the determined billing rule, and use the first time period as the billing time period of the first billing model; a cache updating unit 630, configured to write the first billing model into a computing model cache area, configure an expiration time for the first billing model in the computing model cache area, and delete the first billing model from the computing model cache area when the expiration time is met; and a billing unit 640, configured to determine a computing model matching the billing time period and the time attribute from the computing model cache area according to the time attribute of the billing request, and process the billing request using the determined billing model.
[0097] In some embodiments, the determining unit 610 is further configured to determine a second time period based on the time attribute if the time attribute of the billing request does not match the billing time period of each billing model in the computing model cache; the model generating unit 620 is further configured to determine the billing rule matching the second time period from the database, generate a second billing model based on the determined billing rule, and use the second time period as the billing time period of the second billing model; the cache updating unit 630 is further configured to write the second billing model into the computing model cache and configure the expiration time of the second billing model in the computing model cache.
[0098] In some embodiments, the cache update unit 630 is configured to utilize threads to perform write and delete operations; while a thread is performing write and / or delete operations on the computation model cache, the computation model cache is locked to prevent other threads from performing write and / or delete operations on the computation model cache.
[0099] In some embodiments, the first update condition includes: the current time has reached the update time; the cache update unit 630 is used to periodically update the update time using a preset update period; the computing model cache is configured with a storage limit parameter, and the expiration time is less than the product of the storage limit parameter and the preset update period.
[0100] In some embodiments, the cache update unit 630 is used to obtain the target time period when the second update condition is met; and to delete the billing models in the calculation model cache whose billing time period is outside the target time period.
[0101] In some embodiments, the determining unit 610 is further configured to, if the step of determining a billing rule matching the first time period from the database fails, calculate the retry time of the step according to the exponential backoff algorithm, and re-execute the step when the retry time is reached.
[0102] In some embodiments, the cache update unit 630 is further configured to, if the number of execution failures reaches a preset threshold, copy the billing model in the calculation model cache area whose billing time period is closest to the first time period, and modify the billing time period of the copied billing model to the first time period to obtain the first billing model.
[0103] It is understood that the billing device described above can implement each step of the billing method provided in the foregoing embodiments. The relevant explanations of the billing method are applicable to the billing device and will not be repeated here.
[0104] Figure 7 This is a schematic diagram of the structure of an electronic device according to an embodiment of this application. Please refer to it. Figure 7 At the hardware level, the electronic device includes a processor, and optionally also includes an internal bus, a network interface, and memory. The memory may include main memory, such as high-speed random-access memory (RAM), or non-volatile memory, such as at least one disk drive. Of course, the electronic device may also include other hardware required for other business operations.
[0105] The processor, network interface, and memory can be interconnected via an internal bus, which can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus, or an EISA (Extended Industry Standard Architecture) bus, etc. This bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 7 The symbol is represented by a single double-headed arrow, but this does not mean that there is only one bus or one type of bus.
[0106] Memory is used to store programs. Specifically, programs may include program code, which includes computer operation instructions. Memory may include main memory and non-volatile memory, and provides instructions and data to the processor.
[0107] The processor reads the corresponding computer program from non-volatile memory into main memory and then executes it, forming a billing device at the logical level. The processor executes the program stored in memory and specifically performs the following operations:
[0108] If the first update condition is met, a first time period starting from the current time is determined; a billing rule matching the first time period is determined from the database, a first billing model is generated according to the determined billing rule, and the first time period is used as the billing time period of the first billing model; the first billing model is written into the computing model cache, and an expiration time is configured for the first billing model in the computing model cache so that the first billing model can be deleted from the computing model cache if the expiration time is met; according to the time attribute of the billing request, a computing model matching the billing time period and the time attribute is determined from the computing model cache, and the billing request is processed using the determined billing model.
[0109] The above is as stated in this application. Figure 6 The billing device method disclosed in the illustrated embodiments can be applied to a processor or implemented by a processor. The processor may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by integrated logic circuits in the processor's hardware or by instructions in software form. The processor can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in the embodiments of this application can be directly embodied in the execution of a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor. The software module can reside in a mature storage medium in the field, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. This storage medium is located in memory, and the processor reads information from the memory and, in conjunction with its hardware, completes the steps of the above method.
[0110] The electronic device can also perform Figure 6 The method for the billing device to perform, and to realize the billing device in Figure 3 The functions of the embodiments shown are not described in detail here.
[0111] This application also proposes a computer-readable storage medium that stores one or more programs, the programs including instructions that, when executed by an electronic device including multiple applications, enable the electronic device to perform... Figure 6 The method executed by the billing device in the illustrated embodiment is specifically used to perform:
[0112] If the first update condition is met, a first time period starting from the current time is determined; a billing rule matching the first time period is determined from the database, a first billing model is generated according to the determined billing rule, and the first time period is used as the billing time period of the first billing model; the first billing model is written into the computing model cache, and an expiration time is configured for the first billing model in the computing model cache so that the first billing model can be deleted from the computing model cache if the expiration time is met; according to the time attribute of the billing request, a computing model matching the billing time period and the time attribute is determined from the computing model cache, and the billing request is processed using the determined billing model.
[0113] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0114] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0115] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0116] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0117] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0118] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0119] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, 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 technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0120] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0121] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0122] The above description is merely an embodiment of this application and is not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A billing method, wherein, The method is executed by the billing server and includes: If the first update condition is met, the first time period starting from the current time is determined; The billing rules that match the first time period are determined from the database, a first billing model is generated based on the determined billing rules, and the first time period is used as the billing period of the first billing model. Write the first billing model into the computing model cache area, configure an expiration time for the first billing model in the computing model cache area, and delete the first billing model from the computing model cache area if the expiration time is met. Based on the time attribute of the billing request, a calculation model that matches the time attribute is determined from the calculation model cache, and the billing request is processed using the determined billing model. The first update condition is used to determine whether a billing model should be added to the computing model cache at the current moment; The first update condition includes: the current time reaches the update time; the method further includes: periodically updating the update time using a preset update period; The computing model cache is configured with a storage limit parameter, and the expiration time is less than the product of the storage limit parameter and the preset update cycle.
2. The method as described in claim 1, wherein, The method further includes: If the time attribute of the billing request does not match the billing time period of each billing model in the computing model cache, then a second time period is determined according to the time attribute, a billing rule matching the second time period is determined from the database, a second billing model is generated according to the determined billing rule, and the second time period is used as the billing time period of the second billing model. Write the second billing model into the computing model cache and configure an expiration time for the second billing model in the computing model cache.
3. The method as described in claim 2, wherein, The write and delete operations are performed using threads; the method further includes: When a thread performs write and / or delete operations on the computation model cache, the computation model cache is locked to prevent other threads from performing write and / or delete operations on the computation model cache.
4. The method of claim 1, wherein, The method further includes: If the second update condition is met, obtain the target time period; Delete the billing models in the calculation model cache whose billing time period is outside the target time period.
5. The method of claim 1, wherein, The method further includes: If the step of determining the billing rule that matches the first time period from the database fails, the retry time for this step is calculated according to the exponential backoff algorithm, and the step is re-executed when the retry time is reached.
6. The method of claim 5, wherein, The method further includes: If the number of execution failures reaches a preset threshold, the billing model in the calculation model cache that is closest to the first time period is copied, and the billing time period of the copied billing model is modified to the first time period to obtain the first billing model.
7. A billing device, wherein, The device is applied to a billing server to implement the method described in any one of claims 1 to 6.
8. An electronic device, comprising: processor; as well as A memory configured to store computer-executable instructions, which, when executed, cause the processor to perform the method of any one of claims 1 to 6.
9. A computer-readable storage medium storing one or more programs, which, when executed by an electronic device including a plurality of applications, cause the electronic device to perform the method of any one of claims 1 to 6.
Citation Information
Patent Citations
Method and device for controlling PCC (policy control and charging) rules in Preload mode
CN103002426A
Carbon quota calculation method and device, storage medium and terminal equipment
CN113094580A
