WO2023147716A1 - Flow control and billing methods, apparatuses and system, electronic device, medium and product - Google Patents
Flow control and billing methods, apparatuses and system, electronic device, medium and product Download PDFInfo
- Publication number
- WO2023147716A1 WO2023147716A1 PCT/CN2022/106800 CN2022106800W WO2023147716A1 WO 2023147716 A1 WO2023147716 A1 WO 2023147716A1 CN 2022106800 W CN2022106800 W CN 2022106800W WO 2023147716 A1 WO2023147716 A1 WO 2023147716A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- amount
- request
- billing
- service
- flow control
- Prior art date
Links
- 238000000034 method Methods 0.000 title claims abstract description 140
- 230000004044 response Effects 0.000 claims abstract description 90
- 238000012545 processing Methods 0.000 claims description 128
- 230000008569 process Effects 0.000 claims description 47
- 238000004590 computer program Methods 0.000 claims description 12
- 238000009825 accumulation Methods 0.000 claims description 7
- 230000001960 triggered effect Effects 0.000 claims description 2
- 238000013473 artificial intelligence Methods 0.000 description 13
- 238000010586 diagram Methods 0.000 description 13
- 238000012217 deletion Methods 0.000 description 12
- 230000037430 deletion Effects 0.000 description 12
- 238000004891 communication Methods 0.000 description 9
- 230000006870 function Effects 0.000 description 7
- 230000007246 mechanism Effects 0.000 description 5
- 238000004364 calculation method Methods 0.000 description 4
- 238000007405 data analysis Methods 0.000 description 4
- 238000007781 pre-processing Methods 0.000 description 4
- 230000002028 premature Effects 0.000 description 4
- 239000000284 extract Substances 0.000 description 3
- 238000012986 modification Methods 0.000 description 3
- 230000004048 modification Effects 0.000 description 3
- 230000003287 optical effect Effects 0.000 description 3
- 230000002159 abnormal effect Effects 0.000 description 2
- 230000009471 action Effects 0.000 description 2
- 230000015572 biosynthetic process Effects 0.000 description 2
- 238000011161 development Methods 0.000 description 2
- 238000005516 engineering process Methods 0.000 description 2
- 230000003993 interaction Effects 0.000 description 2
- 238000012552 review Methods 0.000 description 2
- 238000003786 synthesis reaction Methods 0.000 description 2
- 238000013519 translation Methods 0.000 description 2
- 238000004458 analytical method Methods 0.000 description 1
- 238000003491 array Methods 0.000 description 1
- 230000005540 biological transmission Effects 0.000 description 1
- 238000004422 calculation algorithm Methods 0.000 description 1
- 230000001413 cellular effect Effects 0.000 description 1
- 238000010276 construction Methods 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 238000001514 detection method Methods 0.000 description 1
- 239000012634 fragment Substances 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 238000010801 machine learning Methods 0.000 description 1
- 239000013307 optical fiber Substances 0.000 description 1
- 239000004065 semiconductor Substances 0.000 description 1
- 230000001953 sensory effect Effects 0.000 description 1
- 238000007619 statistical method Methods 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
- 238000012546 transfer Methods 0.000 description 1
- 230000000007 visual effect Effects 0.000 description 1
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L12/00—Data switching networks
- H04L12/02—Details
- H04L12/14—Charging, metering or billing arrangements for data wireline or wireless communications
- H04L12/141—Indication of costs
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/14—Session management
- H04L67/146—Markers for unambiguous identification of a particular session, e.g. session cookie or URL-encoding
Definitions
- the present disclosure relates to the technical field of computers, and in particular to the technical field of traffic billing.
- Flow control billing that is, flow control and billing, refers to the control and billing of user access, that is, according to the billing objects consumed by user access, allowing users to access or prohibiting user access, and according to user access Billing is carried out according to the consumption of billing objects.
- Flow control billing scenarios are widely used.
- the current flow control billing scenarios include: AI voice recognition flow control billing scenarios, AI speech synthesis flow control billing scenarios, AI text translation character flow control billing scenarios, AI video live broadcast review flow control billing scenarios and mobile phone Traffic flow control billing scenarios, etc.
- the disclosure provides a flow control billing method, device, system, electronic equipment, medium and product.
- the first aspect of the embodiments of the present disclosure provides a flow control and charging method, which is applied to the flow control and charging module, including:
- the begin request is sent by the proxy service after receiving the service request sent by the terminal, the begin request includes the user ID that triggers the service request and the script for processing the service request Estimated amount of fees;
- the estimated charge amount corresponding to the user identifier is the amount corresponding to the user identifier The sum of the current estimated cost of each service request being processed;
- the second aspect of the embodiments of the present disclosure provides a flow control billing method applied to proxy services, including:
- the flow control and billing module judges the current estimated billing amount and the already charged amount corresponding to the user identifier Whether the sum of the expected fee amount and the used amount is greater than the available amount is obtained to obtain a judgment result, and based on the judgment result, it is determined whether to respond to the service request, and based on the response result of the service request, the used amount corresponding to the user identifier is accumulated, and the The estimated billing amount corresponding to the user ID is the sum of the current estimated billing amounts of the service requests being processed corresponding to the user ID.
- the third aspect of the embodiments of the present disclosure provides a flow control and charging device, which is applied to the flow control and charging module, including:
- the first receiving module is configured to receive a start request sent by the proxy service, the begin request is sent by the proxy service after receiving the service request sent by the terminal, and the begin request includes the user identifier and the user ID that triggered the service request The current estimated fee for processing the business request;
- a judging module configured to judge whether the sum of the expected billing amount, the estimated billing amount corresponding to the user identifier, and the used amount is greater than the available amount, and obtain a judgment result;
- the estimated billing amount corresponding to the user identifier is The sum of the current estimated charges for each service request being processed corresponding to the above user ID;
- the accumulation module is configured to determine whether to respond to the service request based on the judgment result of the judgment module, and to accumulate the used amount corresponding to the user identifier based on the response result of the service request.
- a device for flow control and charging is provided, which is applied to proxy services, including:
- the second receiving module is configured to receive a service request sent by a terminal, where the service request includes a user identifier triggering the service request;
- the current estimated fee amount determination module is used to determine the current estimated fee amount of the service request
- the second sending module is configured to send a begin request carrying the user identifier and the expected charge amount to the flow control and charging module, so that the flow control and charge module can judge the current estimate charge amount, Whether the sum of the estimated charge amount and the used amount corresponding to the user identifier is greater than the available amount is obtained as a judgment result, and based on the judgment result, it is determined whether to respond to the service request, and the user identifier is accumulated based on the response result of the service request.
- the corresponding used amount, the estimated billed amount corresponding to the user ID is the sum of the current estimated billed amount of each service request being processed corresponding to the user ID.
- the fifth aspect of the embodiments of the present disclosure provides a flow control and charging system, including a proxy service, a flow control and charging module, and an operator service;
- the flow control and billing module is configured to execute the method described in any one of the first aspect
- the proxy service is used to perform the method described in any one of the second aspect
- the operator service is used to process business requests.
- an electronic device including:
- the memory stores instructions executable by the at least one processor, the instructions are executed by the at least one processor, so that the at least one processor can perform any one of the first aspect or the second aspect the method described.
- a seventh aspect of the embodiments of the present disclosure provides a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to make the computer execute any one of the first aspect or the second aspect the method described.
- An eighth aspect of the embodiments of the present disclosure provides a computer program product, including a computer program, when the computer program is executed by a processor, the method described in any one of the first aspect or the second aspect is implemented.
- FIG. 1 is a flowchart of a flow control and billing method provided by an embodiment of the present disclosure
- Figure 2a is an exemplary schematic diagram of a flow control charging process in the related art
- Fig. 2b is an exemplary schematic diagram of a flow control and charging process in an embodiment of the present disclosure
- FIG. 3 is a flow chart of a method for refreshing a doing heartbeat provided by an embodiment of the present disclosure
- FIG. 4 is a flow chart of a method for processing a timed task provided by an embodiment of the present disclosure
- FIG. 5 is a flowchart of another flow control and billing method provided by an embodiment of the present disclosure.
- FIG. 6 is a flow chart of another doing heartbeat refreshing method provided by an embodiment of the present disclosure.
- FIG. 7 is an exemplary schematic diagram of a process of processing a begin request provided by an embodiment of the present disclosure.
- FIG. 8 is an exemplary schematic diagram of a process of processing an end request provided by an embodiment of the present disclosure.
- FIG. 9 is an exemplary schematic diagram of a process of processing a doing request provided by an embodiment of the present disclosure.
- FIG. 10 is an exemplary schematic diagram of a process of processing a timed task provided by an embodiment of the present disclosure
- Fig. 11 is a schematic structural diagram of a flow control and billing device provided by an embodiment of the present disclosure.
- Fig. 12 is a schematic structural diagram of another flow control and billing device provided by an embodiment of the present disclosure.
- Fig. 13 is a schematic structural diagram of a flow control and billing system provided by an embodiment of the present disclosure.
- Fig. 14 is a block diagram of an electronic device used to implement the flow control and billing method of the embodiment of the present disclosure.
- Flow control billing that is, flow control and billing, refers to the control and billing of user access, that is, according to the billing objects consumed by user access, allowing users to access or prohibiting user access, and according to user access Billing is carried out according to the consumption of billing objects.
- Flow control billing scenarios are widely used.
- the current flow control billing scenarios include: AI voice recognition flow control billing scenarios, AI speech synthesis flow control billing scenarios, AI text translation character flow control billing scenarios, AI video live broadcast review flow control billing scenarios and mobile phone Traffic flow control billing scenarios, etc.
- the billing objects are different in different flow control billing scenarios.
- the search function needs to perform flow control billing according to the number of searches, that is, the billing object is the number of searches;
- the audio and video processing function needs to perform flow control billing according to the duration of the audio and video, that is, the billing object is the duration of the audio and video;
- Processing requires flow control billing based on the number of words included in the document, that is, the billing object is the number of words included in the document;
- the use of mobile phone traffic needs to be billed according to the byte stream, that is, the billing object is the byte stream.
- each billing object can be represented by a numerical value, so the traditional flow control billing method is an accumulative billing object.
- the traditional flow control billing method is: each time a request sent by a user is received, the number of visits is increased by 1, and the current number of visits is compared with the upper limit. If the upper limit is reached, the access is prohibited; otherwise, the access is allowed, and a billing data with the number of visits plus 1 is generated.
- the billing data includes the amount that needs to be spent for one visit.
- the traditional flow control billing method is: each time a request sent by the user is received, the amount of the billing object is added to n, and the billing object The usage is compared with the upper limit, where n is the number of billing objects consumed by the request. If the upper limit is reached, the access is prohibited; otherwise, the access is allowed, and a billing data of the billing object usage plus n is generated. Wherein, the billing data includes the amount needed to consume n billing objects.
- Solution 1 is pre-emptive flow control: after receiving the request sent by the user, the flow control billing module estimates whether the number of billing objects required to process the request meets the quota requirements, and if so, directly processes the request and sends the estimated The number of billing objects is added to the number of used billing objects, and a bill is generated. When it is found that the processing of the request sent by the user fails, the data rollback operation is performed, or the generated billing bill is deleted.
- This solution has both data accumulation logic and data rollback logic, resulting in complex overall logic and high computational pressure on the flow control and billing module, so it is difficult to apply to high-concurrency scenarios. Moreover, users can perceive abnormal bills generated by request processing failures, so general scenarios are not applicable.
- Solution 2 is downstream flow control: after receiving the request sent by the user, the flow control and billing module determines whether the user is a normal available user.
- the normally available users are users whose number of used billing objects has not exceeded the limit. If it is not a normally available user, the request is rejected. If it is a normal available user, the request is processed directly, and after the request is successfully processed, the number of billing objects consumed by processing the request is added to the number of billing objects used, and a billing bill is generated. Then judge whether the number of used billing objects exceeds the upper limit, and if so, set the user as an unavailable user without quota. If not, keep the user as a normal available user.
- This solution only bills for successfully processed requests, which can avoid abnormal bills. However, in high-concurrency scenarios, it is difficult to achieve timely traffic control due to the lag in the accumulation of billing objects due to subsequent deduction. It may happen that the user overuses the billing object.
- an embodiment of the present disclosure provides a flow control charging method.
- the current estimated billing amount indicates the estimated number of billing objects that will be consumed if the operator service processes the business request received this time.
- the estimated billing amount indicates the sum of the current estimated billing amount of each business request being processed by the operator service.
- the actual billing amount indicates the number of billing objects actually consumed by the operator service to process the business request received this time.
- the successfully billed amount indicates the number of billing objects that have been successfully consumed during the process of the operator service processing the business request received this time.
- the available quota indicates the upper limit of the number of billing objects that the user can use.
- the flow control billing method provided by the embodiment of the present disclosure can be applied to the flow control billing module, as shown in Figure 1, the method includes the following steps:
- the begin request is sent by the proxy service after receiving the service request sent by the terminal, and the begin request includes the user identification triggering the service request and the current estimated fee for processing the service request.
- the user sends a service request to the proxy service through the terminal, and the proxy service extracts the traffic type from the service request after receiving the service request.
- the traffic type may be an audio and video type, a text type, or a search type, and the like.
- the charging mode corresponding to the extracted traffic type is determined.
- the determined charging method determine the current estimated fee amount of the service request. For example, when the billing method is billing according to the duration, the duration of the audio and video data included in the service request is taken as the estimated billing amount for this time; 1.
- the proxy service generates a begin request, wherein the begin request specifically includes: the user ID that triggers the service request, the current estimated billing amount, the session number (Session Number, SN) of the session between the proxy service and the terminal, the charging method and the billing method.
- the fee interface identity identification number (Identity document, id).
- the proxy service sends a begin request to the flow control and billing module.
- the session number may also be referred to as a session identifier.
- the proxy service is used to replace the flow control and billing module to interact with the terminal, and replace the flow control and billing module to interact with the operator service.
- the operator service is used to process business requests.
- the billing interface id is the interface id for calling operator services, that is, each operator service corresponds to a
- the billing interface id the proxy service can extract the billing interface id from the service request.
- the estimated billing amount corresponding to the user ID is the sum of the current estimated billing amounts of the service requests being processed corresponding to the user ID.
- the business requests can be processed in parallel, and the usage will not be accumulated until the business requests are successfully processed. If for each business request, it is only judged whether the sum of the expected fee amount and the used amount of the business request exceeds the available quota, then when multiple business requests are processed in parallel, because the business requests have not been processed, the accumulated amount will not be accumulated. usage, so that the sum of the expected charge amount and the used amount of each business request does not exceed the available quota, and each business request will be processed normally. However, after the processing is completed, when accumulating the used amount, the actual billing amount of each business request is added to the used amount. At this time, the used amount may exceed the available quota, resulting in the problem of exceeding the actual usage quota.
- the flow control billing module receives the first request, it will process it normally. But when the second request is received, if the first request is being processed and the used amount is not accumulated at this time, so that the used amount is still 4, then for the second request, the estimated amount of 1 and the used amount of 4 are still used The sum of is compared with the available quota 5, and the result of not exceeding the available quota is obtained, so that the second request will also be processed. But if the two requests are processed successfully, the accumulated amount will be 6, exceeding the available quota.
- the flow control and billing module when the flow control and billing module receives the first request, it processes it normally.
- the second request if the first request is being processed, the estimated amount is 1.
- the sum of the estimated amount 1, the estimated amount 1, and the used amount 4 exceeds the available amount 5, A result that exceeds the available quota causes the second request to not be processed. In this way, the problem of excessive usage of billing objects in high concurrency scenarios can be reduced.
- S103 Determine whether to respond to the service request based on the judgment result, and accumulate the used amount corresponding to the user identifier based on the response result of the service request.
- the judgment result when the judgment result is yes, it is determined to reject the service request of the terminal, and 0 is added to the used amount corresponding to the user identifier, that is, the used amount corresponding to the user identifier remains unchanged.
- the judgment result is no, it is determined to respond to the service request of the terminal, and the used amount corresponding to the user identifier is accumulated according to the processing situation of the service request.
- the traditional flow control billing scheme adopts the straight-line strategy, that is, the flow control billing module is responsible for receiving service requests sent by users, calling operator services to process service requests, and returning the processing results to users. Perform flow control and billing. It can be seen that in this method, the flow control and billing module is responsible for more processing logic, so the processing pressure it bears is relatively high. In high concurrency scenarios, as the traffic pressure increases, it is difficult to guarantee the stability of the flow control and billing module. .
- the embodiment of the present disclosure separates traffic sending and receiving from flow control and charging, that is, as shown in FIG. 2b, the embodiment of the present disclosure adds a proxy service, and the proxy service replaces the flow control and charging module Interact with terminals and operator services, that is, the proxy service is responsible for simple logic processing and does not perform complex logic calculations.
- the flow control and billing module is responsible for flow control and billing. Since the embodiment of the present disclosure reduces the processing logic of the flow control and charging module, that is, reduces the pressure carried by the flow control and charging module, it is applicable to high concurrency scenarios.
- the flow control and billing module before processing the service request, the flow control and billing module first judges whether the sum of the expected billing amount, the estimated billing amount and the used amount corresponding to the user ID is greater than the available amount, that is, judges whether the processing business The question of whether the request will cause excess, at this time, the available quota is not directly accumulated, but the available quota is subsequently accumulated according to the response result of the business request. Therefore, even if the service request fails to be processed, there is no need to perform data rollback or deletion, which solves the problem of data rollback or deletion caused by premature billing in advance flow control.
- the embodiment of the present disclosure first judges whether processing a business request will cause an overage problem before processing the business request, it solves the hysteresis of subsequent flow control oversubscription determination, and thus can be applied to high concurrency scenarios.
- the above-mentioned S103 determines whether to respond to the service request based on the judgment result, and accumulates the used amount corresponding to the user ID based on the response result of the service request, including the following steps:
- Step 1 If the judgment result is yes, the flow control and billing module sends a begin failure response to the proxy service, so that the proxy service sends a request failure response to the terminal.
- the sum of the estimated billing amount, the estimated billing amount corresponding to the user ID, and the used amount is greater than the available amount, it means that if all the service requests currently being processed by the user are successfully processed, the difference between the available amount and the accumulated estimated amount The difference is less than the expected fee amount for this time, that is, processing the service request currently sent by the user may cause the used quota to exceed the limit, so the service request is rejected and the request failure is reported to the terminal.
- Step 2 If the judgment result is no, the flow control and billing module will add the estimated billing amount to the estimated billing amount corresponding to the user ID, and send a begin success response to the proxy service, so that the proxy service calls the operator service to process the business request, and send an end (end) request to the flow control and billing module when it is determined that the operator service processing is completed.
- the end request includes the actual billing amount consumed by processing the service request.
- the estimated billing amount represents the sum of the current estimated billing amount of each service request being processed by the operator service. If the sum of the current estimated billing amount, the estimated billing amount and the used amount If it is greater than the available quota, it means that if all the business requests currently being processed by the user are successfully processed, the difference between the available quota and the accumulated estimated billing amount is still greater than or equal to the estimated billing amount of this time, that is, the business request currently sent by the user is processed The used quota will not be exceeded, so the received service request can be processed. Since it has been judged that the business request can be processed at this time, and the business request is about to be forwarded to the operator service for processing, it is necessary to add the current estimated fee amount of the business request to the estimated fee amount.
- the response of the flow control and accounting module to the begin request may include a status flag, which is used to indicate whether the begin request is successful, so that the proxy service can identify whether the begin request is successful through the status flag. For example, when the status flag is 1, it means that the begin request is successful, and the response at this time is called a begin success response; when the status flag is 0, it means that the begin request fails, and the response at this time is called a begin failure response.
- the proxy service When the proxy service receives a successful response from begin, it forwards the received business request to the operator service, and the operator service processes the business request and forwards the processing result to the proxy service.
- the processing result specifically includes the response result to the service request and the actual billing amount consumed for processing the service request.
- the proxy service receives the processing result of the operator service, it determines that the processing of the operator service is completed, and sends an end request to the flow control and billing module. Moreover, when the proxy service receives the processing result of the operator service, it can also feed back the response result to the business request to the terminal.
- Step 3 The flow control and billing module receives the end request sent by the proxy service, adds the actual billed amount to the used amount corresponding to the user ID, and deletes the current estimated billed amount from the estimated billed amount corresponding to the user ID.
- the flow control and billing module When the flow control and billing module receives the end request, it means that the operator service has completed processing the business request, so the actual billing amount needs to be added to the user's used amount. At the same time, since the service request has been processed, it is necessary to delete the current estimated amount from the user's estimated amount.
- the flow control and billing module before processing the service request, performs flow control based on the current estimated fee amount, and the current estimated fee amount is not directly added to the used amount, but is added to the service The actual billed amount will be added to the used amount only after the request processing is completed. That is to say, the embodiment of the present disclosure combines proactive flow control and backward flow control, and there is no accumulated used amount during proactive flow control, so even if the service request processing fails, there is no need to perform data rollback or deletion, which solves the problem of proactive flow control Problems caused by premature billing that require data rollback or deletion.
- Subsequent flow control can accumulate the used amount according to the actual billing amount consumed when the request is processed successfully, and pre-emptive flow control is performed before post-traffic flow control, and pre-emptive flow control can reduce traffic overuse, that is, in On the basis of accurate flow control, it solves the problem that subsequent flow control easily leads to excessive use of flow. Therefore, the embodiments of the present disclosure can perform accurate flow control in high concurrency scenarios.
- the operator service may successfully process the service request, it may also fail to process it. Regardless of whether the processing succeeds or fails, the billing amount actually consumed by the computing sub-service in the process of processing the business request can be counted, so that the subsequent analysis and statistics of the processing results of the computing sub-service can be performed. Therefore, no matter whether the operator service is processed successfully or not, the processing result can include the actual billing amount consumed by processing the service request. In order for the flow control billing module to distinguish whether the operator service is successfully processed, the actual billing amount of the successfully processed business request is added to the used amount, and the actual billing amount of the failed business request is not added to the used amount.
- the embodiment of the present disclosure sets a status code (status_code), which is used to indicate whether the service request is processed successfully.
- the proxy service can extract the status code from the processing result fed back by the operator service for the business request, and generate an end request including the status code.
- the flow control and billing module needs to judge whether the actual charging amount needs to be accumulated, including the following steps: judging whether the status code in the end request indicates that the service request is processed successfully, wherein the end request includes the status code. If not, it is determined that the actual charging amount consumed for processing the service request is 0, and the used amount corresponding to the user identifier remains unchanged. If yes, obtain the actual billing amount from the end request, and perform the step of adding the actual billing amount to the used amount corresponding to the user ID in step 3.
- the status code is -1, it means that there is an internal error in the operator service, that is, the business request processing failed; when the status code is 0, it means that the calculation of the business request by the operator service is normal, that is, the business request is processed successfully.
- the status code is used to distinguish whether the service request is successfully processed, so that the flow control and charging module can use the status code to distinguish whether the actual charging amount needs to be added to the used amount. And no matter whether the service request is processed successfully, the end request can include the actual billing amount, so that the flow control billing module can store the actual billing amount of each service request, which is convenient for subsequent statistical analysis.
- the flow control billing module may mistakenly add the actual billed amount in the end request to the used amount for multiple consecutive times, resulting in billing errors.
- both the begin request and the end request include the session identifier of the session between the proxy service and the terminal.
- the flow control and billing module can also record the session ID in the begin request.
- the flow control billing module can perform data analysis and preprocessing on the begin request, including: extracting from the begin request the user ID that triggers the service request, the expected charge amount, SN, and billing method and billing interface id and other data, and store the extracted data correspondingly.
- the data extracted from the begin request, the estimated billing amount, the successfully billed amount, the actual billed amount, and the used amount are collectively referred to as billing data.
- the flow control and billing module can store the billing data in a distributed remote dictionary service (Remote Dictionary Server, Redis), wherein the distributed Redis includes multiple fragments, and the flow control and billing module can be based on user ID, and store the billing data of the same user in the same shard of distributed Redis.
- Redis distributed remote dictionary service
- the embodiments of the present disclosure can improve search efficiency, and thus are more suitable for high concurrency scenarios.
- the flow control and billing module may also delete the recorded session ID when the judgment result is yes. Understandably, since the flow control billing module judges that the sum of the expected billing amount, the estimated amount corresponding to the user ID, and the used amount is greater than the available amount, it returns a begin failure response to the proxy service. At this time, the business request does not will be processed, so delete the recorded session id.
- the flow control billing module can also inquire whether the session ID in the end request has been recorded; if so, delete the recorded session ID; if not, then End requests are ignored.
- the flow control and billing module when the flow control and billing module receives the end request, if the session identifier included in the end request is not recorded, it means that the service request corresponding to the session identifier has not been processed or has been processed, so the end request can be ignored. If the session ID included in the end request is recorded, it means that the service request corresponding to the session ID is currently processed and needs to be billed. Therefore, the flow control billing module will add the actual billing amount to the used amount corresponding to the user ID. Delete the session ID to avoid repeated charging for subsequent service requests corresponding to the session ID.
- the flow control and charging module identifies the processing status of the service request corresponding to the session ID through the session ID, thereby reducing the situation of repeated charging for the service request that has been processed.
- the embodiment of the present disclosure in order to further improve the accuracy of flow control and billing, is based on the requirements of long sessions, and on the basis of combining pre-flow control and post-flow control, between the begin request and the end request Increase the refreshing of doing heartbeats.
- the flow control and billing module sends a begin success response to the proxy service in the above step 2, and before receiving the end request in step 3, it can also perform the following steps:
- S301 Receive a processing (doing) request sent by the proxy service.
- the doing request includes the successfully billed amount consumed by the operator service currently processing the business request.
- the proxy service can obtain the successfully billed amount consumed by processing business requests in real time from the operator service, and periodically send a doing request to the flow control and billing module, so that the flow control and billing module can timely Get the current successfully billed amount.
- the billing module obtains the successfully billed amount, it can update the estimated billed amount to the successfully billed amount, so as to perform traffic control based on the real billed amount. And when the doing request is continuously received subsequently, the current estimated billing amount can be updated to the successfully billed amount included in the latest received doing request, so that flow control can be performed in real time according to the real billing amount.
- the current estimated amount recorded in the flow control billing module is the estimated amount included in the begin request, or the successfully billed amount included in the latest received doing request.
- the actual billing amount included in the end request is the total billing amount consumed by the operator service from the start of processing the business request to the completion of the processing.
- the response of the flow control and billing module to the doing request may include a doing status flag, which is used to indicate whether the doing request is successful, so that the proxy service can identify whether the doing request is successful through the doing status flag. For example, in the response sent by the flow control and accounting module to the proxy service for the doing request, if the doing status flag is 1, it means that the doing request is successful, and the response is called a doing success response; if the doing status flag is 0, it means If the doing request fails, the response is called a doing failure response.
- a doing status flag which is used to indicate whether the doing request is successful, so that the proxy service can identify whether the doing request is successful through the doing status flag. For example, in the response sent by the flow control and accounting module to the proxy service for the doing request, if the doing status flag is 1, it means that the doing request is successful, and the response is called a doing success response; if the doing status flag is 0, it means If the doing request fails, the response is called a doing failure response.
- the proxy service When the proxy service receives a successful response of doing, it means that there is no overrun problem in the current processing of business requests, so the business requests can continue to be executed.
- the proxy service When the proxy service receives a doing failure response, it means that the current processing business request has exceeded the limit and needs to stop processing the business request. Therefore, the proxy service can send a termination notification message to the operator service, so that the operator service stops processing the business request, and When the processing of the business request is stopped, the successfully billed amount consumed by the current processing of the business request is sent to the proxy service.
- the proxy service generates an end request based on the status code indicating that the business request processing failed and the received successful billing amount, and sends the end request to the flow control billing module.
- the flow control and billing module After receiving the end request, the flow control and billing module performs flow control and billing according to the relevant steps in the above step 3.
- the flow control billing module can obtain the successfully billed amount of the operator service processing business request in real time through the doing heartbeat mechanism, and the successful billed amount is the real usage, so the traffic billing module can real-time Traffic control and billing are performed based on actual usage.
- the proxy service can also determine whether the billing method is billing by the number of times.
- the billing method is billing according to the number of times, the session between the terminal and the proxy service is a short connection session.
- the doing heartbeat mechanism shown in Figure 3 may not be executed, or, when the doing heartbeat mechanism is executed, the operator is set The service is billed 1 per successful transfer to the proxy service.
- the billing method is not billing according to the number of times, the session between the terminal and the proxy service is generally a long connection session, so the doing heartbeat mechanism shown in FIG. 3 can be implemented.
- the flow control billing module since the operator service starts to process the business request, the amount of successful billing is small, and the amount of successful billing increases as the processing time increases. Therefore, the successful billing amount received by the flow control billing module in the early stage of business request processing is relatively small. When the successfully billed amount is small, the current estimated billing amount will not be updated for the time being. That is, after the flow control and billing module obtains the successfully billed amount from the doing request in S302, it can also perform the following steps:
- the flow control billing module does not update the estimated billing amount for the time being when the successful billing amount is less than or equal to the estimated billing amount, that is, does not update the estimated billing amount when the successful billing amount is small . If the current estimated charge amount in the estimated charge amount is small, the current flow control based on the estimated charge amount may be inaccurate, resulting in an overuse problem. Therefore, in the embodiment of the present disclosure, when the successfully billed amount is greater than the current estimated billed amount, the current estimated billed amount in the estimated billed amount is updated to the successfully billed amount, so as to reduce the problem of overuse. Moreover, the actual billing amount of the business request may be greater than the estimated billing amount of this time. Therefore, when the successful billing amount is greater than the estimated billing amount of this time, updating the estimated billing amount of this time in time can also reduce the estimated amount of this time. The problem of excess usage caused by the billed amount being less than the actual billed amount.
- the end request sent by the proxy service may be lost due to network or other problems. If the flow control and billing module does not receive the end request, it will always save the current estimated billing amount obtained through the begin request. , and it is also impossible to correctly charge the service request.
- a scheduled garbage collection (Garbage Collection, GC) task is set in the flow control billing module, as shown in Figure 4, the flow control billing module can also perform the following steps:
- S402. Determine that the actual billing amount is the successfully billed amount acquired from the doing request last time.
- the last successfully billed amount obtained from the doing request is closest to the actual billed amount consumed by processing the service request, so the actual billed amount is determined as the latest The successfully billed amount obtained from a doing request.
- the successfully billed amount carried in the doing request has not been obtained, it means that the service request may not be processed, so it is determined that the actual billed amount is 0.
- the flow control billing module can perform timely billing when the session ends abnormally through the scheduled GC task, and clear up the estimated billing amount in time to reduce the storage resources occupied by invalid withholding usage.
- the flow control and billing module can also calculate the actual billing amount based on The actual billing amount generates this billing bill.
- the charging bill includes: the actual billing amount, the fee calculated based on the actual billing amount, and a time stamp.
- the timestamp may be the time when the proxy service receives the business request, or the time when the business request is processed.
- the current billing bill can be regenerated, that is, when the service request processing fails, the actual billing amount is 0, and no billing bill will be generated at this time. Therefore, it avoids the problem that the charging bills generated in advance in the pre-emptive flow control scheme need to be deleted after the service request makes an error.
- the embodiment of the present disclosure also provides a flow control charging method, which is applied to proxy services. As shown in FIG. 5, the method includes the following steps:
- S501 Receive a service request sent by a terminal.
- the service request includes the ID of the user who triggers the service request.
- the flow control and billing module Send a begin request carrying the user ID and the estimated amount of charge to the flow control and billing module, so that the flow control and billing module judges whether the sum of the estimated charge amount, the estimated charge amount and the used amount corresponding to the user identifier is greater than the available amount Quota, get the judgment result, determine whether to respond to the business request based on the judgment result, and accumulate the used amount corresponding to the user ID based on the response result of the business request.
- the estimated billing amount corresponding to the user ID is the sum of the current estimated billing amounts of the service requests being processed corresponding to the user ID.
- the embodiment of the present disclosure separates traffic sending and receiving from flow control billing, that is, as shown in FIG. 2b, the embodiment of the present disclosure adds a proxy service, and the proxy service replaces the stream control billing module Interact with terminals and operator services, that is, the proxy service is responsible for simple logic processing and does not perform complex logic calculations.
- the flow control and billing module is responsible for flow control and billing. Since the embodiment of the present disclosure reduces the processing logic of the flow control and charging module, that is, reduces the pressure carried by the flow control and charging module, it is applicable to high concurrency scenarios.
- the flow control and billing module before processing the service request, the flow control and billing module first judges whether the sum of the expected billing amount, the estimated billing amount and the used amount corresponding to the user ID is greater than the available amount, that is, judges whether the processing business The question of whether the request will cause excess, at this time, the available quota is not directly accumulated, but the available quota is subsequently accumulated according to the response result of the business request. Therefore, even if the service request fails to be processed, there is no need to perform data rollback or deletion, which solves the problem of data rollback or deletion caused by premature billing in advance flow control.
- the embodiment of the present disclosure first judges whether processing a business request will cause an overage problem before processing the business request, it solves the hysteresis of subsequent flow control oversubscription determination, and thus can be applied to high concurrency scenarios.
- the proxy service may also perform the following steps:
- Step 1 Identify whether the received response sent by the flow control and accounting module to the begin request is a begin failure response or a begin success response.
- Step 2 If the begin failure response sent by the flow control and accounting module is received, send a request failure response to the terminal.
- begin failure response sent by the flow control and billing module If the begin failure response sent by the flow control and billing module is received, it means that the processing of the business request may lead to a quota limit problem, so a request failure response is sent to the terminal.
- step 2 reference may be made to the description in the above step 1, which will not be repeated here.
- Step 3 If the begin success response sent by the flow control and billing module is received, the service request is forwarded to the operator service, so that the operator service processes the service request.
- begin success response sent by the flow control and billing module If the begin success response sent by the flow control and billing module is received, it means that the processing of business requests generally does not cause the problem of exceeding the quota, so the operator service can be controlled to process business requests.
- step 3 for the specific implementation manner of step 3, reference may be made to the description in the above step 2, which will not be repeated here.
- Step 4 When it is determined that the operator service has completed the processing of the business request, send an end request to the flow control and billing module, so that the flow control and billing module will add the actual billing amount consumed by processing the business request included in the end request to the user In the used amount corresponding to the ID, delete the estimated billing amount for this time from the estimated billed amount corresponding to the user ID.
- step 4 for the specific implementation manner of step 4, reference may be made to the description in the above step 2, which will not be repeated here.
- the flow control and billing module in the embodiment of the present disclosure performs flow control based on the current estimated fee amount, and the current estimated fee amount is not directly added to the billed amount, but is added to the service
- the actual billed amount is added to the billed amount only after the request processing is completed. That is to say, the embodiment of the present disclosure combines the advanced flow control and the backward flow control, and the billed amount is not accumulated during the advanced flow control, so even if the service request processing fails, there is no need to perform data rollback or deletion, which solves the problem of the advanced flow Problems that require data rollback or deletion caused by premature billing of the control.
- Subsequent flow control can accumulate the used amount according to the actual billing amount consumed when the request is processed successfully, and pre-emptive flow control is performed before post-traffic flow control, and pre-emptive flow control can reduce traffic overuse, that is, in On the basis of accurate flow control, it solves the problem that subsequent flow control easily leads to excessive use of flow. Therefore, the embodiments of the present disclosure can perform accurate flow control in high concurrency scenarios.
- the proxy service in order to further improve the accuracy of flow control and billing, after the above step 3 forwards the business request to the operator service, as shown in Figure 6, the proxy service can also perform the following steps:
- the operator service may send the successful billing amount consumed by the previously processed service request to the proxy service in real time during the process of processing the service request.
- S602. Periodically send a doing request carrying a successfully billed amount to the flow control and billing module, so that the flow control and billing module obtains the successfully billed amount from the doing request, and includes the estimated billed amount corresponding to the user identifier Update the estimated billing amount of this time to the successfully billed amount obtained, and judge whether the sum of the current estimated billing amount and the used amount corresponding to the user ID is greater than the available amount, if not, send a doing success response to the proxy service, If so, send a doing failure response to the proxy service.
- the doing success response sent by the flow control and billing module if the doing success response sent by the flow control and billing module is received, it means that there is no overage problem in currently processing the service request, so the service request can continue to be processed.
- the flow control billing module can obtain the successfully billed amount of the operator service processing business request in real time, and the successful billed amount is the real usage, so the traffic billing module can real-time Traffic control and billing are performed based on actual usage.
- the flow control and billing module performs data analysis and preprocessing on the begin request, specifically: extracting the user ID that triggers the service request, the estimated amount of charge, SN, and billing method from the begin request and billing interface id and other data, and record the extracted data correspondingly. Then call the lua script of begin, and the processing process of the lua script of begin is the steps in the dotted line box in Fig. 7. Among them, lua is a small scripting language that can be flexibly embedded in applications, thus providing flexible expansion and customization functions for applications.
- lock the session identifier of the session that is, record the SN, and judge whether the locking is successful. If unsuccessful, return a begin failure response to the proxy service. If it succeeds, it is judged whether the sum of the expected charge amount, the estimated charge amount corresponding to the user ID, and the used amount is greater than the available amount. If it is greater than, the lock is released, that is, the recorded SN is deleted, and a begin failure response is returned to the proxy service. If it is not greater, add the estimated fee amount to the estimated fee amount.
- Store session data information specifically store the data extracted from the begin request to distributed Redis. Then return a begin success response to the proxy service.
- the flow control and billing module After receiving the end request, the flow control and billing module performs data analysis and preprocessing on the end request, specifically: extracting SN, status_code and actual billing amount from the end request, and corresponding records. Then judge whether the status_code is 0; if not, set the actual billing amount to 0, and if so, call the lua script of end.
- the processing process of the lua script of end is the steps in the dashed box in Figure 8.
- the session data information corresponding to the SN is deleted. If yes, generate a current billing bill according to the actual billing amount, and then delete the session data information corresponding to the SN. Afterwards, an end response is returned to the proxy service, indicating that the charging for this session is completed.
- the flow control and billing module after receiving the doing request, performs data analysis and preprocessing on the doing request, specifically: extracting the SN and the successfully billed amount, and corresponding records. Then call the lua script of doing, and the processing process of the lua script of doing is the steps in the dotted line box in Fig. 9 .
- the lua script of doing determine whether the lock of the session identifier exists, that is, whether the SN is recorded. If it does not exist, return a doing failure response to the proxy service. If it exists, update the latest processing time to the current time, and judge whether the successfully billed amount is greater than the expected billing amount this time. If it is greater, update the current estimated billing amount in the estimated billing amount corresponding to the user identifier to the successfully billed amount. If not greater than, keep the estimated cost unchanged. Then it is judged whether the sum of the current estimated billing amount and the used amount corresponding to the user identifier is greater than the available amount. If it is greater than, return a doing failure response to the proxy service. If it is not greater than, return a doing success response to the proxy service.
- the flow control and billing module detects in real time whether there is a timeout session, that is, for each SN, it is judged whether the doing request including the SN has not been received for a preset period of time after receiving the begin or doing request of the SN last time or end request. If not, return to continue detection. If yes, it is judged whether the timed out session has been marked with the successful billing amount by doing, that is, whether the successful billing amount carried in the doing request has been obtained. If not marked, set the actual billing amount to 0. If marked, set the actual billing amount to the last successful billing amount obtained from the doing request. Then call the lua script of end.
- the session data information corresponding to the SN is deleted. If yes, then generate the current billing bill according to the actual billing amount, and then delete the session data information corresponding to the SN. Then return to continue to detect whether there is a timeout session.
- an embodiment of the present disclosure provides a flow control and charging device, which is applied to the flow control and charging module.
- the device includes: a first receiving module 1101 , judgment module 1102 and accumulation module 1103;
- the first receiving module 1101 is used to receive the begin request sent by the proxy service.
- the begin request is sent by the proxy service after receiving the service request sent by the terminal.
- the begin request includes the user identification that triggers the service request and the current estimated fee for processing the service request quantity;
- the judging module 1102 is used to judge whether the sum of the expected billing amount, the estimated billing amount corresponding to the user ID, and the used amount is greater than the available amount, and obtain the judgment result; The sum of the current estimated fee volume of each service request processed;
- the accumulation module 1103 is configured to determine whether to respond to the service request based on the judgment result of the judgment module 1102, and to accumulate the used amount corresponding to the user identifier based on the response result of the service request.
- the accumulation module 1103 is specifically used for:
- the judging result of the judging module 1102 is no, then add the estimated billing amount to the estimated billing amount corresponding to the user identifier, and send a begin success response to the proxy service, so that the proxy service calls the operator service to process the business request, and When it is determined that the operator service processing is completed, an end request is sent to the flow control and billing module, and the end request includes the actual billing amount consumed by processing the business request;
- Receive the end request sent by the proxy service add the actual billing amount to the used amount corresponding to the user ID, and delete the estimated billing amount from the estimated billing amount corresponding to the user ID.
- the end request includes a status code, and the status code is used to indicate whether the service request is processed successfully;
- the device may also include: an actual charging amount determination module and an acquisition module;
- the judging module 1102 is also used to judge whether the status code in the end request indicates that the business request is processed successfully after receiving the end request sent by the proxy service;
- the actual billing amount determination module is used to determine that the actual billing amount consumed by processing the service request is 0 if the judgment result of the judging module 1102 is no, and keep the used amount corresponding to the user identification unchanged;
- the acquiring module is configured to acquire the actual billing amount from the end request if the judging result of the judging module 1102 is yes, and perform the step of adding the actual billing amount to the used amount corresponding to the user identifier.
- both the begin request and the end request include the session identifier of the session between the proxy service and the terminal;
- the device may also include: a recording module, a deletion module and a query module;
- the recording module is used to record the session ID in the begin request before judging whether the sum of the estimated billing amount, the estimated billing amount and the used amount corresponding to the user ID is greater than the available amount;
- the deletion module is used to delete the recorded session identification after judging whether the sum of the estimated amount of charge, the estimated amount corresponding to the user ID, and the amount used is greater than the available amount;
- the query module is used to query whether the session ID in the end request has been recorded before adding the actual billing amount to the used amount corresponding to the user ID; if so, delete the recorded session ID; if not, ignore the end request.
- the device may further include: a first sending module
- the first receiving module 1101 is also configured to receive the processing doing request sent by the proxy service after sending the begin success response to the proxy service and before receiving the end request sent by the proxy service, the doing request includes the current processing business request of the operator service The successfully billed amount consumed;
- the judging module 1102 is also used to obtain the successfully billed amount from the doing request, update the current estimated billed amount in the estimated billed amount corresponding to the user identifier to the acquired successful billed amount, and judge the current estimated billed amount Whether the sum of the fee amount and the used amount corresponding to the user ID is greater than the available amount;
- the first sending module is configured to send a doing success response to the proxy service if the judgment result of the judging module 1102 is no, so that the proxy service sends an end request to the flow control and charging module when it is determined that the operator service processing is completed;
- the first sending module is also configured to send a doing failure response to the proxy service if the judgment result of the judging module 1102 is yes, so that the proxy service terminates the operator service to process the business request, and determines that the actual billing amount is the current operator service Process the successfully billed amount consumed by the service request, and send an end request carrying the determined actual billed amount.
- the device may further include: a calling module;
- the judging module 1102 is also used for judging whether the successfully billed amount is greater than the expected billing amount after obtaining the successfully billed amount from the doing request;
- the calling module is used to call the judging module 1102 to execute the step of updating the current estimated charging amount in the estimated charging amount corresponding to the user identification to the acquired successful charging amount if the judgment result of the judging module 1102 is yes;
- the calling module is also used to keep the estimated billing amount unchanged if the judging result of the judging module 1102 is no, and call the judging module 1102 to judge whether the sum of the current estimated billing amount and the used amount corresponding to the user identification is greater than the available amount Quota steps.
- the device may further include: an actual billing amount determination module and a deletion module;
- the judging module 1102 is also used to judge whether the successful billing amount carried in the doing request has been obtained if the doing request or the end request has not been received for a preset duration;
- the actual billing amount determination module is used to determine that the actual billing amount is the successful billing amount obtained from the doing request last time if the judging result of the judging module 1102 is yes;
- the actual billing amount determination module is also used to determine that the actual billing amount is 0 if the judgment result of the judging module 1102 is no;
- the deletion module is used to add the actual billing amount determined by the actual billing amount determination module to the used amount corresponding to the user ID, and delete the current estimated billing amount from the estimated billing amount corresponding to the user ID.
- the device may further include: a generating module
- the generating module is configured to generate a current bill based on the actual billing amount when the actual billing amount is greater than zero after deleting the current estimated billing amount from the estimated billing amount corresponding to the user identifier.
- the embodiment of the present disclosure provides a device for flow control and billing, which is applied to proxy services.
- the device includes: a second receiving module 1201, this The estimated fee amount determination module 1202 and the second sending module 1203;
- the second receiving module 1201 is configured to receive a service request sent by a terminal, where the service request includes a user identifier triggering the service request;
- the current estimated fee amount determination module 1202 is used to determine the current estimated fee amount of the service request
- the second sending module 1203 is configured to send a begin request carrying a user identifier and an estimated billing amount to the flow control and billing module, so that the stream control and billing module can determine the estimated billing amount, the estimated billing amount corresponding to the user identifier, and the Determine whether the sum of usage is greater than the available quota. Based on the judgment result, determine whether to respond to the business request, and based on the response result of the business request, add up the used amount corresponding to the user ID.
- the estimated amount corresponding to the user ID is the amount corresponding to the user ID. The sum of the current estimated charge amount of each service request being processed.
- the device may further include: an identification module;
- the identification module is used to identify whether the received response sent by the flow control and accounting module to the begin request is a begin failure response or a begin success response after sending a begin request carrying a user identifier and an estimated amount to the flow control and accounting module;
- the second sending module 1203 is further configured to send a request failure response to the terminal if the begin failure response sent by the flow control and billing module is received;
- the second sending module 1203 is further configured to forward the service request to the operator service if the begin success response sent by the flow control and billing module is received, so that the operator service processes the service request;
- the second sending module 1203 is further configured to send an end request to the flow control and billing module when it is determined that the operator service has completed the processing of the service request, so that the flow control and billing module will use the end request to process the service request.
- the actual billed amount is added to the used amount corresponding to the user ID, and the current estimated billing amount is deleted from the estimated billed amount corresponding to the user ID.
- the device may further include: an acquisition module;
- the obtaining module is used to obtain the successfully billed amount consumed by the current processing business request from the operator service in real time after forwarding the service request to the operator service;
- the second sending module 1203 is also configured to periodically send a doing request carrying a successfully charged amount to the flow control and charging module, so that the flow control and charging module obtains the successfully charged amount from the doing request, and identifies the user In the corresponding estimated billing amount, the current estimated billing amount is updated to the obtained successfully billed amount, and it is judged whether the sum of the current estimated billing amount and the used amount corresponding to the user ID is greater than the available amount, and if not, send to The proxy service sends a doing success response, and if so, sends a doing failure response to the proxy service;
- the second sending module 1203 is further configured to terminate the operator service processing business request if receiving the doing failure response sent by the flow control and charging module, and determine that the actual billing amount is the consumed current processing business request of the operator service Successful billing amount, generate an end request based on the determined actual billing amount, and send the generated end request to the flow control billing module.
- an embodiment of the present disclosure provides a flow control billing system, as shown in FIG. 1303;
- Proxy service 1301, configured to execute the method steps performed by the proxy service in the above method embodiments
- the collection, storage, use, processing, transmission, provision, and disclosure of billing data involved are all in compliance with relevant laws and regulations, and do not violate public order and good customs.
- the service request in this embodiment is not a request for a specific user, and cannot reflect the personal information of a specific user.
- the present disclosure also provides an electronic device, a readable storage medium, and a computer program product.
- FIG. 14 shows a schematic block diagram of an example electronic device 1400 that may be used to implement embodiments of the present disclosure.
- Electronic device is intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other suitable computers.
- Electronic devices may also represent various forms of mobile devices, such as personal digital processing, cellular telephones, smart phones, wearable devices, and other similar computing devices.
- the components shown herein, their connections and relationships, and their functions, are by way of example only, and are not intended to limit implementations of the disclosure described and/or claimed herein.
- an electronic device 1400 includes a computing unit 1401, which can perform calculations according to a computer program stored in a read-only memory (ROM) 1402 or a computer program loaded from a storage unit 1408 into a random access memory (RAM) 1403. Various appropriate actions and processes are performed. In the RAM 1403, various programs and data necessary for the operation of the electronic device 1400 can also be stored.
- the computing unit 1401, ROM 1402, and RAM 1403 are connected to each other through a bus 1404.
- An input/output (I/O) interface 1405 is also connected to the bus 1404 .
- the I/O interface 1405 includes: an input unit 1406, such as a keyboard, a mouse, etc.; an output unit 1407, such as various types of displays, speakers, etc.; a storage unit 1408, such as a magnetic disk, an optical disk etc.; and a communication unit 1409, such as a network card, a modem, a wireless communication transceiver, and the like.
- the communication unit 1409 allows the electronic device 1400 to exchange information/data with other devices through a computer network such as the Internet and/or various telecommunication networks.
- the computing unit 1401 may be various general-purpose and/or special-purpose processing components having processing and computing capabilities. Some examples of computing units 1401 include, but are not limited to, central processing units (CPUs), graphics processing units (GPUs), various dedicated artificial intelligence (AI) computing chips, various computing units that run machine learning model algorithms, digital signal processing processor (DSP), and any suitable processor, controller, microcontroller, etc.
- the computing unit 1401 executes various methods and processes described above, such as flow control and charging methods.
- the flow control billing method may be implemented as a computer software program tangibly embodied on a machine-readable medium, such as the storage unit 1408 .
- part or all of the computer program can be loaded and/or installed on the electronic device 1400 via the ROM 1402 and/or the communication unit 1409.
- the computer program is loaded into the RAM 1403 and executed by the computing unit 1401, one or more steps of the flow control charging method described above can be performed.
- the computing unit 1401 may be configured in any other appropriate way (for example, by means of firmware) to execute the flow control and charging method.
- Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips Implemented in a system of systems (SOC), complex programmable logic device (CPLD), computer hardware, firmware, software, and/or combinations thereof.
- FPGAs field programmable gate arrays
- ASICs application specific integrated circuits
- ASSPs application specific standard products
- SOC system of systems
- CPLD complex programmable logic device
- computer hardware firmware, software, and/or combinations thereof.
- programmable processor can be special-purpose or general-purpose programmable processor, can receive data and instruction from storage system, at least one input device, and at least one output device, and transmit data and instruction to this storage system, this at least one input device, and this at least one output device an output device.
- Program codes for implementing the methods of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special purpose computer, or other programmable data processing devices, so that the program codes, when executed by the processor or controller, make the functions/functions specified in the flow diagrams and/or block diagrams Action is implemented.
- the program code may execute entirely on the machine, partly on the machine, as a stand-alone software package partly on the machine and partly on a remote machine or entirely on the remote machine or server.
- a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device.
- a machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium.
- a machine-readable medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing.
- machine-readable storage media would include one or more wire-based electrical connections, portable computer discs, hard drives, random access memory (RAM), read only memory (ROM), erasable programmable read only memory (EPROM or flash memory), optical fiber, compact disk read only memory (CD-ROM), optical storage, magnetic storage, or any suitable combination of the foregoing.
- RAM random access memory
- ROM read only memory
- EPROM or flash memory erasable programmable read only memory
- CD-ROM compact disk read only memory
- magnetic storage or any suitable combination of the foregoing.
- the systems and techniques described herein can be implemented on a computer having a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user. ); and a keyboard and pointing device (eg, a mouse or a trackball) through which a user can provide input to the computer.
- a display device e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor
- a keyboard and pointing device eg, a mouse or a trackball
- Other kinds of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and can be in any form (including Acoustic input, speech input or, tactile input) to receive input from the user.
- the systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., as a a user computer having a graphical user interface or web browser through which a user can interact with embodiments of the systems and techniques described herein), or including such backend components, middleware components, Or any combination of front-end components in a computing system.
- the components of the system can be interconnected by any form or medium of digital data communication, eg, a communication network. Examples of communication networks include: Local Area Network (LAN), Wide Area Network (WAN) and the Internet.
- a computer system may include clients and servers.
- Clients and servers are generally remote from each other and typically interact through a communication network.
- the relationship of client and server arises by computer programs running on the respective computers and having a client-server relationship to each other.
- the server can be a cloud server, a server of a distributed system, or a server combined with a blockchain.
- steps may be reordered, added or deleted using the various forms of flow shown above.
- each step described in the present disclosure may be executed in parallel, sequentially, or in a different order, as long as the desired result of the technical solution disclosed in the present disclosure can be achieved, no limitation is imposed herein.
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Management, Administration, Business Operations System, And Electronic Commerce (AREA)
Abstract
The disclosure relates to the technical field of computers, in particular to the technical field of flow billing. Provided in the present disclosure are flow control and billing methods, apparatuses and system, an electronic device, a medium and a product, which may improve the accuracy of flow control in a high-concurrency scenario. A specific implementation solution is that: a flow control and billing module receives a begin request sent by a proxy service, and judges whether the sum of a current pre-billing amount, and a pre-billed amount and an expended amount corresponding to a user identifier is greater than an available credit so as to obtain a judgment result, wherein, the pre-billed amount corresponding to the user identifier is the sum of current pre-billing amounts of service requests which are being processed and which correspond to the user identifier; and then, whether to respond to a service request is determined on the basis of the judgment result, and the expended amounts corresponding to the user identifier are accumulated on the basis of the response result for the service request.
Description
本申请要求于2022年02月07日提交中国专利局、申请号为202210116365.5发明名称为“一种流控计费方法、装置、系统、电子设备、介质及产品”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese patent application with the application number 202210116365.5 submitted to the China Patent Office on February 07, 2022. The entire contents of which are incorporated by reference in this application.
本公开涉及计算机技术领域,尤其涉及流量计费技术领域。The present disclosure relates to the technical field of computers, and in particular to the technical field of traffic billing.
随着当下互联网人工智能(Artificial Intelligence,AI)技术的不断发展,AI产品形态也日新月异,越来越多的场景具有流控计费(Flow Control and Billing)需求。流控计费,即流量控制与计费,指的是对用户的访问进行控制并计费,也就是根据用户访问所消耗的计费对象情况,允许用户访问或禁止用户访问,并按照用户访问所消耗的计费对象情况进行计费。With the continuous development of the current Internet artificial intelligence (AI) technology, the form of AI products is also changing with each passing day, and more and more scenarios have the demand for flow control and billing (Flow Control and Billing). Flow control billing, that is, flow control and billing, refers to the control and billing of user access, that is, according to the billing objects consumed by user access, allowing users to access or prohibiting user access, and according to user access Billing is carried out according to the consumption of billing objects.
流控计费场景应用非常广泛。例如,当前的流控计费场景包括:AI语音识别流控计费场景、AI语音合成流控计费场景、AI文本翻译字符流控计费场景、AI视频直播审核流控计费场景和手机流量流控计费场景等。Flow control billing scenarios are widely used. For example, the current flow control billing scenarios include: AI voice recognition flow control billing scenarios, AI speech synthesis flow control billing scenarios, AI text translation character flow control billing scenarios, AI video live broadcast review flow control billing scenarios and mobile phone Traffic flow control billing scenarios, etc.
发明内容Contents of the invention
本公开提供了一种流控计费方法、装置、系统、电子设备、介质及产品。The disclosure provides a flow control billing method, device, system, electronic equipment, medium and product.
本公开实施例的第一方面,提供了一种流控计费方法,应用于流控计费模块,包括:The first aspect of the embodiments of the present disclosure provides a flow control and charging method, which is applied to the flow control and charging module, including:
接收代理服务发送的开始begin请求,所述begin请求为所述代理服务在接收到终端发送的业务请求后发送,所述begin请求包括触发所述业务请求的用户标识和处理所述业务请求的本次预计费量;Receiving a start request sent by the proxy service, the begin request is sent by the proxy service after receiving the service request sent by the terminal, the begin request includes the user ID that triggers the service request and the script for processing the service request Estimated amount of fees;
判断所述本次预计费量、所述用户标识对应的已预计费量和已用量的总和是否大于可用额度,得到判断结果;所述用户标识对应的已预计费量为所述用户标识对应的正在被处理的各业务请求的本次预计费量总和;Judging whether the sum of the expected charge amount for this time, the estimated charge amount corresponding to the user identifier, and the used amount is greater than the available amount, and obtain a judgment result; the estimated charge amount corresponding to the user identifier is the amount corresponding to the user identifier The sum of the current estimated cost of each service request being processed;
基于判断结果,确定是否响应所述业务请求,并基于所述业务请求的响应结果累加所述用户标识对应的已用量。Based on the judgment result, determine whether to respond to the service request, and accumulate the used amount corresponding to the user identifier based on the response result of the service request.
本公开实施例的第二方面,提供了一种流控计费方法,应用于代理服务,包括:The second aspect of the embodiments of the present disclosure provides a flow control billing method applied to proxy services, including:
接收终端发送的业务请求,所述业务请求中包括触发所述业务请求的用户标识;receiving a service request sent by a terminal, where the service request includes a user identifier triggering the service request;
确定所述业务请求的本次预计费量;Determining the current estimated fee amount of the business request;
向所述流控计费模块发送携带所述用户标识和所述预计费量的开始begin请求,以使得所述流控计费模块判断所述本次预计费量、所述用户标识对应的已预计费量和已用量的总和是否大于可用额度,得到判断结果,基于判断结果,确定是否响应所述业务请求,并基于所述业务请求的响应结果累加所述用户标识对应的已用量,所述用户标识对应的已预计费量为所述用户标识对应的正在被处理的各业务请求的本次预计费量总和。Sending a begin request carrying the user identifier and the estimated billing amount to the flow control and charging module, so that the flow control and billing module judges the current estimated billing amount and the already charged amount corresponding to the user identifier Whether the sum of the expected fee amount and the used amount is greater than the available amount is obtained to obtain a judgment result, and based on the judgment result, it is determined whether to respond to the service request, and based on the response result of the service request, the used amount corresponding to the user identifier is accumulated, and the The estimated billing amount corresponding to the user ID is the sum of the current estimated billing amounts of the service requests being processed corresponding to the user ID.
本公开实施例的第三方面,提供了一种流控计费装置,应用于流控计费模块,包括:The third aspect of the embodiments of the present disclosure provides a flow control and charging device, which is applied to the flow control and charging module, including:
第一接收模块,用于接收代理服务发送的开始begin请求,所述begin请求为所述代理服务在接收到终端发送的业务请求后发送,所述begin请求包括触发所述业务请求的用户 标识和处理所述业务请求的本次预计费量;The first receiving module is configured to receive a start request sent by the proxy service, the begin request is sent by the proxy service after receiving the service request sent by the terminal, and the begin request includes the user identifier and the user ID that triggered the service request The current estimated fee for processing the business request;
判断模块,用于判断所述本次预计费量、所述用户标识对应的已预计费量和已用量的总和是否大于可用额度,得到判断结果;所述用户标识对应的已预计费量为所述用户标识对应的正在被处理的各业务请求的本次预计费量总和;A judging module, configured to judge whether the sum of the expected billing amount, the estimated billing amount corresponding to the user identifier, and the used amount is greater than the available amount, and obtain a judgment result; the estimated billing amount corresponding to the user identifier is The sum of the current estimated charges for each service request being processed corresponding to the above user ID;
累加模块,用于基于判断模块的判断结果,确定是否响应所述业务请求,并基于所述业务请求的响应结果累加所述用户标识对应的已用量。The accumulation module is configured to determine whether to respond to the service request based on the judgment result of the judgment module, and to accumulate the used amount corresponding to the user identifier based on the response result of the service request.
本公开实施例的第四方面,提供了一种流控计费装置,应用于代理服务,包括:According to the fourth aspect of the embodiments of the present disclosure, a device for flow control and charging is provided, which is applied to proxy services, including:
第二接收模块,用于接收终端发送的业务请求,所述业务请求中包括触发所述业务请求的用户标识;The second receiving module is configured to receive a service request sent by a terminal, where the service request includes a user identifier triggering the service request;
本次预计费量确定模块,用于确定所述业务请求的本次预计费量;The current estimated fee amount determination module is used to determine the current estimated fee amount of the service request;
第二发送模块,用于向所述流控计费模块发送携带所述用户标识和所述预计费量的开始begin请求,以使得所述流控计费模块判断所述本次预计费量、所述用户标识对应的已预计费量和已用量的总和是否大于可用额度,得到判断结果,基于判断结果,确定是否响应所述业务请求,并基于所述业务请求的响应结果累加所述用户标识对应的已用量,所述用户标识对应的已预计费量为所述用户标识对应的正在被处理的各业务请求的本次预计费量总和。The second sending module is configured to send a begin request carrying the user identifier and the expected charge amount to the flow control and charging module, so that the flow control and charge module can judge the current estimate charge amount, Whether the sum of the estimated charge amount and the used amount corresponding to the user identifier is greater than the available amount is obtained as a judgment result, and based on the judgment result, it is determined whether to respond to the service request, and the user identifier is accumulated based on the response result of the service request The corresponding used amount, the estimated billed amount corresponding to the user ID is the sum of the current estimated billed amount of each service request being processed corresponding to the user ID.
本公开实施例的第五方面,提供了一种流控计费系统,包括代理服务、流控计费模块和算子服务;The fifth aspect of the embodiments of the present disclosure provides a flow control and charging system, including a proxy service, a flow control and charging module, and an operator service;
所述流控计费模块,用于执行第一方面中任一项所述的方法;The flow control and billing module is configured to execute the method described in any one of the first aspect;
所述代理服务,用于执行第二方面中任一项所述的方法;The proxy service is used to perform the method described in any one of the second aspect;
所述算子服务,用于处理业务请求。The operator service is used to process business requests.
本公开实施例的第六方面,提供了一种电子设备,包括:According to a sixth aspect of the embodiments of the present disclosure, an electronic device is provided, including:
至少一个处理器;以及at least one processor; and
与所述至少一个处理器通信连接的存储器;其中,a memory communicatively coupled to the at least one processor; wherein,
所述存储器存储有可被所述至少一个处理器执行的指令,所述指令被所述至少一个处理器执行,以使所述至少一个处理器能够执行第一方面或者第二方面中任一项所述的方法。The memory stores instructions executable by the at least one processor, the instructions are executed by the at least one processor, so that the at least one processor can perform any one of the first aspect or the second aspect the method described.
本公开实施例的第七方面,提供了一种存储有计算机指令的非瞬时计算机可读存储介质,其中,所述计算机指令用于使所述计算机执行第一方面或者第二方面中任一项所述的方法。A seventh aspect of the embodiments of the present disclosure provides a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to make the computer execute any one of the first aspect or the second aspect the method described.
本公开实施例的第八方面,提供了一种计算机程序产品,包括计算机程序,所述计算机程序在被处理器执行时实现第一方面或者第二方面中任一项所述的方法。An eighth aspect of the embodiments of the present disclosure provides a computer program product, including a computer program, when the computer program is executed by a processor, the method described in any one of the first aspect or the second aspect is implemented.
应当理解,本部分所描述的内容并非旨在标识本公开的实施例的关键或重要特征,也不用于限制本公开的范围。本公开的其它特征将通过以下的说明书而变得容易理解。It should be understood that what is described in this section is not intended to identify key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will be readily understood through the following description.
为了更清楚地说明本公开实施例和现有技术的技术方案,下面对实施例和现有技术中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本公开的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附 图获得其他的附图。In order to more clearly illustrate the embodiments of the present disclosure and the technical solutions of the prior art, the following briefly introduces the accompanying drawings required in the embodiments and the prior art. Obviously, the accompanying drawings in the following description are only the present invention. For some disclosed embodiments, those skilled in the art can also obtain other drawings based on these drawings without any creative work.
图1是本公开实施例提供的一种流控计费方法的流程图;FIG. 1 is a flowchart of a flow control and billing method provided by an embodiment of the present disclosure;
图2a是相关技术中流控计费过程的示例性示意图;Figure 2a is an exemplary schematic diagram of a flow control charging process in the related art;
图2b是本公开实施例中流控计费过程的示例性示意图;Fig. 2b is an exemplary schematic diagram of a flow control and charging process in an embodiment of the present disclosure;
图3是本公开实施例提供的一种doing心跳刷新方法的流程图;FIG. 3 is a flow chart of a method for refreshing a doing heartbeat provided by an embodiment of the present disclosure;
图4是本公开实施例提供的一种处理定时任务的方法的流程图;FIG. 4 is a flow chart of a method for processing a timed task provided by an embodiment of the present disclosure;
图5是本公开实施例提供的另一种流控计费方法的流程图;FIG. 5 is a flowchart of another flow control and billing method provided by an embodiment of the present disclosure;
图6是本公开实施例提供的另一种doing心跳刷新方法的流程图;FIG. 6 is a flow chart of another doing heartbeat refreshing method provided by an embodiment of the present disclosure;
图7是本公开实施例提供的一种处理begin请求过程的示例性示意图;FIG. 7 is an exemplary schematic diagram of a process of processing a begin request provided by an embodiment of the present disclosure;
图8是本公开实施例提供的一种处理end请求过程的示例性示意图;FIG. 8 is an exemplary schematic diagram of a process of processing an end request provided by an embodiment of the present disclosure;
图9是本公开实施例提供的一种处理doing请求过程的示例性示意图;FIG. 9 is an exemplary schematic diagram of a process of processing a doing request provided by an embodiment of the present disclosure;
图10是本公开实施例提供的一种处理定时任务过程的示例性示意图;FIG. 10 is an exemplary schematic diagram of a process of processing a timed task provided by an embodiment of the present disclosure;
图11是本公开实施例提供的一种流控计费装置的结构示意图;Fig. 11 is a schematic structural diagram of a flow control and billing device provided by an embodiment of the present disclosure;
图12是本公开实施例提供的另一种流控计费装置的结构示意图;Fig. 12 is a schematic structural diagram of another flow control and billing device provided by an embodiment of the present disclosure;
图13是本公开实施例提供的一种流控计费系统的结构示意图;Fig. 13 is a schematic structural diagram of a flow control and billing system provided by an embodiment of the present disclosure;
图14是用来实现本公开实施例的流控计费方法的电子设备的框图。Fig. 14 is a block diagram of an electronic device used to implement the flow control and billing method of the embodiment of the present disclosure.
以下结合附图对本公开的示范性实施例做出说明,其中包括本公开实施例的各种细节以助于理解,应当将它们认为仅仅是示范性的。因此,本领域普通技术人员应当认识到,可以对这里描述的实施例做出各种改变和修改,而不会背离本公开的范围和精神。同样,为了清楚和简明,以下的描述中省略了对公知功能和结构的描述。Exemplary embodiments of the present disclosure are described below in conjunction with the accompanying drawings, which include various details of the embodiments of the present disclosure to facilitate understanding, and they should be regarded as exemplary only. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the disclosure. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
随着当下互联网人工智能(Artificial Intelligence,AI)技术的不断发展,AI产品形态也日新月异,越来越多的场景具有流控计费(Flow Control and Billing)需求。流控计费,即流量控制与计费,指的是对用户的访问进行控制并计费,也就是根据用户访问所消耗的计费对象情况,允许用户访问或禁止用户访问,并按照用户访问所消耗的计费对象情况进行计费。With the continuous development of the current Internet artificial intelligence (AI) technology, the form of AI products is also changing with each passing day, and more and more scenarios have the demand for flow control and billing (Flow Control and Billing). Flow control billing, that is, flow control and billing, refers to the control and billing of user access, that is, according to the billing objects consumed by user access, allowing users to access or prohibiting user access, and according to user access Billing is carried out according to the consumption of billing objects.
流控计费场景应用非常广泛。例如,当前的流控计费场景包括:AI语音识别流控计费场景、AI语音合成流控计费场景、AI文本翻译字符流控计费场景、AI视频直播审核流控计费场景和手机流量流控计费场景等。Flow control billing scenarios are widely used. For example, the current flow control billing scenarios include: AI voice recognition flow control billing scenarios, AI speech synthesis flow control billing scenarios, AI text translation character flow control billing scenarios, AI video live broadcast review flow control billing scenarios and mobile phone Traffic flow control billing scenarios, etc.
不同的流控计费场景下的计费对象不同。例如,搜索功能需要按搜索次数进行流控计费,即计费对象为搜索次数;音视频处理功能需要按音视频的时长进行流控计费,即计费对象为音视频的时长;文本文档处理需要按文档包括的字数进行流控计费,即计费对象为文档包括的字数;手机流量的使用需要按字节流进行流控计费等,即计费对象为字节流。The billing objects are different in different flow control billing scenarios. For example, the search function needs to perform flow control billing according to the number of searches, that is, the billing object is the number of searches; the audio and video processing function needs to perform flow control billing according to the duration of the audio and video, that is, the billing object is the duration of the audio and video; Processing requires flow control billing based on the number of words included in the document, that is, the billing object is the number of words included in the document; the use of mobile phone traffic needs to be billed according to the byte stream, that is, the billing object is the byte stream.
虽然各种场景下的计费对象不同,但各计费对象都可以用数值表示,因此传统的流控计费方式是累加计费对象。Although the billing objects in various scenarios are different, each billing object can be represented by a numerical value, so the traditional flow control billing method is an accumulative billing object.
例如,当计费对象为访问次数时,传统的流控计费方式为:每次接收到用户发送的请求,将访问次数加1,并将当前的访问次数与上限额度进行比较。若达到上限额度,则禁 止访问;否则允许访问,并生成一条访问次数加1的计费数据。其中,该计费数据包括一次访问需要花费的金额。For example, when the billing object is the number of visits, the traditional flow control billing method is: each time a request sent by a user is received, the number of visits is increased by 1, and the current number of visits is compared with the upper limit. If the upper limit is reached, the access is prohibited; otherwise, the access is allowed, and a billing data with the number of visits plus 1 is generated. Wherein, the billing data includes the amount that needs to be spent for one visit.
当计费对象为时长、字数、字节流等非次数的对象时,传统的流控计费方式为:每次接收到用户发送的请求,将计费对象用量加n,并将计费对象用量与上限额度进行比较,其中n为请求消耗的计费对象数量。若达到上限额度,则禁止访问;否则允许访问,并生成一条计费对象用量加n的计费数据。其中,该计费数据包括消耗n个计费对象需要花费的金额。When the billing object is a non-time object such as duration, word count, byte stream, etc., the traditional flow control billing method is: each time a request sent by the user is received, the amount of the billing object is added to n, and the billing object The usage is compared with the upper limit, where n is the number of billing objects consumed by the request. If the upper limit is reached, the access is prohibited; otherwise, the access is allowed, and a billing data of the billing object usage plus n is generated. Wherein, the billing data includes the amount needed to consume n billing objects.
这两种流控计费方式虽然能满足流控计费的基本需求,但是在高并发场景下难以保证流控计费的准确性。这是由于在高并发场景中,受限于网络的抖动以及处理用户发送的请求的算子服务的稳定性,算子服务不是每次处理请求都能处理成功,但算子服务对请求处理失败的情况下,也可能进行了计费,导致计费错误。因此如何避免算子服务处理失败的情况下仍进行计费的问题,是流控计费的难点。Although these two flow control billing methods can meet the basic needs of flow control billing, it is difficult to guarantee the accuracy of flow control billing in high concurrency scenarios. This is because in high-concurrency scenarios, limited by network jitter and the stability of operator services that process requests sent by users, operator services cannot process requests successfully every time, but operator services fail to process requests. In some cases, billing may also be performed, resulting in billing errors. Therefore, how to avoid the problem of billing even when the operator service fails to process is the difficulty of flow control billing.
为了应对该问题,目前有两种解决方案:To deal with this problem, there are currently two solutions:
方案一为先行流控:流控计费模块在接收到用户发送的请求后,预估处理该请求所需消耗的计费对象数量是否满足额度要求,若满足则直接处理请求,并将预估的计费对象数量累加到已用计费对象数量中,并生成计费账单。后续发现用户发送的该请求处理失败时,再进行数据回滚操作,或者删除生成的计费账单。该方案既存在数据累加逻辑又存在数据回滚逻辑,导致整体逻辑复杂,使得流控计费模块的计算压力大,因此难以应用在高并发场景。而且用户可感知到请求处理失败产生的异常账单,因此一般场景均不适用。Solution 1 is pre-emptive flow control: after receiving the request sent by the user, the flow control billing module estimates whether the number of billing objects required to process the request meets the quota requirements, and if so, directly processes the request and sends the estimated The number of billing objects is added to the number of used billing objects, and a bill is generated. When it is found that the processing of the request sent by the user fails, the data rollback operation is performed, or the generated billing bill is deleted. This solution has both data accumulation logic and data rollback logic, resulting in complex overall logic and high computational pressure on the flow control and billing module, so it is difficult to apply to high-concurrency scenarios. Moreover, users can perceive abnormal bills generated by request processing failures, so general scenarios are not applicable.
方案二为后行流控:流控计费模块在接收到用户发送的请求后,判断用户是否为正常可用用户。其中,正常可用用户为已用计费对象数量未超限的用户。若不是正常可用用户,则拒绝该请求。若是正常可用用户,则直接处理请求,之后在请求处理成功后,再将处理请求所消耗的计费对象数量与已用计费对象数量进行累加,并生成计费账单。然后再判断已用计费对象数量是否超过上限额度,若超过,则将该用户设置为无额度不可用用户。若不超过,则保持用户为正常可用用户。该方案只针对已成功处理的请求进行计费,可以避免出现异常账单的情况,但是在高并发场景下,由于后行扣费对计费对象累加具有滞后性,难以做到及时地流量控制,可能产生用户超额使用计费对象的情况。Solution 2 is downstream flow control: after receiving the request sent by the user, the flow control and billing module determines whether the user is a normal available user. Among them, the normally available users are users whose number of used billing objects has not exceeded the limit. If it is not a normally available user, the request is rejected. If it is a normal available user, the request is processed directly, and after the request is successfully processed, the number of billing objects consumed by processing the request is added to the number of billing objects used, and a billing bill is generated. Then judge whether the number of used billing objects exceeds the upper limit, and if so, set the user as an unavailable user without quota. If not, keep the user as a normal available user. This solution only bills for successfully processed requests, which can avoid abnormal bills. However, in high-concurrency scenarios, it is difficult to achieve timely traffic control due to the lag in the accumulation of billing objects due to subsequent deduction. It may happen that the user overuses the billing object.
可见,上述两种方案均不适用于高并发场景。为了在高并发场景下进行准确地流量控制,本公开实施例提供了一种流控计费方法。It can be seen that the above two solutions are not suitable for high concurrency scenarios. In order to perform accurate flow control in a high-concurrency scenario, an embodiment of the present disclosure provides a flow control charging method.
首先对本公开实施例涉及的名词进行说明:First, the nouns involved in the embodiments of the present disclosure are described:
本次预计费量,表示若算子服务处理本次接收到的业务请求,预计需要消耗的计费对象数量。The current estimated billing amount indicates the estimated number of billing objects that will be consumed if the operator service processes the business request received this time.
已预计费量,表示算子服务正在处理的各业务请求的本次预计费量总和。The estimated billing amount indicates the sum of the current estimated billing amount of each business request being processed by the operator service.
实际计费量,表示算子服务处理本次接收到的业务请求实际消耗的计费对象数量。The actual billing amount indicates the number of billing objects actually consumed by the operator service to process the business request received this time.
已成功计费量,表示算子服务处理本次接收到的业务请求的过程中,当前已成功消耗的计费对象数量。The successfully billed amount indicates the number of billing objects that have been successfully consumed during the process of the operator service processing the business request received this time.
可用额度,表示用户可以使用的计费对象数量上限。The available quota indicates the upper limit of the number of billing objects that the user can use.
本公开实施例提供的流控计费方法,可以应用于流控计费模块,如图1所示,该方法包括如下步骤:The flow control billing method provided by the embodiment of the present disclosure can be applied to the flow control billing module, as shown in Figure 1, the method includes the following steps:
S101、接收代理服务发送的开始(begin)请求。S101. Receive a start (begin) request sent by the proxy service.
其中,begin请求为代理服务在接收到终端发送的业务请求后发送,begin请求包括触发业务请求的用户标识和处理业务请求的本次预计费量。Wherein, the begin request is sent by the proxy service after receiving the service request sent by the terminal, and the begin request includes the user identification triggering the service request and the current estimated fee for processing the service request.
一种实现方式中,用户通过终端向代理服务发送业务请求,代理服务接收到业务请求后,从业务请求中提取流量类型。其中,流量类型可以是音视频类型、文本类型或者搜索类型等。然后根据流量类型和计费方式之间的预设对应关系,确定提取的流量类型对应的计费方式。并按照确定的计费方式,确定业务请求的本次预计费量。例如,计费方式为按照时长计费时,将业务请求包括的音视频数据的时长作为本次预计费量;又例如,计费方式为按照次数计费时,将确定本次预计费量为1。然后代理服务生成begin请求,其中,begin请求具体包括:触发业务请求的用户标识、本次预计费量、代理服务与终端之间的会话的会话号(Session Number,SN)、计费方式和计费接口身份标识号(Identity document,id)。之后代理服务向流控计费模块发送begin请求。其中,会话号也可称为会话标识。In one implementation manner, the user sends a service request to the proxy service through the terminal, and the proxy service extracts the traffic type from the service request after receiving the service request. Wherein, the traffic type may be an audio and video type, a text type, or a search type, and the like. Then, according to the preset corresponding relationship between the traffic type and the charging mode, the charging mode corresponding to the extracted traffic type is determined. And according to the determined charging method, determine the current estimated fee amount of the service request. For example, when the billing method is billing according to the duration, the duration of the audio and video data included in the service request is taken as the estimated billing amount for this time; 1. Then the proxy service generates a begin request, wherein the begin request specifically includes: the user ID that triggers the service request, the current estimated billing amount, the session number (Session Number, SN) of the session between the proxy service and the terminal, the charging method and the billing method. The fee interface identity identification number (Identity document, id). Afterwards, the proxy service sends a begin request to the flow control and billing module. Wherein, the session number may also be referred to as a session identifier.
在本公开实施例中,代理服务用于代替流控计费模块与终端交互,以及代替流控计费模块与算子服务交互。其中,算子服务用于处理业务请求。In the embodiment of the present disclosure, the proxy service is used to replace the flow control and billing module to interact with the terminal, and replace the flow control and billing module to interact with the operator service. Among them, the operator service is used to process business requests.
在本公开实施例中,算子服务可以存在多个,不同的算子服务用于实现不同的处理逻辑,计费接口id为调用算子服务的接口id,即每个算子服务对应一个计费接口id,代理服务可以从业务请求中提取计费接口id。In the embodiment of the present disclosure, there may be multiple operator services, and different operator services are used to implement different processing logics. The billing interface id is the interface id for calling operator services, that is, each operator service corresponds to a The billing interface id, the proxy service can extract the billing interface id from the service request.
S102、判断本次预计费量、用户标识对应的已预计费量和已用量的总和是否大于可用额度,得到判断结果。其中,用户标识对应的已预计费量为用户标识对应的正在被处理的各业务请求的本次预计费量总和。S102 , judging whether the sum of the expected billing amount, the estimated billing amount corresponding to the user identifier, and the used amount is greater than the available amount, and a judgment result is obtained. Wherein, the estimated billing amount corresponding to the user ID is the sum of the current estimated billing amounts of the service requests being processed corresponding to the user ID.
由于在高并发场景下,同一个用户可能发送多个业务请求,业务请求可并行处理,而且已用量在业务请求处理成功后才会累计。如果针对每个业务请求,都仅判断该业务请求的本次预计费量与已用量的总和是否超过可用额度,那么在并行处理多个业务请求时,由于业务请求未处理完成,不会累计已用量,使得每个业务请求的本次预计费量与已用量的总和不超过可用额度,各业务请求均会被正常处理。但是在处理完成后,累计已用量时,各业务请求的实际计费量均累加到已用量中,此时已用量可能超过可用额度,导致实际使用额度超限问题。Because in a high-concurrency scenario, the same user may send multiple business requests, the business requests can be processed in parallel, and the usage will not be accumulated until the business requests are successfully processed. If for each business request, it is only judged whether the sum of the expected fee amount and the used amount of the business request exceeds the available quota, then when multiple business requests are processed in parallel, because the business requests have not been processed, the accumulated amount will not be accumulated. usage, so that the sum of the expected charge amount and the used amount of each business request does not exceed the available quota, and each business request will be processed normally. However, after the processing is completed, when accumulating the used amount, the actual billing amount of each business request is added to the used amount. At this time, the used amount may exceed the available quota, resulting in the problem of exceeding the actual usage quota.
因此,本公开实施例中,针对每个业务请求,判断处理该业务请求的预计费量、正在处理的该用户的其他业务请求所需消耗的已预计费量以及该用户的已用量的总和是否超过可用额度,该方式下,即使同时处理的各业务请求均处理成功,累加已用量时,也不会导致已用量超过可用额度,从而减少实际使用额度超限的问题。Therefore, in the embodiment of the present disclosure, for each service request, it is judged whether the sum of the estimated charge amount for processing the service request, the estimated charge amount consumed by the user’s other service requests being processed, and the user’s used amount is Exceeding the available quota, in this way, even if all business requests processed at the same time are successfully processed, when the used amount is accumulated, the used amount will not exceed the available quota, thereby reducing the problem of the actual usage quota exceeding the limit.
例如,假设按照次数计费,一个用户发送两个业务请求,该用户的可用额度为5,已用量为4,流控计费模块接收到第一个请求时,正常处理。但接收到第二个请求时,如果第一个请求正在处理,此时未累加已用量,使得已用量仍为4,那么对于第二个请求,仍利用本次预计费量1与已用量4的总和与可用额度5比较,得到不超过可用额度的结果, 使得第二个请求也会被处理。但是如果这两个请求均处理成功,则已用量累加到6,超过可用额度。For example, assuming billing by the number of times, a user sends two service requests, the user's available quota is 5, and the used quota is 4. When the flow control billing module receives the first request, it will process it normally. But when the second request is received, if the first request is being processed and the used amount is not accumulated at this time, so that the used amount is still 4, then for the second request, the estimated amount of 1 and the used amount of 4 are still used The sum of is compared with the available quota 5, and the result of not exceeding the available quota is obtained, so that the second request will also be processed. But if the two requests are processed successfully, the accumulated amount will be 6, exceeding the available quota.
而本公开实施例中,流控计费模块接收到第一个请求时,正常处理。接收到第二个请求时,如果第一个请求正在处理,那么已预计量为1,此时判断本次预计费量1、已预计费量1和已用量4的总和是否超过可用额度5,得到超过可用额度的结果,使得第二个请求不会被处理。从而减少高并发场景下对计费对象的超额使用的问题。However, in the embodiment of the present disclosure, when the flow control and billing module receives the first request, it processes it normally. When the second request is received, if the first request is being processed, the estimated amount is 1. At this time, it is judged whether the sum of the estimated amount 1, the estimated amount 1, and the used amount 4 exceeds the available amount 5, A result that exceeds the available quota causes the second request to not be processed. In this way, the problem of excessive usage of billing objects in high concurrency scenarios can be reduced.
S103、基于判断结果,确定是否响应业务请求,并基于业务请求的响应结果累加用户标识对应的已用量。S103. Determine whether to respond to the service request based on the judgment result, and accumulate the used amount corresponding to the user identifier based on the response result of the service request.
一种实现方式中,在判断结果为是时,确定拒绝终端的业务请求,并对用户标识对应的已用量累加0,即对用户标识对应的已用量保持不变。在判断结果为否时,确定响应终端的业务请求,并按照业务请求的处理情况累加用户标识对应的已用量。In an implementation manner, when the judgment result is yes, it is determined to reject the service request of the terminal, and 0 is added to the used amount corresponding to the user identifier, that is, the used amount corresponding to the user identifier remains unchanged. When the judgment result is no, it is determined to respond to the service request of the terminal, and the used amount corresponding to the user identifier is accumulated according to the processing situation of the service request.
如图2a所示,传统的流控计费方案采用直路策略,即流控计费模块负责接收用户发送的业务请求,并调用算子服务处理业务请求,将处理结果返回给用户,同时还需要进行流量控制和计费。可见这种方式中,流控计费模块负责的处理逻辑较多,因此所承载的处理压力较大,在高并发场景下随着流量压力的增大,难以保障流控计费模块的稳定性。As shown in Figure 2a, the traditional flow control billing scheme adopts the straight-line strategy, that is, the flow control billing module is responsible for receiving service requests sent by users, calling operator services to process service requests, and returning the processing results to users. Perform flow control and billing. It can be seen that in this method, the flow control and billing module is responsible for more processing logic, so the processing pressure it bears is relatively high. In high concurrency scenarios, as the traffic pressure increases, it is difficult to guarantee the stability of the flow control and billing module. .
由图1所示的方法可以看出,本公开实施例将流量收发和流控计费分离,即如图2b所示,本公开实施例增加了代理服务,由代理服务代替流控计费模块与终端和算子服务交互,即由代理服务负责简单的逻辑处理,不做复杂的逻辑计算。由流控计费模块负责流量控制和计费。由于本公开实施例减少了流控计费模块的处理逻辑,即减少了流控计费模块承载的压力,从而能够适用于高并发场景。It can be seen from the method shown in FIG. 1 that the embodiment of the present disclosure separates traffic sending and receiving from flow control and charging, that is, as shown in FIG. 2b, the embodiment of the present disclosure adds a proxy service, and the proxy service replaces the flow control and charging module Interact with terminals and operator services, that is, the proxy service is responsible for simple logic processing and does not perform complex logic calculations. The flow control and billing module is responsible for flow control and billing. Since the embodiment of the present disclosure reduces the processing logic of the flow control and charging module, that is, reduces the pressure carried by the flow control and charging module, it is applicable to high concurrency scenarios.
而且,在本公开实施例中,流控计费模块在处理业务请求之前,先判断本次预计费量、用户标识对应的已预计费量和已用量的总和是否大于可用额度,即判断处理业务请求是否会产生超额的问题,此时并未直接累加可用额度,而是后续根据业务请求的响应结果累加可用额度。因此即使业务请求处理失败,也不需要进行数据回滚或删除,即解决了先行流控的过早计费所造成的需要数据回滚或删除的问题。此外,由于本公开实施例在处理业务请求之前,先判断处理业务请求是否会产生超额问题,因此解决了后行流控超额判定的滞后性,从而能够适用于高并发场景。Moreover, in the embodiment of the present disclosure, before processing the service request, the flow control and billing module first judges whether the sum of the expected billing amount, the estimated billing amount and the used amount corresponding to the user ID is greater than the available amount, that is, judges whether the processing business The question of whether the request will cause excess, at this time, the available quota is not directly accumulated, but the available quota is subsequently accumulated according to the response result of the business request. Therefore, even if the service request fails to be processed, there is no need to perform data rollback or deletion, which solves the problem of data rollback or deletion caused by premature billing in advance flow control. In addition, because the embodiment of the present disclosure first judges whether processing a business request will cause an overage problem before processing the business request, it solves the hysteresis of subsequent flow control oversubscription determination, and thus can be applied to high concurrency scenarios.
在本公开的一个实施例中,上述S103基于判断结果,确定是否响应业务请求,并基于业务请求的响应结果累加用户标识对应的已用量的方式,包括以下步骤:In an embodiment of the present disclosure, the above-mentioned S103 determines whether to respond to the service request based on the judgment result, and accumulates the used amount corresponding to the user ID based on the response result of the service request, including the following steps:
步骤一、若判断结果为是,则流控计费模块向代理服务发送begin失败响应,以使得代理服务向终端发送请求失败响应。Step 1. If the judgment result is yes, the flow control and billing module sends a begin failure response to the proxy service, so that the proxy service sends a request failure response to the terminal.
当本次预计费量、用户标识对应的已预计费量和已用量的总和大于可用额度,说明该用户当前正在被处理的业务请求如果均处理成功,可用额度与累加后的已预计量之间的差额小于本次预计费量,即处理用户当前发送的业务请求可能导致已用额度超限,因此拒绝该业务请求,向终端反馈请求失败。When the sum of the estimated billing amount, the estimated billing amount corresponding to the user ID, and the used amount is greater than the available amount, it means that if all the service requests currently being processed by the user are successfully processed, the difference between the available amount and the accumulated estimated amount The difference is less than the expected fee amount for this time, that is, processing the service request currently sent by the user may cause the used quota to exceed the limit, so the service request is rejected and the request failure is reported to the terminal.
步骤二、若判断结果为否,则流控计费模块将本次预计费量加入用户标识对应的已预计费量,并向代理服务发送begin成功响应,以使得代理服务调用算子服务处理业务请求, 并在确定算子服务处理完成时向流控计费模块发送结束(end)请求。其中,end请求包括处理业务请求所消耗的实际计费量。Step 2. If the judgment result is no, the flow control and billing module will add the estimated billing amount to the estimated billing amount corresponding to the user ID, and send a begin success response to the proxy service, so that the proxy service calls the operator service to process the business request, and send an end (end) request to the flow control and billing module when it is determined that the operator service processing is completed. Wherein, the end request includes the actual billing amount consumed by processing the service request.
在本公开实施例中,已预计费量表示算子服务正在处理的各业务请求的本次预计费量总和,若本次预计费量、用户标识对应的已预计费量和已用量的总和不大于可用额度,说明该用户当前正在被处理的业务请求如果均处理成功,可用额度与累加后的已预计费量之间的差额仍然大于等于本次预计费量,即处理用户当前发送的业务请求不会使得已用额度超限,因此可以处理接收到的业务请求。由于此时已判断出可以处理业务请求,业务请求即将被转发至算子服务处理,因此需要将该业务请求的本次预计费量累加到已预计费量中。In the embodiments of the present disclosure, the estimated billing amount represents the sum of the current estimated billing amount of each service request being processed by the operator service. If the sum of the current estimated billing amount, the estimated billing amount and the used amount If it is greater than the available quota, it means that if all the business requests currently being processed by the user are successfully processed, the difference between the available quota and the accumulated estimated billing amount is still greater than or equal to the estimated billing amount of this time, that is, the business request currently sent by the user is processed The used quota will not be exceeded, so the received service request can be processed. Since it has been judged that the business request can be processed at this time, and the business request is about to be forwarded to the operator service for processing, it is necessary to add the current estimated fee amount of the business request to the estimated fee amount.
其中,流控计费模块针对begin请求的响应中可以包括状态标记,用于表示begin请求是否成功,方便代理服务通过该状态标记识别begin请求是否成功。例如,状态标记为1时表示begin请求成功,此时的响应称为begin成功响应;状态标记为0时表示begin请求失败,此时的响应称为begin失败响应。Wherein, the response of the flow control and accounting module to the begin request may include a status flag, which is used to indicate whether the begin request is successful, so that the proxy service can identify whether the begin request is successful through the status flag. For example, when the status flag is 1, it means that the begin request is successful, and the response at this time is called a begin success response; when the status flag is 0, it means that the begin request fails, and the response at this time is called a begin failure response.
代理服务接收到begin成功响应时,向算子服务转发接收到的业务请求,由算子服务处理业务请求,并向代理服务转发处理结果。其中,处理结果具体包括对业务请求的响应结果以及处理业务请求所消耗的实际计费量。代理服务接收到算子服务的处理结果时,确定算子服务处理完成,并向流控计费模块发送end请求。而且,代理服务在接收到算子服务的处理结果时,还可以向终端反馈对业务请求的响应结果。When the proxy service receives a successful response from begin, it forwards the received business request to the operator service, and the operator service processes the business request and forwards the processing result to the proxy service. Wherein, the processing result specifically includes the response result to the service request and the actual billing amount consumed for processing the service request. When the proxy service receives the processing result of the operator service, it determines that the processing of the operator service is completed, and sends an end request to the flow control and billing module. Moreover, when the proxy service receives the processing result of the operator service, it can also feed back the response result to the business request to the terminal.
步骤三、流控计费模块接收代理服务发送的end请求,将实际计费量累加到用户标识对应的已用量中,并从用户标识对应的已预计费量中删除本次预计费量。Step 3: The flow control and billing module receives the end request sent by the proxy service, adds the actual billed amount to the used amount corresponding to the user ID, and deletes the current estimated billed amount from the estimated billed amount corresponding to the user ID.
当流控计费模块接收到end请求时,表示算子服务当前已对业务请求处理完成,因此实际计费量需要累加到该用户的已用量中。同时,由于该业务请求已经处理完成,因此需要从该用户的已预计费量中删除本次预计费量。When the flow control and billing module receives the end request, it means that the operator service has completed processing the business request, so the actual billing amount needs to be added to the user's used amount. At the same time, since the service request has been processed, it is necessary to delete the current estimated amount from the user's estimated amount.
采用上述方法,本公开实施例中,流控计费模块在处理业务请求之前,先基于本次预计费量进行流量控制,且本次预计费量没有直接累加到已用量中,而是在业务请求处理完成之后,才将实际计费量累加到已用量中。即本公开实施例结合了先行流控和后行流控,且先行流控时没有累加已用量,因此即使业务请求处理失败,也不需要进行数据回滚或删除,即解决了先行流控的过早计费所造成的需要数据回滚或删除的问题。后行流控可以按照请求处理成功时所消耗的实际计费量进行已用量的累加,而且在后行流控之前进行了先行流控,而先行流控可以减少流量超额使用的情况,即在准确地进行流量控制的基础上,解决了后行流控容易导致流量超额使用的问题。因此本公开实施例能够在高并发场景下进行准确地流量控制。Using the above method, in the embodiment of the present disclosure, before processing the service request, the flow control and billing module performs flow control based on the current estimated fee amount, and the current estimated fee amount is not directly added to the used amount, but is added to the service The actual billed amount will be added to the used amount only after the request processing is completed. That is to say, the embodiment of the present disclosure combines proactive flow control and backward flow control, and there is no accumulated used amount during proactive flow control, so even if the service request processing fails, there is no need to perform data rollback or deletion, which solves the problem of proactive flow control Problems caused by premature billing that require data rollback or deletion. Subsequent flow control can accumulate the used amount according to the actual billing amount consumed when the request is processed successfully, and pre-emptive flow control is performed before post-traffic flow control, and pre-emptive flow control can reduce traffic overuse, that is, in On the basis of accurate flow control, it solves the problem that subsequent flow control easily leads to excessive use of flow. Therefore, the embodiments of the present disclosure can perform accurate flow control in high concurrency scenarios.
在本公开的一个实施例中,由于算子服务对业务请求可能处理成功,也可能处理失败。而无论处理成功还是失败,都可以统计算子服务处理业务请求的过程中所实际消耗的计费量,以便后续对算子服务的处理结果进行分析统计。因此,无论算子服务是否处理成功,处理结果中都可以包括处理业务请求所消耗的实际计费量。而为了让流控计费模块区分算子服务是否处理成功,从而将处理成功的业务请求的实际计费量累加到已用量中,避免将处理失败的业务请求的实际计费量累加到已用量中,需要对业务请求处理成功时的实际计 费量和业务请求处理失败时的实际计费量进行区分。本公开实施例设置了状态码(status_code),状态码用于表示业务请求是否处理成功。代理服务可以从算子服务针对业务请求反馈的处理结果中提取状态码,并生成包括状态码的end请求。In an embodiment of the present disclosure, because the operator service may successfully process the service request, it may also fail to process it. Regardless of whether the processing succeeds or fails, the billing amount actually consumed by the computing sub-service in the process of processing the business request can be counted, so that the subsequent analysis and statistics of the processing results of the computing sub-service can be performed. Therefore, no matter whether the operator service is processed successfully or not, the processing result can include the actual billing amount consumed by processing the service request. In order for the flow control billing module to distinguish whether the operator service is successfully processed, the actual billing amount of the successfully processed business request is added to the used amount, and the actual billing amount of the failed business request is not added to the used amount. In , it is necessary to distinguish between the actual billing amount when the service request is processed successfully and the actual billing amount when the service request fails to be processed. The embodiment of the present disclosure sets a status code (status_code), which is used to indicate whether the service request is processed successfully. The proxy service can extract the status code from the processing result fed back by the operator service for the business request, and generate an end request including the status code.
因此,流控计费模块在接收到end请求后,需要判断是否需要累加实际计费量,包括以下步骤:判断end请求中的状态码是否表示业务请求处理成功,其中,end请求包括状态码。若否,则确定处理业务请求所消耗的实际计费量为0,并保持用户标识对应的已用量不变。若是,则从end请求中获取实际计费量,并执行步骤三中将实际计费量累加到用户标识对应的已用量中的步骤。Therefore, after receiving the end request, the flow control and billing module needs to judge whether the actual charging amount needs to be accumulated, including the following steps: judging whether the status code in the end request indicates that the service request is processed successfully, wherein the end request includes the status code. If not, it is determined that the actual charging amount consumed for processing the service request is 0, and the used amount corresponding to the user identifier remains unchanged. If yes, obtain the actual billing amount from the end request, and perform the step of adding the actual billing amount to the used amount corresponding to the user ID in step 3.
例如,当状态码为-1时,表示算子服务内部错误,即业务请求处理失败;当状态码为0时,表示算子服务对业务请求的计算正常,即业务请求处理成功。For example, when the status code is -1, it means that there is an internal error in the operator service, that is, the business request processing failed; when the status code is 0, it means that the calculation of the business request by the operator service is normal, that is, the business request is processed successfully.
本公开实施例中,通过状态码区分业务请求是否处理成功,从而使得流控计费模块能够通过状态码,区分实际计费量是否需要累加到已用量中。而且无论业务请求是否处理成功,end请求中均可以包括实际计费量,使得流控计费模块能够存储各业务请求的实际计费量,方便后续进行统计分析。In the embodiment of the present disclosure, the status code is used to distinguish whether the service request is successfully processed, so that the flow control and charging module can use the status code to distinguish whether the actual charging amount needs to be added to the used amount. And no matter whether the service request is processed successfully, the end request can include the actual billing amount, so that the flow control billing module can store the actual billing amount of each service request, which is convenient for subsequent statistical analysis.
在本公开的一个实施例中,由于代理服务与流控计费模块之间的通信可能存在不稳定的情况,如果流控计费模块接收到至少两次代理服务针对同一个业务请求发送的end请求,那么流控计费模块可能错误地将end请求中的实际计费量连续多次累加到已用量中,导致计费错误的情况。In one embodiment of the present disclosure, since the communication between the proxy service and the flow control and billing module may be unstable, if the flow control and billing module receives at least two end request, the flow control billing module may mistakenly add the actual billed amount in the end request to the used amount for multiple consecutive times, resulting in billing errors.
为了减少这种错误,本公开实施例设置了begin请求和end请求中均包括代理服务与终端之间的会话的会话标识。In order to reduce such errors, in the embodiment of the present disclosure, both the begin request and the end request include the session identifier of the session between the proxy service and the terminal.
因此在S102判断本次预计费量、用户标识对应的已预计费量和已用量的总和是否大于可用额度之前,流控计费模块还可以记录begin请求中的会话标识。Therefore, before S102 judges whether the sum of the expected charge amount, the estimated charge amount corresponding to the user ID, and the used amount is greater than the available amount, the flow control and billing module can also record the session ID in the begin request.
具体的,流控计费模块在接收到begin请求后,可以对begin请求进行数据解析及预处理,包括:从begin请求提取触发业务请求的用户标识、本次预计费量、SN、计费方式和计费接口id等数据,并将提取的各项数据对应存储。本公开实施例将从begin请求中提取的数据、已预计费量、已成功计费量、实际计费量和已用量统称为计费数据。Specifically, after receiving the begin request, the flow control billing module can perform data analysis and preprocessing on the begin request, including: extracting from the begin request the user ID that triggers the service request, the expected charge amount, SN, and billing method and billing interface id and other data, and store the extracted data correspondingly. In the embodiments of the present disclosure, the data extracted from the begin request, the estimated billing amount, the successfully billed amount, the actual billed amount, and the used amount are collectively referred to as billing data.
可选的,流控计费模块可以将计费数据存储在分布式远程字典服务(Remote Dictionary Server,Redis)中,其中,分布式Redis中包括多个分片,流控计费模块可以基于用户标识,将同一个用户的计费数据存储在分布式Redis的同一个分片中。这使得流控计费模块在查找计费数据时,方便从同一个分片中查找同一个用户的计费数据,相比于从多个分片中查找同一个用户的计费数据的方式,本公开实施例能够提高查找效率,从而更适用于高并发场景。Optionally, the flow control and billing module can store the billing data in a distributed remote dictionary service (Remote Dictionary Server, Redis), wherein the distributed Redis includes multiple fragments, and the flow control and billing module can be based on user ID, and store the billing data of the same user in the same shard of distributed Redis. This makes it convenient for the flow control billing module to find the billing data of the same user from the same shard when looking for billing data. Compared with the method of finding the billing data of the same user from multiple shards, The embodiments of the present disclosure can improve search efficiency, and thus are more suitable for high concurrency scenarios.
在S102判断本次预计费量、用户标识对应的已预计费量和已用量的总和是否大于可用额度之后,流控计费模块还可以在判断结果为是时,删除记录的会话标识。可以理解的,由于流控计费模块在判断出本次预计费量、用户标识对应的已预计费量和已用量的总和大于可用额度时,向代理服务返回begin失败响应,此时业务请求不会被处理,因此删除记录的该会话标识。After S102 judges whether the sum of the expected billing amount, the estimated billing amount corresponding to the user ID, and the used amount is greater than the available amount, the flow control and billing module may also delete the recorded session ID when the judgment result is yes. Understandably, since the flow control billing module judges that the sum of the expected billing amount, the estimated amount corresponding to the user ID, and the used amount is greater than the available amount, it returns a begin failure response to the proxy service. At this time, the business request does not will be processed, so delete the recorded session id.
在步骤三将实际计费量累加到用户标识对应的已用量中之前,流控计费模块还可以查询是否已记录end请求中的会话标识;若是,则删除记录的会话标识;若否,则忽略end请求。Before step 3 adds the actual billing amount to the used amount corresponding to the user ID, the flow control billing module can also inquire whether the session ID in the end request has been recorded; if so, delete the recorded session ID; if not, then End requests are ignored.
可以理解的,当流控计费模块接收到end请求后,如果未记录end请求包括的会话标识,说明该会话标识对应的业务请求未被处理或者已处理结束,因此可以忽略该end请求。如果记录有end请求包括的会话标识,说明该会话标识对应的业务请求目前处理完成,需要进行计费,因此流控计费模块将实际计费量累加到用户标识对应的已用量中的同时,删除会话标识,避免后续对该会话标识对应的业务请求重复计费。It can be understood that when the flow control and billing module receives the end request, if the session identifier included in the end request is not recorded, it means that the service request corresponding to the session identifier has not been processed or has been processed, so the end request can be ignored. If the session ID included in the end request is recorded, it means that the service request corresponding to the session ID is currently processed and needs to be billed. Therefore, the flow control billing module will add the actual billing amount to the used amount corresponding to the user ID. Delete the session ID to avoid repeated charging for subsequent service requests corresponding to the session ID.
采用上述方法,流控计费模块通过会话标识,识别会话标识对应的业务请求的处理情况,从而减少对已处理结束的业务请求重复计费的情况。Using the above method, the flow control and charging module identifies the processing status of the service request corresponding to the session ID through the session ID, thereby reducing the situation of repeated charging for the service request that has been processed.
在本公开的一个实施例中,为了进一步提升流控计费的准确性,本公开实施例基于长会话要求,在结合先行流控和后行流控的基础上,在begin请求和end请求之间增加doing心跳刷新。如图3所示,流控计费模块在上述步骤二中向代理服务发送begin成功响应之后,且在步骤三接收end请求之前,还可以执行以下步骤:In one embodiment of the present disclosure, in order to further improve the accuracy of flow control and billing, the embodiment of the present disclosure is based on the requirements of long sessions, and on the basis of combining pre-flow control and post-flow control, between the begin request and the end request Increase the refreshing of doing heartbeats. As shown in Figure 3, after the flow control and billing module sends a begin success response to the proxy service in the above step 2, and before receiving the end request in step 3, it can also perform the following steps:
S301、接收代理服务发送的处理中(doing)请求。其中,doing请求包括算子服务当前处理业务请求所消耗的已成功计费量。S301. Receive a processing (doing) request sent by the proxy service. Among them, the doing request includes the successfully billed amount consumed by the operator service currently processing the business request.
一种实现方式中,代理服务可以从算子服务中实时获取处理业务请求所消耗的已成功计费量,并周期性地向流控计费模块发送doing请求,以使得流控计费模块及时获得当前的已成功计费量。In one implementation, the proxy service can obtain the successfully billed amount consumed by processing business requests in real time from the operator service, and periodically send a doing request to the flow control and billing module, so that the flow control and billing module can timely Get the current successfully billed amount.
S302、从doing请求中获取已成功计费量,将用户标识对应的已预计费量中的本次预计费量更新为获取的已成功计费量,并判断当前的已预计费量与用户标识对应的已用量的总和是否大于可用额度。若否,则执行S303;若是,则执行S304。S302. Obtain the successfully billed amount from the doing request, update the current estimated billed amount in the estimated billed amount corresponding to the user ID to the obtained successfully billed amount, and determine the current estimated billed amount and the user ID Whether the sum of the corresponding used amount is greater than the available amount. If not, execute S303; if yes, execute S304.
由于首次确定的本次预计费量是对处理业务请求预估的计费量,并不是真实的计费量,而已成功计费量是处理业务请求所消耗的真实的计费量,因此流控计费模块获取到已成功计费量时,可以将本次预计费量更新为已成功计费量,从而基于真实的计费量进行流量控制。且后续继续接收到doing请求时,可以再将本次预计费量更新为最新接收到的doing请求中包括的已成功计费量,从而实时地根据真实的计费量进行流量控制。Since the estimated billing amount determined for the first time is the estimated billing amount for processing business requests, not the real billing amount, and the successful billing amount is the real billing amount consumed by processing business requests, so flow control When the billing module obtains the successfully billed amount, it can update the estimated billed amount to the successfully billed amount, so as to perform traffic control based on the real billed amount. And when the doing request is continuously received subsequently, the current estimated billing amount can be updated to the successfully billed amount included in the latest received doing request, so that flow control can be performed in real time according to the real billing amount.
即流控计费模块中记录的本次预计量为begin请求包括的预计费量,或者最新接收到的doing请求中包括的已成功计费量。That is, the current estimated amount recorded in the flow control billing module is the estimated amount included in the begin request, or the successfully billed amount included in the latest received doing request.
S303、向代理服务发送doing成功响应,以使得代理服务在确定算子服务处理完成时向流控计费模块发送end请求。其中end请求包括的实际计费量为算子服务对业务请求从开始处理到处理完成时总共消耗的计费量。S303. Send a doing success response to the proxy service, so that the proxy service sends an end request to the flow control and charging module when it is determined that the processing of the operator service is completed. The actual billing amount included in the end request is the total billing amount consumed by the operator service from the start of processing the business request to the completion of the processing.
其中,流控计费模块针对doing请求的响应中可以包括doing状态标记,用于表示doing请求是否成功,方便代理服务通过doing状态标记识别doing请求是否成功。例如,流控计费模块针对doing请求向代理服务发送的响应中,如果doing状态标记为1,则表示doing请求成功,此时该响应称为doing成功响应;如果doing状态标记为0,则表示doing请求失败,此时该响应称为doing失败响应。Wherein, the response of the flow control and billing module to the doing request may include a doing status flag, which is used to indicate whether the doing request is successful, so that the proxy service can identify whether the doing request is successful through the doing status flag. For example, in the response sent by the flow control and accounting module to the proxy service for the doing request, if the doing status flag is 1, it means that the doing request is successful, and the response is called a doing success response; if the doing status flag is 0, it means If the doing request fails, the response is called a doing failure response.
代理服务接收到doing成功响应时,表示当前处理业务请求还未出现超额问题,因此可以保持业务请求继续执行。When the proxy service receives a successful response of doing, it means that there is no overrun problem in the current processing of business requests, so the business requests can continue to be executed.
S304、向代理服务发送doing失败响应,以使得代理服务终止算子服务处理业务请求,并确定实际计费量为算子服务当前处理业务请求所消耗的已成功计费量,并发送携带确定的实际计费量的end请求。S304. Send a doing failure response to the proxy service, so that the proxy service terminates the operator service to process the business request, and determines that the actual billing amount is the successfully billed amount consumed by the operator service currently processing the business request, and sends the determined The end request of the actual billing amount.
代理服务接收到doing失败响应时,表示当前处理业务请求已出现了超额问题,需要终止处理业务请求,因此代理服务可以向算子服务发送终止通知消息,以使得算子服务停止处理业务请求,并将停止处理业务请求时,当前处理业务请求消耗的已成功计费量发送至代理服务。代理服务基于表示业务请求处理失败的状态码、以及接收到的已成功计费量,生成end请求,并向流控计费模块发送end请求。When the proxy service receives a doing failure response, it means that the current processing business request has exceeded the limit and needs to stop processing the business request. Therefore, the proxy service can send a termination notification message to the operator service, so that the operator service stops processing the business request, and When the processing of the business request is stopped, the successfully billed amount consumed by the current processing of the business request is sent to the proxy service. The proxy service generates an end request based on the status code indicating that the business request processing failed and the received successful billing amount, and sends the end request to the flow control billing module.
流控计费模块接收到end请求后,按照上述步骤三中的相关步骤进行流量控制和计费。After receiving the end request, the flow control and billing module performs flow control and billing according to the relevant steps in the above step 3.
采用上述方法,流控计费模块可以通过doing心跳机制,实时获取到算子服务处理业务请求的已成功计费量,而已成功计费量为真实的使用量,因此流量计费模块可以实时的根据真实使用量进行流量控制和计费。Using the above method, the flow control billing module can obtain the successfully billed amount of the operator service processing business request in real time through the doing heartbeat mechanism, and the successful billed amount is the real usage, so the traffic billing module can real-time Traffic control and billing are performed based on actual usage.
需要说明的是,代理服务在发送doing请求之前,还可以判断计费方式是否为按照次数计费。当计费方式为按照次数计费时,终端与代理服务之间的会话为短连接会话,此时可以不执行图3所示的doing心跳机制,或者,在执行doing心跳机制时,设置算子服务向代理服务每次传输的已成功计费量为1。It should be noted that before the proxy service sends the doing request, it can also determine whether the billing method is billing by the number of times. When the billing method is billing according to the number of times, the session between the terminal and the proxy service is a short connection session. At this time, the doing heartbeat mechanism shown in Figure 3 may not be executed, or, when the doing heartbeat mechanism is executed, the operator is set The service is billed 1 per successful transfer to the proxy service.
相反的,当计费方式不为按照次数计费时,终端与代理服务之间的会话一般为长连接会话,因此可以执行图3所示的doing心跳机制。On the contrary, when the billing method is not billing according to the number of times, the session between the terminal and the proxy service is generally a long connection session, so the doing heartbeat mechanism shown in FIG. 3 can be implemented.
在本公开的一个实施例中,由于算子服务开始处理业务请求时,已成功计费量较少,随着处理时长的增加,已成功计费量也会增加。因此流控计费模块在业务请求的处理前期接收到的已成功计费量较小,为了减少由于业务请求的本次预计费量小于实际所需计费量而导致的超额使用问题,还可以在已成功计费量较小时,暂不更新本次预计费量。即流控计费模块在S302从doing请求中获取已成功计费量之后,还可以执行以下步骤:In an embodiment of the present disclosure, since the operator service starts to process the business request, the amount of successful billing is small, and the amount of successful billing increases as the processing time increases. Therefore, the successful billing amount received by the flow control billing module in the early stage of business request processing is relatively small. When the successfully billed amount is small, the current estimated billing amount will not be updated for the time being. That is, after the flow control and billing module obtains the successfully billed amount from the doing request in S302, it can also perform the following steps:
判断已成功计费量是否大于本次预计费量。若是,则执行S302中将用户标识对应的已预计费量中的本次预计费量更新为获取的已成功计费量的步骤。若否,则保持已预计费量不变,并执行S302中判断当前的已预计费量与用户标识对应的已用量的总和是否大于可用额度的步骤。Determine whether the successfully billed amount is greater than the current estimated billing amount. If yes, execute the step of updating the estimated billing amount for this time among the estimated billing amounts corresponding to the user identifier in S302 to the obtained successfully billed amount. If not, keep the estimated billing amount unchanged, and execute the step of judging whether the sum of the current estimated billing amount and the used amount corresponding to the user identifier is greater than the available quota in S302.
采用上述方法,流控计费模块在已成功计费量小于等于本次预计费量时,暂不更新本次预计费量,即在已成功计费量较小时,不更新本次预计费量。如果已预计费量中的本次预计费量较小,可能导致当前基于已预计费量进行流量控制不准确,从而导致超额使用问题。因此本公开实施例在已成功计费量大于本次预计费量时,才将已预计费量中的本次预计费量更新为已成功计费量,减少超额使用的问题。而且业务请求的实际计费量可能大于本次预计费量,因此在已成功计费量大于本次预计费量时,对本次预计费量进行及时更新,也能减少预估的本次预计费量小于实际计费量而导致的超额使用问题。Using the above method, the flow control billing module does not update the estimated billing amount for the time being when the successful billing amount is less than or equal to the estimated billing amount, that is, does not update the estimated billing amount when the successful billing amount is small . If the current estimated charge amount in the estimated charge amount is small, the current flow control based on the estimated charge amount may be inaccurate, resulting in an overuse problem. Therefore, in the embodiment of the present disclosure, when the successfully billed amount is greater than the current estimated billed amount, the current estimated billed amount in the estimated billed amount is updated to the successfully billed amount, so as to reduce the problem of overuse. Moreover, the actual billing amount of the business request may be greater than the estimated billing amount of this time. Therefore, when the successful billing amount is greater than the estimated billing amount of this time, updating the estimated billing amount of this time in time can also reduce the estimated amount of this time. The problem of excess usage caused by the billed amount being less than the actual billed amount.
在本公开的一个实施例中,由于网络或其他问题可能导致代理服务发送的end请求丢 失,流控计费模块如果没有接收到end请求,则会一直保存通过begin请求获取的本次预计费量,而且也无法对业务请求进行正确地计费。In one embodiment of the present disclosure, the end request sent by the proxy service may be lost due to network or other problems. If the flow control and billing module does not receive the end request, it will always save the current estimated billing amount obtained through the begin request. , and it is also impossible to correctly charge the service request.
为了解决该问题,本公开实施例中在流控计费模块中设置定时垃圾回收(Garbage Collection,GC)任务,如图4所示,流控计费模块还可以执行以下步骤:In order to solve this problem, in the embodiment of the present disclosure, a scheduled garbage collection (Garbage Collection, GC) task is set in the flow control billing module, as shown in Figure 4, the flow control billing module can also perform the following steps:
S401、若持续预设时长未接收到doing请求或者end请求,则判断是否获取过doing请求中携带的已成功计费量。若是,则执行S402;若否,则执行S403。S401. If a doing request or an end request is not received for a preset duration, judge whether the successfully billed amount carried in the doing request has been obtained. If yes, execute S402; if not, execute S403.
一种实现方式中,在上一次接收到begin请求或者doing请求开始,如果持续预设时长仍未接收到doing请求或者end请求,可以认为会话异常结束。此时可以判断之前是否从doing请求中获取过已成功计费量。In one implementation manner, after receiving a begin request or a doing request last time, if the doing request or the end request is not received for a preset period of time, it may be considered that the session ends abnormally. At this point, it can be judged whether the successfully billed amount has been obtained from the doing request before.
S402、确定实际计费量为最近一次从doing请求中获取的已成功计费量。S402. Determine that the actual billing amount is the successfully billed amount acquired from the doing request last time.
如果获取过doing请求中携带的已成功计费量,则最近一次从doing请求中获取的已成功计费量最接近处理业务请求所消耗的实际计费量,因此将实际计费量确定为最近一次从doing请求中获取的已成功计费量。If you have obtained the successfully billed amount carried in the doing request, the last successfully billed amount obtained from the doing request is closest to the actual billed amount consumed by processing the service request, so the actual billed amount is determined as the latest The successfully billed amount obtained from a doing request.
S403、确定实际计费量为0。S403. Determine that the actual billing amount is 0.
如果未获取过doing请求中携带的已成功计费量,则说明业务请求可能未被处理,因此确定实际计费量为0。If the successfully billed amount carried in the doing request has not been obtained, it means that the service request may not be processed, so it is determined that the actual billed amount is 0.
S404、将确定的实际计费量累加到用户标识对应的已用量中,并从用户标识对应的已预计费量中删除本次预计费量。S404. Add the determined actual billing amount to the used amount corresponding to the user ID, and delete the current estimated billing amount from the estimated billing amount corresponding to the user ID.
由于持续预设时长未接收到doing请求或者end请求,此时确定会话异常结束,且确定业务请求停止处理,因此需要进行计费,即将实际计费量累加到用户标识对应的已用量中。而且由于业务请求已停止处理,因此需要从用户标识对应的已预计费量中删除本次预计费量。Since no doing request or end request is received for the preset duration, it is determined that the session ends abnormally and the processing of the service request stops, so billing is required, that is, the actual billed amount is added to the used amount corresponding to the user ID. And because the processing of the service request has stopped, it is necessary to delete the current estimated amount from the estimated amount corresponding to the user ID.
采用上述方法,流控计费模块可以通过定时GC任务,在会话异常结束时,进行及时地计费,并及时清理本次预计费量,减少无效的预扣用量占用的存储资源。Using the above method, the flow control billing module can perform timely billing when the session ends abnormally through the scheduled GC task, and clear up the estimated billing amount in time to reduce the storage resources occupied by invalid withholding usage.
在本公开的一个实施例中,在上述步骤三或者S404从用户标识对应的已预计费量中删除本次预计费量之后,流控计费模块还可以在实际计费量大于零时,基于实际计费量生成本次计费账单。In an embodiment of the present disclosure, after the above step 3 or S404 deletes the current estimated amount from the estimated amount corresponding to the user ID, the flow control and billing module can also calculate the actual billing amount based on The actual billing amount generates this billing bill.
其中,计费账单包括:实际计费量、基于实际计费量计算得到的费用、以及时间戳等。其中时间戳可以是代理服务接收到业务请求的时间,或者业务请求处理完成的时间等。Wherein, the charging bill includes: the actual billing amount, the fee calculated based on the actual billing amount, and a time stamp. The timestamp may be the time when the proxy service receives the business request, or the time when the business request is processed.
本公开实施例可以在业务请求处理完成且实际计费量不为0时,再生成本次计费账单,即业务请求处理失败时,实际计费量为0,此时不会生成计费账单。因此避免了先行流控方案中先行生成计费账单,而导致业务请求出错后需要删除原本生成的计费账单的问题。In the embodiment of the present disclosure, when the service request processing is completed and the actual billing amount is not 0, the current billing bill can be regenerated, that is, when the service request processing fails, the actual billing amount is 0, and no billing bill will be generated at this time. Therefore, it avoids the problem that the charging bills generated in advance in the pre-emptive flow control scheme need to be deleted after the service request makes an error.
基于相同的发明构思,对应于图1所示的方法实施例,本公开实施例还提供了一种流控计费方法,应用于代理服务,如图5所示,该方法包括如下步骤:Based on the same inventive concept, corresponding to the method embodiment shown in FIG. 1, the embodiment of the present disclosure also provides a flow control charging method, which is applied to proxy services. As shown in FIG. 5, the method includes the following steps:
S501、接收终端发送的业务请求。其中,业务请求中包括触发业务请求的用户标识。S501. Receive a service request sent by a terminal. Wherein, the service request includes the ID of the user who triggers the service request.
S502、确定业务请求的本次预计费量。S502. Determine the current estimated fee amount of the service request.
其中,S501和S502的具体实现方式可参考上述S101中的描述,此处不再赘述。Wherein, for specific implementation manners of S501 and S502, reference may be made to the description in S101 above, and details are not repeated here.
S503、向流控计费模块发送携带用户标识和预计费量的begin请求,以使得流控计费模块判断本次预计费量、用户标识对应的已预计费量和已用量的总和是否大于可用额度,得到判断结果,基于判断结果,确定是否响应业务请求,并基于业务请求的响应结果累加用户标识对应的已用量。其中,用户标识对应的已预计费量为用户标识对应的正在被处理的各业务请求的本次预计费量总和。S503. Send a begin request carrying the user ID and the estimated amount of charge to the flow control and billing module, so that the flow control and billing module judges whether the sum of the estimated charge amount, the estimated charge amount and the used amount corresponding to the user identifier is greater than the available amount Quota, get the judgment result, determine whether to respond to the business request based on the judgment result, and accumulate the used amount corresponding to the user ID based on the response result of the business request. Wherein, the estimated billing amount corresponding to the user ID is the sum of the current estimated billing amounts of the service requests being processed corresponding to the user ID.
其中,S503的具体实现方式可参考上述S102中的描述,此处不再赘述。Wherein, for the specific implementation manner of S503, reference may be made to the description in S102 above, which will not be repeated here.
由图5所示的方法可以看出,本公开实施例将流量收发和流控计费分离,即如图2b所示,本公开实施例增加了代理服务,由代理服务代替流控计费模块与终端和算子服务交互,即由代理服务负责简单的逻辑处理,不做复杂的逻辑计算。由流控计费模块负责流量控制和计费。由于本公开实施例减少了流控计费模块的处理逻辑,即减少了流控计费模块承载的压力,从而能够适用于高并发场景。It can be seen from the method shown in FIG. 5 that the embodiment of the present disclosure separates traffic sending and receiving from flow control billing, that is, as shown in FIG. 2b, the embodiment of the present disclosure adds a proxy service, and the proxy service replaces the stream control billing module Interact with terminals and operator services, that is, the proxy service is responsible for simple logic processing and does not perform complex logic calculations. The flow control and billing module is responsible for flow control and billing. Since the embodiment of the present disclosure reduces the processing logic of the flow control and charging module, that is, reduces the pressure carried by the flow control and charging module, it is applicable to high concurrency scenarios.
而且,在本公开实施例中,流控计费模块在处理业务请求之前,先判断本次预计费量、用户标识对应的已预计费量和已用量的总和是否大于可用额度,即判断处理业务请求是否会产生超额的问题,此时并未直接累加可用额度,而是后续根据业务请求的响应结果累加可用额度。因此即使业务请求处理失败,也不需要进行数据回滚或删除,即解决了先行流控的过早计费所造成的需要数据回滚或删除的问题。此外,由于本公开实施例在处理业务请求之前,先判断处理业务请求是否会产生超额问题,因此解决了后行流控超额判定的滞后性,从而能够适用于高并发场景。Moreover, in the embodiment of the present disclosure, before processing the service request, the flow control and billing module first judges whether the sum of the expected billing amount, the estimated billing amount and the used amount corresponding to the user ID is greater than the available amount, that is, judges whether the processing business The question of whether the request will cause excess, at this time, the available quota is not directly accumulated, but the available quota is subsequently accumulated according to the response result of the business request. Therefore, even if the service request fails to be processed, there is no need to perform data rollback or deletion, which solves the problem of data rollback or deletion caused by premature billing in advance flow control. In addition, because the embodiment of the present disclosure first judges whether processing a business request will cause an overage problem before processing the business request, it solves the hysteresis of subsequent flow control oversubscription determination, and thus can be applied to high concurrency scenarios.
在本公开的一个实施例中,在上述S503之后,代理服务还可以执行如下步骤:In an embodiment of the present disclosure, after the above S503, the proxy service may also perform the following steps:
步骤1、识别接收到的流控计费模块针对begin请求发送的响应是begin失败响应还是begin成功响应。Step 1. Identify whether the received response sent by the flow control and accounting module to the begin request is a begin failure response or a begin success response.
步骤2、若接收到流控计费模块发送的begin失败响应,则向终端发送请求失败响应。Step 2. If the begin failure response sent by the flow control and accounting module is received, send a request failure response to the terminal.
如果接收到流控计费模块发送的begin失败响应,表示处理业务请求可能导致额度超限问题,因此向终端发送请求失败响应。If the begin failure response sent by the flow control and billing module is received, it means that the processing of the business request may lead to a quota limit problem, so a request failure response is sent to the terminal.
其中,步骤2的具体实现方式可参考上述步骤一中的描述,此处不再赘述。Wherein, for the specific implementation manner of step 2, reference may be made to the description in the above step 1, which will not be repeated here.
步骤3、若接收到流控计费模块发送的begin成功响应,则向算子服务转发业务请求,以使得算子服务处理业务请求。Step 3. If the begin success response sent by the flow control and billing module is received, the service request is forwarded to the operator service, so that the operator service processes the service request.
如果接收到流控计费模块发送的begin成功响应,表示处理业务请求一般不会导致额度超限问题,因此可以控制算子服务处理业务请求。If the begin success response sent by the flow control and billing module is received, it means that the processing of business requests generally does not cause the problem of exceeding the quota, so the operator service can be controlled to process business requests.
其中,步骤3的具体实现方式可参考上述步骤二中的描述,此处不再赘述。Wherein, for the specific implementation manner of step 3, reference may be made to the description in the above step 2, which will not be repeated here.
步骤4、在确定算子服务对业务请求处理完成时,向流控计费模块发送end请求,以使得流控计费模块将end请求包括的处理业务请求所消耗的实际计费量累加到用户标识对应的已用量中,并从用户标识对应的已预计费量中删除本次预计费量。Step 4. When it is determined that the operator service has completed the processing of the business request, send an end request to the flow control and billing module, so that the flow control and billing module will add the actual billing amount consumed by processing the business request included in the end request to the user In the used amount corresponding to the ID, delete the estimated billing amount for this time from the estimated billed amount corresponding to the user ID.
其中,步骤4的具体实现方式可参考上述步骤二中的描述,此处不再赘述。Wherein, for the specific implementation manner of step 4, reference may be made to the description in the above step 2, which will not be repeated here.
采用上述方法,本公开实施例中流控计费模块在处理业务请求之前,先基于本次预计费量进行流量控制,且本次预计费量没有直接累加到已计费量中,而是在业务请求处理完 成之后,才将实际计费量累加到已计费量中。即本公开实施例结合了先行流控和后行流控,且先行流控时没有累加已计费量,因此即使业务请求处理失败,也不需要进行数据回滚或删除,既解决了先行流控的过早计费所造成的需要数据回滚或删除的问题。后行流控可以按照请求处理成功时所消耗的实际计费量进行已用量的累加,而且在后行流控之前进行了先行流控,而先行流控可以减少流量超额使用的情况,即在准确地进行流量控制的基础上,解决了后行流控容易导致流量超额使用的问题。因此本公开实施例能够在高并发场景下进行准确地流量控制。Using the above method, before processing the service request, the flow control and billing module in the embodiment of the present disclosure performs flow control based on the current estimated fee amount, and the current estimated fee amount is not directly added to the billed amount, but is added to the service The actual billed amount is added to the billed amount only after the request processing is completed. That is to say, the embodiment of the present disclosure combines the advanced flow control and the backward flow control, and the billed amount is not accumulated during the advanced flow control, so even if the service request processing fails, there is no need to perform data rollback or deletion, which solves the problem of the advanced flow Problems that require data rollback or deletion caused by premature billing of the control. Subsequent flow control can accumulate the used amount according to the actual billing amount consumed when the request is processed successfully, and pre-emptive flow control is performed before post-traffic flow control, and pre-emptive flow control can reduce traffic overuse, that is, in On the basis of accurate flow control, it solves the problem that subsequent flow control easily leads to excessive use of flow. Therefore, the embodiments of the present disclosure can perform accurate flow control in high concurrency scenarios.
在本公开的一个实施例中,为了进一步提升流控计费的准确性,在上述步骤3向算子服务转发业务请求之后,如图6所示,代理服务还可以执行以下步骤:In an embodiment of the present disclosure, in order to further improve the accuracy of flow control and billing, after the above step 3 forwards the business request to the operator service, as shown in Figure 6, the proxy service can also perform the following steps:
S601、实时从算子服务中获取当前处理业务请求所消耗的已成功计费量。S601. Obtain in real time the successfully billed amount consumed by the current service request processing from the operator service.
一种实现方式中,算子服务可以在处理业务请求的过程中,实时向代理服务发送前处理业务请求所消耗的已成功计费量。In one implementation manner, the operator service may send the successful billing amount consumed by the previously processed service request to the proxy service in real time during the process of processing the service request.
S602、周期性地向流控计费模块发送携带已成功计费量的doing请求,以使得流控计费模块从doing请求中获取已成功计费量,将用户标识对应的已预计费量中的本次预计费量更新为获取的已成功计费量,并判断当前的已预计费量与用户标识对应的已用量的总和是否大于可用额度,若否,则向代理服务发送doing成功响应,若是,则向代理服务发送doing失败响应。S602. Periodically send a doing request carrying a successfully billed amount to the flow control and billing module, so that the flow control and billing module obtains the successfully billed amount from the doing request, and includes the estimated billed amount corresponding to the user identifier Update the estimated billing amount of this time to the successfully billed amount obtained, and judge whether the sum of the current estimated billing amount and the used amount corresponding to the user ID is greater than the available amount, if not, send a doing success response to the proxy service, If so, send a doing failure response to the proxy service.
其中,S602的具体实现方式可参考上述S302-S304中的描述,此处不再赘述。Wherein, for the specific implementation manner of S602, reference may be made to the above descriptions in S302-S304, which will not be repeated here.
S603、若接收到流控计费模块发送的doing失败响应,则终止算子服务处理业务请求,并确定实际计费量为算子服务当前处理业务请求所消耗的已成功计费量,基于确定的实际计费量生成end请求,并向流控计费模块发送生成的end请求。S603. If the doing failure response sent by the flow control and billing module is received, terminate the operator service to process the business request, and determine that the actual billing amount is the successfully billed amount consumed by the operator service currently processing the business request, based on the determination The actual billing amount generates an end request, and sends the generated end request to the flow control billing module.
在本公开实施例中,若接收到流控计费模块发送的doing成功响应,则表示当前处理业务请求还未出现超额问题,因此可以继续处理业务请求。In the embodiment of the present disclosure, if the doing success response sent by the flow control and billing module is received, it means that there is no overage problem in currently processing the service request, so the service request can continue to be processed.
其中,S603的具体实现方式可参考上述S304中的描述,此处不再赘述。Wherein, for the specific implementation manner of S603, reference may be made to the description in S304 above, which will not be repeated here.
采用上述方法,通过doing心跳机制,流控计费模块可以实时获取到算子服务处理业务请求的已成功计费量,而已成功计费量为真实的使用量,因此流量计费模块可以实时的根据真实使用量进行流量控制和计费。Using the above method, through the doing heartbeat mechanism, the flow control billing module can obtain the successfully billed amount of the operator service processing business request in real time, and the successful billed amount is the real usage, so the traffic billing module can real-time Traffic control and billing are performed based on actual usage.
应用于代理服务的流控计费方法和应用于流控计费模块的流控计费方法中,相同的步骤的实现方式可相互参照。In the flow control and charging method applied to the proxy service and the flow control and charging method applied to the flow control and charging module, the realization of the same steps can be referred to each other.
以下结合应用场景,对本公开实施例提供的流控计费方法的具体过程进行说明:The specific process of the flow control and billing method provided by the embodiment of the present disclosure is described below in conjunction with the application scenario:
参见图7,流控计费模块接收到begin请求后,对begin请求进行数据解析及预处理,具体为:从begin请求提取触发业务请求的用户标识、本次预计费量、SN、计费方式和计费接口id等数据,并将提取的各项数据对应记录。然后调用begin的lua脚本,begin的lua脚本的处理过程为图7中虚线框内的步骤。其中,lua是一个小巧的脚本语言,能够灵活地嵌入应用程序中,从而为应用程序提供灵活地扩展和定制功能。Referring to Figure 7, after receiving the begin request, the flow control and billing module performs data analysis and preprocessing on the begin request, specifically: extracting the user ID that triggers the service request, the estimated amount of charge, SN, and billing method from the begin request and billing interface id and other data, and record the extracted data correspondingly. Then call the lua script of begin, and the processing process of the lua script of begin is the steps in the dotted line box in Fig. 7. Among them, lua is a small scripting language that can be flexibly embedded in applications, thus providing flexible expansion and customization functions for applications.
通过调用begin的lua脚本,对该路会话的会话标识进行加锁,即记录SN,并判断加锁是否成功。若未成功,则向代理服务返回begin失败响应。若成功,则判断本次预计费 量、用户标识对应的已预计费量和已用量的总和是否大于可用额度。若大于,则进行锁释放,即删除记录的SN,并向代理服务返回begin失败响应。若不大于,则将本次预计费量加入已预计费量。存储会话数据信息,具体为将从begin请求中提取的数据存储到分布式Redis。之后向代理服务返回begin成功响应。By calling the lua script of begin, lock the session identifier of the session, that is, record the SN, and judge whether the locking is successful. If unsuccessful, return a begin failure response to the proxy service. If it succeeds, it is judged whether the sum of the expected charge amount, the estimated charge amount corresponding to the user ID, and the used amount is greater than the available amount. If it is greater than, the lock is released, that is, the recorded SN is deleted, and a begin failure response is returned to the proxy service. If it is not greater, add the estimated fee amount to the estimated fee amount. Store session data information, specifically store the data extracted from the begin request to distributed Redis. Then return a begin success response to the proxy service.
参见图8,流控计费模块接收到end请求后,对end请求进行数据解析及预处理,具体为:从end请求中提取SN、status_code和实际计费量,并对应记录。然后判断status_code是否为0;若否,则设置实际计费量为0,若是,则调用end的lua脚本。end的lua脚本的处理过程为图8中虚线框内的步骤。Referring to Figure 8, after receiving the end request, the flow control and billing module performs data analysis and preprocessing on the end request, specifically: extracting SN, status_code and actual billing amount from the end request, and corresponding records. Then judge whether the status_code is 0; if not, set the actual billing amount to 0, and if so, call the lua script of end. The processing process of the lua script of end is the steps in the dashed box in Figure 8.
通过调用end的lua脚本,对该路会话的SN进行锁释放,并判断锁释放是否成功,若不成功,则删除SN对应的会话数据信息。若成功,则将提取的实际计费量累加到用户标识对应的已用量中,并从用户标识对应的已预计费量中删除本次预计费量。By calling the lua script of end, release the lock of the SN of the session, and judge whether the lock release is successful, if not, delete the session data information corresponding to the SN. If successful, add the extracted actual charging amount to the used amount corresponding to the user ID, and delete the current estimated billing amount from the estimated billing amount corresponding to the user ID.
然后判断实际计费量是否为非0,若否,则删除SN对应的会话数据信息。若是,则根据实际计费量生成本次计费账单,然后删除SN对应的会话数据信息。之后向代理服务返回end响应,表示对本次会话计费完成。Then it is judged whether the actual charging amount is non-zero, and if not, the session data information corresponding to the SN is deleted. If yes, generate a current billing bill according to the actual billing amount, and then delete the session data information corresponding to the SN. Afterwards, an end response is returned to the proxy service, indicating that the charging for this session is completed.
参见图9,流控计费模块接收到doing请求后,对doing请求进行数据解析和预处理,具体为:提取SN和已成功计费量,并对应记录。然后调用doing的lua脚本,doing的lua脚本的处理过程为图9中虚线框内的步骤。Referring to Figure 9, after receiving the doing request, the flow control and billing module performs data analysis and preprocessing on the doing request, specifically: extracting the SN and the successfully billed amount, and corresponding records. Then call the lua script of doing, and the processing process of the lua script of doing is the steps in the dotted line box in Fig. 9 .
通过调用doing的lua脚本,判断会话标识的锁是否存在,即是否记录有该SN。若不存在,则向代理服务返回doing失败响应。若存在,则更新最新处理时间为当前时间,并判断已成功计费量是否大于本次预计费量。若大于,则将用户标识对应的已预计费量中的本次预计费量更新为已成功计费量。若不大于,则保持已预计费量不变。之后判断当前的已预计费量与用户标识对应的已用量的总和是否大于可用额度。若大于,则向代理服务返回doing失败响应。若不大于,则向代理服务返回doing成功响应。By calling the lua script of doing, determine whether the lock of the session identifier exists, that is, whether the SN is recorded. If it does not exist, return a doing failure response to the proxy service. If it exists, update the latest processing time to the current time, and judge whether the successfully billed amount is greater than the expected billing amount this time. If it is greater, update the current estimated billing amount in the estimated billing amount corresponding to the user identifier to the successfully billed amount. If not greater than, keep the estimated cost unchanged. Then it is judged whether the sum of the current estimated billing amount and the used amount corresponding to the user identifier is greater than the available amount. If it is greater than, return a doing failure response to the proxy service. If it is not greater than, return a doing success response to the proxy service.
参见图10,流控计费模块实时检测是否存在超时会话,即针对每个SN,判断上一次接收到该SN的begin或者doing请求后,是否持续预设时长未接收到包括该SN的doing请求或者end请求。若否,则返回继续检测。若是,则判断超时会话是否被doing标记过已成功计费量,即是否获取过doing请求中携带的已成功计费量。若未标记过,则设置实际计费量为0。若标记过,则设置实际计费量为最近一次从doing请求中获取的已成功计费量。然后调用end的lua脚本。Referring to Figure 10, the flow control and billing module detects in real time whether there is a timeout session, that is, for each SN, it is judged whether the doing request including the SN has not been received for a preset period of time after receiving the begin or doing request of the SN last time or end request. If not, return to continue detection. If yes, it is judged whether the timed out session has been marked with the successful billing amount by doing, that is, whether the successful billing amount carried in the doing request has been obtained. If not marked, set the actual billing amount to 0. If marked, set the actual billing amount to the last successful billing amount obtained from the doing request. Then call the lua script of end.
通过调用end的lua脚本,对该路会话的SN进行锁释放,并判断锁释放是否成功,若不成功,则删除SN对应的会话数据信息。若成功,则将提取的实际计费量累加到用户标识对应的已用量中,并从用户标识对应的已预计费量中删除本次预计费量。By calling the lua script of end, release the lock of the SN of the session, and judge whether the lock release is successful, if not, delete the session data information corresponding to the SN. If successful, add the extracted actual charging amount to the used amount corresponding to the user ID, and delete the current estimated billing amount from the estimated billing amount corresponding to the user ID.
然后判断实际计费量是否为非0,若否,则删除SN对应的会话数据信息。若是,则根据实际计费量生成成本次计费账单,之后删除SN对应的会话数据信息。之后返回继续检测是否存在超时会话。Then it is judged whether the actual charging amount is non-zero, and if not, the session data information corresponding to the SN is deleted. If yes, then generate the current billing bill according to the actual billing amount, and then delete the session data information corresponding to the SN. Then return to continue to detect whether there is a timeout session.
图7-图10的具体实现方式可参考上述相关描述。For the specific implementation manners of FIGS. 7-10 , reference may be made to the above related descriptions.
基于相同的发明构思,对应于上述方法实施例,本公开实施例提供了一种流控计费装置,应用于流控计费模块,如图11所示,该装置包括:第一接收模块1101、判断模块1102和累加模块1103;Based on the same inventive concept, corresponding to the above-mentioned method embodiments, an embodiment of the present disclosure provides a flow control and charging device, which is applied to the flow control and charging module. As shown in FIG. 11 , the device includes: a first receiving module 1101 , judgment module 1102 and accumulation module 1103;
第一接收模块1101,用于接收代理服务发送的begin请求,begin请求为代理服务在接收到终端发送的业务请求后发送,begin请求包括触发业务请求的用户标识和处理业务请求的本次预计费量;The first receiving module 1101 is used to receive the begin request sent by the proxy service. The begin request is sent by the proxy service after receiving the service request sent by the terminal. The begin request includes the user identification that triggers the service request and the current estimated fee for processing the service request quantity;
判断模块1102,用于判断本次预计费量、用户标识对应的已预计费量和已用量的总和是否大于可用额度,得到判断结果;用户标识对应的已预计费量为用户标识对应的正在被处理的各业务请求的本次预计费量总和;The judging module 1102 is used to judge whether the sum of the expected billing amount, the estimated billing amount corresponding to the user ID, and the used amount is greater than the available amount, and obtain the judgment result; The sum of the current estimated fee volume of each service request processed;
累加模块1103,用于基于判断模块1102的判断结果,确定是否响应业务请求,并基于业务请求的响应结果累加用户标识对应的已用量。The accumulation module 1103 is configured to determine whether to respond to the service request based on the judgment result of the judgment module 1102, and to accumulate the used amount corresponding to the user identifier based on the response result of the service request.
在本公开的一个实施例中,累加模块1103,具体用于:In an embodiment of the present disclosure, the accumulation module 1103 is specifically used for:
若判断模块1102的判断结果为是,则向代理服务发送begin失败响应,以使得代理服务向终端发送请求失败响应;If the judgment result of the judging module 1102 is yes, then send a begin failure response to the proxy service, so that the proxy service sends a request failure response to the terminal;
若判断模块1102的判断结果为否,则将本次预计费量加入用户标识对应的已预计费量,并向代理服务发送begin成功响应,以使得代理服务调用算子服务处理业务请求,并在确定算子服务处理完成时向流控计费模块发送结束end请求,end请求包括处理业务请求所消耗的实际计费量;If the judging result of the judging module 1102 is no, then add the estimated billing amount to the estimated billing amount corresponding to the user identifier, and send a begin success response to the proxy service, so that the proxy service calls the operator service to process the business request, and When it is determined that the operator service processing is completed, an end request is sent to the flow control and billing module, and the end request includes the actual billing amount consumed by processing the business request;
接收代理服务发送的end请求,将实际计费量累加到用户标识对应的已用量中,并从用户标识对应的已预计费量中删除本次预计费量。Receive the end request sent by the proxy service, add the actual billing amount to the used amount corresponding to the user ID, and delete the estimated billing amount from the estimated billing amount corresponding to the user ID.
在本公开的一个实施例中,end请求包括状态码,状态码用于表示业务请求是否处理成功;该装置还可以包括:实际计费量确定模块和获取模块;In an embodiment of the present disclosure, the end request includes a status code, and the status code is used to indicate whether the service request is processed successfully; the device may also include: an actual charging amount determination module and an acquisition module;
判断模块1102,还用于在接收代理服务发送的end请求之后,判断end请求中的状态码是否表示业务请求处理成功;The judging module 1102 is also used to judge whether the status code in the end request indicates that the business request is processed successfully after receiving the end request sent by the proxy service;
实际计费量确定模块,用于若判断模块1102的判断结果为否,则确定处理业务请求所消耗的实际计费量为0,并保持用户标识对应的已用量不变;The actual billing amount determination module is used to determine that the actual billing amount consumed by processing the service request is 0 if the judgment result of the judging module 1102 is no, and keep the used amount corresponding to the user identification unchanged;
获取模块,用于若判断模块1102的判断结果为是,则从end请求中获取实际计费量,并执行将实际计费量累加到用户标识对应的已用量中的步骤。The acquiring module is configured to acquire the actual billing amount from the end request if the judging result of the judging module 1102 is yes, and perform the step of adding the actual billing amount to the used amount corresponding to the user identifier.
在本公开的一个实施例中,begin请求和end请求中均包括代理服务与终端之间的会话的会话标识;该装置还可以包括:记录模块、删除模块和查询模块;In an embodiment of the present disclosure, both the begin request and the end request include the session identifier of the session between the proxy service and the terminal; the device may also include: a recording module, a deletion module and a query module;
记录模块,用于在判断本次预计费量、用户标识对应的已预计费量和已用量的总和是否大于可用额度之前,记录begin请求中的会话标识;The recording module is used to record the session ID in the begin request before judging whether the sum of the estimated billing amount, the estimated billing amount and the used amount corresponding to the user ID is greater than the available amount;
删除模块,用于在判断本次预计费量、用户标识对应的已预计费量和已用量的总和是否大于可用额度之后,若是,则删除记录的会话标识;The deletion module is used to delete the recorded session identification after judging whether the sum of the estimated amount of charge, the estimated amount corresponding to the user ID, and the amount used is greater than the available amount;
查询模块,用于在将实际计费量累加到用户标识对应的已用量中之前,查询是否已记录end请求中的会话标识;若是,则删除记录的会话标识;若否,则忽略end请求。The query module is used to query whether the session ID in the end request has been recorded before adding the actual billing amount to the used amount corresponding to the user ID; if so, delete the recorded session ID; if not, ignore the end request.
在本公开的一个实施例中,该装置还可以包括:第一发送模块;In an embodiment of the present disclosure, the device may further include: a first sending module;
第一接收模块1101,还用于在向代理服务发送begin成功响应之后,且在接收代理服务发送的end请求之前,接收代理服务发送的处理中doing请求,doing请求包括算子服务当前处理业务请求所消耗的已成功计费量;The first receiving module 1101 is also configured to receive the processing doing request sent by the proxy service after sending the begin success response to the proxy service and before receiving the end request sent by the proxy service, the doing request includes the current processing business request of the operator service The successfully billed amount consumed;
判断模块1102,还用于从doing请求中获取已成功计费量,将用户标识对应的已预计费量中的本次预计费量更新为获取的已成功计费量,并判断当前的已预计费量与用户标识对应的已用量的总和是否大于可用额度;The judging module 1102 is also used to obtain the successfully billed amount from the doing request, update the current estimated billed amount in the estimated billed amount corresponding to the user identifier to the acquired successful billed amount, and judge the current estimated billed amount Whether the sum of the fee amount and the used amount corresponding to the user ID is greater than the available amount;
第一发送模块,用于若判断模块1102的判断结果为否,则向代理服务发送doing成功响应,以使得代理服务在确定算子服务处理完成时向流控计费模块发送end请求;The first sending module is configured to send a doing success response to the proxy service if the judgment result of the judging module 1102 is no, so that the proxy service sends an end request to the flow control and charging module when it is determined that the operator service processing is completed;
第一发送模块,还用于若判断模块1102的判断结果为是,则向代理服务发送doing失败响应,以使得代理服务终止算子服务处理业务请求,并确定实际计费量为算子服务当前处理业务请求所消耗的已成功计费量,并发送携带确定的实际计费量的end请求。The first sending module is also configured to send a doing failure response to the proxy service if the judgment result of the judging module 1102 is yes, so that the proxy service terminates the operator service to process the business request, and determines that the actual billing amount is the current operator service Process the successfully billed amount consumed by the service request, and send an end request carrying the determined actual billed amount.
在本公开的一个实施例中,该装置还可以包括:调用模块;In an embodiment of the present disclosure, the device may further include: a calling module;
判断模块1102,还用于在从doing请求中获取已成功计费量之后,判断已成功计费量是否大于本次预计费量;The judging module 1102 is also used for judging whether the successfully billed amount is greater than the expected billing amount after obtaining the successfully billed amount from the doing request;
调用模块,用于若判断模块1102的判断结果为是,则调用判断模块1102执行将用户标识对应的已预计费量中的本次预计费量更新为获取的已成功计费量的步骤;The calling module is used to call the judging module 1102 to execute the step of updating the current estimated charging amount in the estimated charging amount corresponding to the user identification to the acquired successful charging amount if the judgment result of the judging module 1102 is yes;
调用模块,还用于若判断模块1102的判断结果为否,则保持已预计费量不变,并调用判断模块1102执行判断当前的已预计费量与用户标识对应的已用量的总和是否大于可用额度的步骤。The calling module is also used to keep the estimated billing amount unchanged if the judging result of the judging module 1102 is no, and call the judging module 1102 to judge whether the sum of the current estimated billing amount and the used amount corresponding to the user identification is greater than the available amount Quota steps.
在本公开的一个实施例中,该装置还可以包括:实际计费量确定模块和删除模块;In an embodiment of the present disclosure, the device may further include: an actual billing amount determination module and a deletion module;
判断模块1102,还用于若持续预设时长未接收到doing请求或者end请求,则判断是否获取过doing请求中携带的已成功计费量;The judging module 1102 is also used to judge whether the successful billing amount carried in the doing request has been obtained if the doing request or the end request has not been received for a preset duration;
实际计费量确定模块,用于若判断模块1102的判断结果为是,则确定实际计费量为最近一次从doing请求中获取的已成功计费量;The actual billing amount determination module is used to determine that the actual billing amount is the successful billing amount obtained from the doing request last time if the judging result of the judging module 1102 is yes;
实际计费量确定模块,还用于若判断模块1102的判断结果为否,则确定实际计费量为0;The actual billing amount determination module is also used to determine that the actual billing amount is 0 if the judgment result of the judging module 1102 is no;
删除模块,用于将实际计费量确定模块确定的实际计费量累加到用户标识对应的已用量中,并从用户标识对应的已预计费量中删除本次预计费量。The deletion module is used to add the actual billing amount determined by the actual billing amount determination module to the used amount corresponding to the user ID, and delete the current estimated billing amount from the estimated billing amount corresponding to the user ID.
在本公开的一个实施例中,该装置还可以包括:生成模块;In an embodiment of the present disclosure, the device may further include: a generating module;
生成模块,用于在从用户标识对应的已预计费量中删除本次预计费量之后,在实际计费量大于零时,基于实际计费量生成本次计费账单。The generating module is configured to generate a current bill based on the actual billing amount when the actual billing amount is greater than zero after deleting the current estimated billing amount from the estimated billing amount corresponding to the user identifier.
基于相同的发明构思,对应于上述方法实施例,本公开实施例提供了一种流控计费装置,应用于代理服务,如图12所示,该装置包括:第二接收模块1201、本次预计费量确定模块1202和第二发送模块1203;Based on the same inventive concept, corresponding to the above-mentioned method embodiments, the embodiment of the present disclosure provides a device for flow control and billing, which is applied to proxy services. As shown in FIG. 12 , the device includes: a second receiving module 1201, this The estimated fee amount determination module 1202 and the second sending module 1203;
第二接收模块1201,用于接收终端发送的业务请求,业务请求中包括触发业务请求的用户标识;The second receiving module 1201 is configured to receive a service request sent by a terminal, where the service request includes a user identifier triggering the service request;
本次预计费量确定模块1202,用于确定业务请求的本次预计费量;The current estimated fee amount determination module 1202 is used to determine the current estimated fee amount of the service request;
第二发送模块1203,用于向流控计费模块发送携带用户标识和预计费量的begin请求,以使得流控计费模块判断本次预计费量、用户标识对应的已预计费量和已用量的总和是否大于可用额度,得到判断结果,基于判断结果,确定是否响应业务请求,并基于业务请求的响应结果累加用户标识对应的已用量,用户标识对应的已预计费量为用户标识对应的正在被处理的各业务请求的本次预计费量总和。The second sending module 1203 is configured to send a begin request carrying a user identifier and an estimated billing amount to the flow control and billing module, so that the stream control and billing module can determine the estimated billing amount, the estimated billing amount corresponding to the user identifier, and the Determine whether the sum of usage is greater than the available quota. Based on the judgment result, determine whether to respond to the business request, and based on the response result of the business request, add up the used amount corresponding to the user ID. The estimated amount corresponding to the user ID is the amount corresponding to the user ID. The sum of the current estimated charge amount of each service request being processed.
在本公开实施例中,该装置还可以包括:识别模块;In an embodiment of the present disclosure, the device may further include: an identification module;
识别模块,用于在向流控计费模块发送携带用户标识和预计费量的begin请求之后,识别接收到的流控计费模块针对begin请求发送的响应是begin失败响应还是begin成功响应;The identification module is used to identify whether the received response sent by the flow control and accounting module to the begin request is a begin failure response or a begin success response after sending a begin request carrying a user identifier and an estimated amount to the flow control and accounting module;
第二发送模块1203,还用于若接收到流控计费模块发送的begin失败响应,则向终端发送请求失败响应;The second sending module 1203 is further configured to send a request failure response to the terminal if the begin failure response sent by the flow control and billing module is received;
第二发送模块1203,还用于若接收到流控计费模块发送的begin成功响应,则向算子服务转发业务请求,以使得算子服务处理业务请求;The second sending module 1203 is further configured to forward the service request to the operator service if the begin success response sent by the flow control and billing module is received, so that the operator service processes the service request;
第二发送模块1203,还用于在确定算子服务对业务请求处理完成时,向流控计费模块发送结束end请求,以使得流控计费模块将end请求包括的处理业务请求所消耗的实际计费量累加到用户标识对应的已用量中,并从用户标识对应的已预计费量中删除本次预计费量。The second sending module 1203 is further configured to send an end request to the flow control and billing module when it is determined that the operator service has completed the processing of the service request, so that the flow control and billing module will use the end request to process the service request. The actual billed amount is added to the used amount corresponding to the user ID, and the current estimated billing amount is deleted from the estimated billed amount corresponding to the user ID.
在本公开的一个实施例中,该装置还可以包括:获取模块;In an embodiment of the present disclosure, the device may further include: an acquisition module;
获取模块,用于在向算子服务转发业务请求之后,实时从算子服务中获取当前处理业务请求所消耗的已成功计费量;The obtaining module is used to obtain the successfully billed amount consumed by the current processing business request from the operator service in real time after forwarding the service request to the operator service;
第二发送模块1203,还用于周期性地向流控计费模块发送携带已成功计费量的doing请求,以使得流控计费模块从doing请求中获取已成功计费量,将用户标识对应的已预计费量中的本次预计费量更新为获取的已成功计费量,并判断当前的已预计费量与用户标识对应的已用量的总和是否大于可用额度,若否,则向代理服务发送doing成功响应,若是,则向代理服务发送doing失败响应;The second sending module 1203 is also configured to periodically send a doing request carrying a successfully charged amount to the flow control and charging module, so that the flow control and charging module obtains the successfully charged amount from the doing request, and identifies the user In the corresponding estimated billing amount, the current estimated billing amount is updated to the obtained successfully billed amount, and it is judged whether the sum of the current estimated billing amount and the used amount corresponding to the user ID is greater than the available amount, and if not, send to The proxy service sends a doing success response, and if so, sends a doing failure response to the proxy service;
第二发送模块1203,还用于若接收到流控计费模块发送的doing失败响应,则终止算子服务处理业务请求,并确定实际计费量为算子服务当前处理业务请求所消耗的已成功计费量,基于确定的实际计费量生成end请求,并向流控计费模块发送生成的end请求。The second sending module 1203 is further configured to terminate the operator service processing business request if receiving the doing failure response sent by the flow control and charging module, and determine that the actual billing amount is the consumed current processing business request of the operator service Successful billing amount, generate an end request based on the determined actual billing amount, and send the generated end request to the flow control billing module.
基于相同的发明构思,对应于上述方法实施例,本公开实施例提供了一种流控计费系统,如图13所示,该系统包括代理服务1301、流控计费模块1302和算子服务1303;Based on the same inventive concept, corresponding to the above-mentioned method embodiments, an embodiment of the present disclosure provides a flow control billing system, as shown in FIG. 1303;
流控计费模块1302,用于执行上述方法实施例中由流控计费模块执行的方法步骤;A flow control and billing module 1302, configured to execute the method steps performed by the flow control and billing module in the above method embodiments;
代理服务1301,用于执行上述方法实施例中由代理服务执行的方法步骤;Proxy service 1301, configured to execute the method steps performed by the proxy service in the above method embodiments;
算子服务1303,用于处理业务请求。Operator service 1303, used to process business requests.
本公开的技术方案中,所涉及的计费数据的收集、存储、使用、加工、传输、提供和公开等处理,均符合相关法律法规的规定,且不违背公序良俗。In the technical solution of the present disclosure, the collection, storage, use, processing, transmission, provision, and disclosure of billing data involved are all in compliance with relevant laws and regulations, and do not violate public order and good customs.
需要说明的是,本实施例中的业务请求并不是针对某一特定用户的请求,并不能反映出某一特定用户的个人信息。It should be noted that the service request in this embodiment is not a request for a specific user, and cannot reflect the personal information of a specific user.
根据本公开的实施例,本公开还提供了一种电子设备、一种可读存储介质和一种计算机程序产品。According to the embodiments of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium, and a computer program product.
图14示出了可以用来实施本公开的实施例的示例电子设备1400的示意性框图。电子设备旨在表示各种形式的数字计算机,诸如,膝上型计算机、台式计算机、工作台、个人数字助理、服务器、刀片式服务器、大型计算机、和其它适合的计算机。电子设备还可以表示各种形式的移动装置,诸如,个人数字处理、蜂窝电话、智能电话、可穿戴设备和其它类似的计算装置。本文所示的部件、它们的连接和关系、以及它们的功能仅仅作为示例,并且不意在限制本文中描述的和/或者要求的本公开的实现。FIG. 14 shows a schematic block diagram of an example electronic device 1400 that may be used to implement embodiments of the present disclosure. Electronic device is intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other suitable computers. Electronic devices may also represent various forms of mobile devices, such as personal digital processing, cellular telephones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are by way of example only, and are not intended to limit implementations of the disclosure described and/or claimed herein.
如图14所示,电子设备1400包括计算单元1401,其可以根据存储在只读存储器(ROM)1402中的计算机程序或者从存储单元1408加载到随机访问存储器(RAM)1403中的计算机程序,来执行各种适当的动作和处理。在RAM 1403中,还可存储电子设备1400操作所需的各种程序和数据。计算单元1401、ROM 1402以及RAM 1403通过总线1404彼此相连。输入/输出(I/O)接口1405也连接至总线1404。As shown in FIG. 14 , an electronic device 1400 includes a computing unit 1401, which can perform calculations according to a computer program stored in a read-only memory (ROM) 1402 or a computer program loaded from a storage unit 1408 into a random access memory (RAM) 1403. Various appropriate actions and processes are performed. In the RAM 1403, various programs and data necessary for the operation of the electronic device 1400 can also be stored. The computing unit 1401, ROM 1402, and RAM 1403 are connected to each other through a bus 1404. An input/output (I/O) interface 1405 is also connected to the bus 1404 .
电子设备1400中的多个部件连接至I/O接口1405,包括:输入单元1406,例如键盘、鼠标等;输出单元1407,例如各种类型的显示器、扬声器等;存储单元1408,例如磁盘、光盘等;以及通信单元1409,例如网卡、调制解调器、无线通信收发机等。通信单元1409允许电子设备1400通过诸如因特网的计算机网络和/或各种电信网络与其他设备交换信息/数据。Multiple components in the electronic device 1400 are connected to the I/O interface 1405, including: an input unit 1406, such as a keyboard, a mouse, etc.; an output unit 1407, such as various types of displays, speakers, etc.; a storage unit 1408, such as a magnetic disk, an optical disk etc.; and a communication unit 1409, such as a network card, a modem, a wireless communication transceiver, and the like. The communication unit 1409 allows the electronic device 1400 to exchange information/data with other devices through a computer network such as the Internet and/or various telecommunication networks.
计算单元1401可以是各种具有处理和计算能力的通用和/或专用处理组件。计算单元1401的一些示例包括但不限于中央处理单元(CPU)、图形处理单元(GPU)、各种专用的人工智能(AI)计算芯片、各种运行机器学习模型算法的计算单元、数字信号处理器(DSP)、以及任何适当的处理器、控制器、微控制器等。计算单元1401执行上文所描述的各个方法和处理,例如流控计费方法。例如,在一些实施例中,流控计费方法可被实现为计算机软件程序,其被有形地包含于机器可读介质,例如存储单元1408。在一些实施例中,计算机程序的部分或者全部可以经由ROM 1402和/或通信单元1409而被载入和/或安装到电子设备1400上。当计算机程序加载到RAM 1403并由计算单元1401执行时,可以执行上文描述的流控计费方法的一个或多个步骤。备选地,在其他实施例中,计算单元1401可以通过其他任何适当的方式(例如,借助于固件)而被配置为执行流控计费方法。The computing unit 1401 may be various general-purpose and/or special-purpose processing components having processing and computing capabilities. Some examples of computing units 1401 include, but are not limited to, central processing units (CPUs), graphics processing units (GPUs), various dedicated artificial intelligence (AI) computing chips, various computing units that run machine learning model algorithms, digital signal processing processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 1401 executes various methods and processes described above, such as flow control and charging methods. For example, in some embodiments, the flow control billing method may be implemented as a computer software program tangibly embodied on a machine-readable medium, such as the storage unit 1408 . In some embodiments, part or all of the computer program can be loaded and/or installed on the electronic device 1400 via the ROM 1402 and/or the communication unit 1409. When the computer program is loaded into the RAM 1403 and executed by the computing unit 1401, one or more steps of the flow control charging method described above can be performed. Alternatively, in other embodiments, the computing unit 1401 may be configured in any other appropriate way (for example, by means of firmware) to execute the flow control and charging method.
本文中以上描述的系统和技术的各种实施方式可以在数字电子电路系统、集成电路系统、场可编程门阵列(FPGA)、专用集成电路(ASIC)、专用标准产品(ASSP)、芯片上系统的系统(SOC)、复杂可编程逻辑设备(CPLD)、计算机硬件、固件、软件、和/或它们的组合中实现。这些各种实施方式可以包括:实施在一个或者多个计算机程序中,该一个或者多个计算机程序可在包括至少一个可编程处理器的可编程系统上执行和/或解释,该可编程处理器可以是专用或者通用可编程处理器,可以从存储系统、至少一个输入装置、和至少一个输出装置接收数据和指令,并且将数据和指令传输至该存储系统、该至少一个输入装置、和该至少一个输出装置。Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips Implemented in a system of systems (SOC), complex programmable logic device (CPLD), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include being implemented in one or more computer programs executable and/or interpreted on a programmable system including at least one programmable processor, the programmable processor Can be special-purpose or general-purpose programmable processor, can receive data and instruction from storage system, at least one input device, and at least one output device, and transmit data and instruction to this storage system, this at least one input device, and this at least one output device an output device.
用于实施本公开的方法的程序代码可以采用一个或多个编程语言的任何组合来编写。 这些程序代码可以提供给通用计算机、专用计算机或其他可编程数据处理装置的处理器或控制器,使得程序代码当由处理器或控制器执行时使流程图和/或框图中所规定的功能/操作被实施。程序代码可以完全在机器上执行、部分地在机器上执行,作为独立软件包部分地在机器上执行且部分地在远程机器上执行或完全在远程机器或服务器上执行。Program codes for implementing the methods of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special purpose computer, or other programmable data processing devices, so that the program codes, when executed by the processor or controller, make the functions/functions specified in the flow diagrams and/or block diagrams Action is implemented. The program code may execute entirely on the machine, partly on the machine, as a stand-alone software package partly on the machine and partly on a remote machine or entirely on the remote machine or server.
在本公开的上下文中,机器可读介质可以是有形的介质,其可以包含或存储以供指令执行系统、装置或设备使用或与指令执行系统、装置或设备结合地使用的程序。机器可读介质可以是机器可读信号介质或机器可读储存介质。机器可读介质可以包括但不限于电子的、磁性的、光学的、电磁的、红外的、或半导体系统、装置或设备,或者上述内容的任何合适组合。机器可读存储介质的更具体示例会包括基于一个或多个线的电气连接、便携式计算机盘、硬盘、随机存取存储器(RAM)、只读存储器(ROM)、可擦除可编程只读存储器(EPROM或快闪存储器)、光纤、便捷式紧凑盘只读存储器(CD-ROM)、光学储存设备、磁储存设备、或上述内容的任何合适组合。In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media would include one or more wire-based electrical connections, portable computer discs, hard drives, random access memory (RAM), read only memory (ROM), erasable programmable read only memory (EPROM or flash memory), optical fiber, compact disk read only memory (CD-ROM), optical storage, magnetic storage, or any suitable combination of the foregoing.
为了提供与用户的交互,可以在计算机上实施此处描述的系统和技术,该计算机具有:用于向用户显示信息的显示装置(例如,CRT(阴极射线管)或者LCD(液晶显示器)监视器);以及键盘和指向装置(例如,鼠标或者轨迹球),用户可以通过该键盘和该指向装置来将输入提供给计算机。其它种类的装置还可以用于提供与用户的交互;例如,提供给用户的反馈可以是任何形式的传感反馈(例如,视觉反馈、听觉反馈、或者触觉反馈);并且可以用任何形式(包括声输入、语音输入或者、触觉输入)来接收来自用户的输入。To provide for interaction with the user, the systems and techniques described herein can be implemented on a computer having a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user. ); and a keyboard and pointing device (eg, a mouse or a trackball) through which a user can provide input to the computer. Other kinds of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and can be in any form (including Acoustic input, speech input or, tactile input) to receive input from the user.
可以将此处描述的系统和技术实施在包括后台部件的计算系统(例如,作为数据服务器)、或者包括中间件部件的计算系统(例如,应用服务器)、或者包括前端部件的计算系统(例如,具有图形用户界面或者网络浏览器的用户计算机,用户可以通过该图形用户界面或者该网络浏览器来与此处描述的系统和技术的实施方式交互)、或者包括这种后台部件、中间件部件、或者前端部件的任何组合的计算系统中。可以通过任何形式或者介质的数字数据通信(例如,通信网络)来将系统的部件相互连接。通信网络的示例包括:局域网(LAN)、广域网(WAN)和互联网。The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., as a a user computer having a graphical user interface or web browser through which a user can interact with embodiments of the systems and techniques described herein), or including such backend components, middleware components, Or any combination of front-end components in a computing system. The components of the system can be interconnected by any form or medium of digital data communication, eg, a communication network. Examples of communication networks include: Local Area Network (LAN), Wide Area Network (WAN) and the Internet.
计算机系统可以包括客户端和服务器。客户端和服务器一般远离彼此并且通常通过通信网络进行交互。通过在相应的计算机上运行并且彼此具有客户端-服务器关系的计算机程序来产生客户端和服务器的关系。服务器可以是云服务器,也可以为分布式系统的服务器,或者是结合了区块链的服务器。A computer system may include clients and servers. Clients and servers are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by computer programs running on the respective computers and having a client-server relationship to each other. The server can be a cloud server, a server of a distributed system, or a server combined with a blockchain.
应该理解,可以使用上面所示的各种形式的流程,重新排序、增加或删除步骤。例如,本公开中记载的各步骤可以并行地执行也可以顺序地执行也可以不同的次序执行,只要能够实现本公开公开的技术方案所期望的结果,本文在此不进行限制。It should be understood that steps may be reordered, added or deleted using the various forms of flow shown above. For example, each step described in the present disclosure may be executed in parallel, sequentially, or in a different order, as long as the desired result of the technical solution disclosed in the present disclosure can be achieved, no limitation is imposed herein.
上述具体实施方式,并不构成对本公开保护范围的限制。本领域技术人员应该明白的是,根据设计要求和其他因素,可以进行各种修改、组合、子组合和替代。任何在本公开的精神和原则之内所作的修改、等同替换和改进等,均应包含在本公开保护范围之内。The specific implementation manners described above do not limit the protection scope of the present disclosure. It should be apparent to those skilled in the art that various modifications, combinations, sub-combinations and substitutions may be made depending on design requirements and other factors. Any modifications, equivalent replacements and improvements made within the spirit and principles of the present disclosure shall be included within the protection scope of the present disclosure.
Claims (17)
- 一种流控计费方法,应用于流控计费模块,包括:A flow control billing method applied to a flow control billing module, comprising:接收代理服务发送的开始begin请求,所述begin请求为所述代理服务在接收到终端发送的业务请求后发送,所述begin请求包括触发所述业务请求的用户标识和处理所述业务请求的本次预计费量;Receiving a start request sent by the proxy service, the begin request is sent by the proxy service after receiving the service request sent by the terminal, the begin request includes the user ID that triggers the service request and the script for processing the service request Estimated fee amount;判断所述本次预计费量、所述用户标识对应的已预计费量和已用量的总和是否大于可用额度,得到判断结果;所述用户标识对应的已预计费量为所述用户标识对应的正在被处理的各业务请求的本次预计费量总和;Judging whether the sum of the expected charge amount for this time, the estimated charge amount corresponding to the user identifier, and the used amount is greater than the available amount, and obtain a judgment result; the estimated charge amount corresponding to the user identifier is the amount corresponding to the user identifier The sum of the current estimated cost of each service request being processed;基于判断结果,确定是否响应所述业务请求,并基于所述业务请求的响应结果累加所述用户标识对应的已用量。Based on the judgment result, determine whether to respond to the service request, and accumulate the used amount corresponding to the user identifier based on the response result of the service request.
- 根据权利要求1所述的方法,其中,所述基于判断结果,确定是否响应所述业务请求,并基于所述业务请求的响应结果累加所述用户标识对应的已用量,包括:The method according to claim 1, wherein, based on the judgment result, determining whether to respond to the service request, and accumulating the used amount corresponding to the user identifier based on the response result of the service request, includes:若判断结果为是,则向所述代理服务发送begin失败响应,以使得所述代理服务向所述终端发送请求失败响应;If the judgment result is yes, then send a begin failure response to the proxy service, so that the proxy service sends a request failure response to the terminal;若判断结果为否,则将所述本次预计费量加入所述用户标识对应的已预计费量,并向所述代理服务发送begin成功响应,以使得所述代理服务调用算子服务处理所述业务请求,并在确定所述算子服务处理完成时向所述流控计费模块发送结束end请求,所述end请求包括处理所述业务请求所消耗的实际计费量;If the judgment result is no, then add the current estimated billing amount to the estimated billing amount corresponding to the user identifier, and send a begin success response to the proxy service, so that the proxy service calls the operator service to process the The service request, and when it is determined that the operator service processing is completed, send an end request to the flow control and charging module, the end request includes the actual billing amount consumed by processing the service request;接收所述代理服务发送的end请求,将所述实际计费量累加到所述用户标识对应的已用量中,并从所述用户标识对应的已预计费量中删除所述本次预计费量。Receive the end request sent by the proxy service, add the actual billing amount to the used amount corresponding to the user ID, and delete the current estimated billing amount from the estimated billing amount corresponding to the user ID .
- 根据权利要求2所述的方法,所述end请求包括状态码,所述状态码用于表示所述业务请求是否处理成功;在所述接收所述代理服务发送的end请求之后,所述方法还包括:According to the method according to claim 2, the end request includes a status code, and the status code is used to indicate whether the business request is processed successfully; after receiving the end request sent by the proxy service, the method further include:判断所述end请求中的状态码是否表示业务请求处理成功;Judging whether the status code in the end request indicates that the business request has been processed successfully;若否,则确定处理所述业务请求所消耗的实际计费量为0,并保持所述用户标识对应的已用量不变;If not, then determine that the actual billing amount consumed by processing the service request is 0, and keep the used amount corresponding to the user identifier unchanged;若是,则从所述end请求中获取实际计费量,并执行所述将所述实际计费量累加到所述用户标识对应的已用量中的步骤。If yes, the actual billing amount is obtained from the end request, and the step of adding the actual billing amount to the used amount corresponding to the user identifier is executed.
- 根据权利要求2或3所述的方法,所述begin请求和所述end请求中均包括所述代理服务与所述终端之间的会话的会话标识;According to the method according to claim 2 or 3, both the begin request and the end request include the session identifier of the session between the proxy service and the terminal;在所述判断所述本次预计费量、所述用户标识对应的已预计费量和已用量的总和是否大于可用额度之前,所述方法还包括:记录所述begin请求中的会话标识;Before judging whether the sum of the current estimated billing amount, the estimated billing amount corresponding to the user identifier, and the used amount is greater than the available quota, the method further includes: recording the session identifier in the begin request;在所述判断所述本次预计费量、所述用户标识对应的已预计费量和已用量的总和是否大于可用额度之后,所述方法还包括:若是,则删除记录的所述会话标识;After judging whether the sum of the current estimated billing amount, the estimated billing amount corresponding to the user identifier, and the used amount is greater than the available quota, the method further includes: if yes, deleting the recorded session identifier;在所述将所述实际计费量累加到所述用户标识对应的已用量中之前,所述方法还包括:查询是否已记录所述end请求中的会话标识;若是,则删除记录的所述会话标识;若否,则忽略所述end请求。Before adding the actual charging amount to the used amount corresponding to the user identifier, the method further includes: querying whether the session identifier in the end request has been recorded; if so, deleting the recorded Session ID; if not, the end request is ignored.
- 根据权利要求2所述的方法,在所述向所述代理服务发送begin成功响应之后,且 在所述接收所述代理服务发送的end请求之前,所述方法还包括:The method according to claim 2, after sending a begin success response to the proxy service and before receiving the end request sent by the proxy service, the method further comprises:接收所述代理服务发送的处理中doing请求,所述doing请求包括所述算子服务当前处理所述业务请求所消耗的已成功计费量;receiving a processing doing request sent by the proxy service, where the doing request includes the successfully billed amount consumed by the operator service currently processing the business request;从所述doing请求中获取已成功计费量,将所述用户标识对应的已预计费量中的所述本次预计费量更新为获取的已成功计费量,并判断当前的已预计费量与所述用户标识对应的已用量的总和是否大于所述可用额度;Obtain the successfully billed amount from the doing request, update the current estimated billed amount in the estimated billed amount corresponding to the user ID to the obtained successfully billed amount, and determine the current estimated billed amount Whether the sum of the amount and the used amount corresponding to the user ID is greater than the available amount;若否,则向所述代理服务发送doing成功响应,以使得所述代理服务在确定所述算子服务处理完成时向所述流控计费模块发送end请求;If not, then send a doing success response to the proxy service, so that the proxy service sends an end request to the flow control and charging module when it is determined that the operator service processing is completed;若是,则向所述代理服务发送doing失败响应,以使得所述代理服务终止所述算子服务处理所述业务请求,并确定实际计费量为所述算子服务当前处理所述业务请求所消耗的已成功计费量,并发送携带确定的实际计费量的end请求。If so, send a doing failure response to the proxy service, so that the proxy service terminates the operator service from processing the business request, and determines that the actual charging amount is what the operator service is currently processing the business request The successfully billed amount consumed, and an end request carrying the determined actual billed amount is sent.
- 根据权利要求5所述的方法,在所述从所述doing请求中获取已成功计费量之后,所述方法还包括:According to the method according to claim 5, after said obtaining the successfully billed amount from said doing request, said method further comprises:判断所述已成功计费量是否大于所述本次预计费量;Judging whether the successfully billed amount is greater than the current expected billing amount;若是,则执行将所述用户标识对应的已预计费量中的所述本次预计费量更新为获取的已成功计费量的步骤;If yes, then perform the step of updating the current estimated charge amount in the estimated charge amount corresponding to the user identifier to the obtained successfully charged amount;若否,则保持已预计费量不变,并执行判断当前的已预计费量与所述用户标识对应的已用量的总和是否大于所述可用额度的步骤。If not, keep the estimated amount unchanged, and execute the step of judging whether the sum of the current estimated amount and the used amount corresponding to the user identifier is greater than the available amount.
- 根据权利要求5或6所述的方法,所述方法还包括:The method according to claim 5 or 6, said method further comprising:若持续预设时长未接收到doing请求或者end请求,则判断是否获取过doing请求中携带的已成功计费量;If the doing request or end request is not received for the preset duration, it is judged whether the successful billing amount carried in the doing request has been obtained;若是,则确定实际计费量为最近一次从doing请求中获取的已成功计费量;If so, determine that the actual billing amount is the last successful billing amount obtained from the doing request;若否,则确定实际计费量为0;If not, then determine that the actual billing amount is 0;将确定的实际计费量累加到所述用户标识对应的已用量中,并从所述用户标识对应的已预计费量中删除所述本次预计费量。Adding the determined actual billing amount to the used amount corresponding to the user identifier, and deleting the current estimated billing amount from the estimated billing amount corresponding to the user identifier.
- 根据权利要求2-7任一项所述的方法,在所述从所述用户标识对应的已预计费量中删除所述本次预计费量之后,所述方法还包括:According to the method according to any one of claims 2-7, after deleting the current estimated charge amount from the estimated charge amount corresponding to the user identifier, the method further includes:在所述实际计费量大于零时,基于所述实际计费量生成本次计费账单。When the actual charging amount is greater than zero, a current charging bill is generated based on the actual charging amount.
- 一种流控计费方法,应用于代理服务,包括:A flow control billing method applied to proxy services, comprising:接收终端发送的业务请求,所述业务请求中包括触发所述业务请求的用户标识;receiving a service request sent by a terminal, where the service request includes a user identifier triggering the service request;确定所述业务请求的本次预计费量;Determining the current estimated fee amount of the business request;向所述流控计费模块发送携带所述用户标识和所述预计费量的开始begin请求,以使得所述流控计费模块判断所述本次预计费量、所述用户标识对应的已预计费量和已用量的总和是否大于可用额度,得到判断结果,基于判断结果,确定是否响应所述业务请求,并基于所述业务请求的响应结果累加所述用户标识对应的已用量,所述用户标识对应的已预计费量为所述用户标识对应的正在被处理的各业务请求的本次预计费量总和。Sending a begin request carrying the user identifier and the estimated billing amount to the flow control and charging module, so that the flow control and billing module judges the current estimated billing amount and the already charged amount corresponding to the user identifier Whether the sum of the expected fee amount and the used amount is greater than the available amount is obtained to obtain a judgment result, and based on the judgment result, it is determined whether to respond to the service request, and based on the response result of the service request, the used amount corresponding to the user identifier is accumulated, and the The estimated billing amount corresponding to the user ID is the sum of the current estimated billing amounts of the service requests being processed corresponding to the user ID.
- 根据权利要求9所述的方法,在所述向所述流控计费模块发送携带所述用户标识 和所述预计费量的开始begin请求之后,所述方法还包括:The method according to claim 9, after sending the begin request carrying the user identification and the estimated billing amount to the flow control billing module, the method further includes:识别接收到的所述流控计费模块针对所述begin请求发送的响应是begin失败响应还是begin成功响应;identifying whether the received response sent by the flow control and billing module to the begin request is a begin failure response or a begin success response;若接收到所述流控计费模块发送的begin失败响应,则向所述终端发送请求失败响应;If the begin failure response sent by the flow control and billing module is received, a request failure response is sent to the terminal;或者,若接收到所述流控计费模块发送的begin成功响应,则向所述算子服务转发所述业务请求,以使得所述算子服务处理所述业务请求;Or, if the begin success response sent by the flow control and billing module is received, forward the service request to the operator service, so that the operator service processes the service request;在确定所述算子服务对所述业务请求处理完成时,向所述流控计费模块发送结束end请求,以使得所述流控计费模块将所述end请求包括的处理所述业务请求所消耗的实际计费量累加到所述用户标识对应的已用量中,并从所述用户标识对应的已预计费量中删除所述本次预计费量。When it is determined that the operator service has completed the processing of the business request, an end request is sent to the flow control and charging module, so that the flow control and charging module processes the service request included in the end request The actual billing amount consumed is added to the used amount corresponding to the user identifier, and the current estimated billing amount is deleted from the estimated billing amount corresponding to the user identifier.
- 根据权利要求10所述的方法,在所述向所述算子服务转发所述业务请求之后,所述方法还包括:According to the method according to claim 10, after said forwarding said service request to said operator service, said method further comprises:实时从所述算子服务中获取当前处理所述业务请求所消耗的已成功计费量;Acquiring in real time from the operator service the successfully billed amount currently consumed in processing the business request;周期性地向所述流控计费模块发送携带所述已成功计费量的doing请求,以使得所述流控计费模块从所述doing请求中获取已成功计费量,将所述用户标识对应的已预计费量中的所述本次预计费量更新为获取的已成功计费量,并判断当前的已预计费量与所述用户标识对应的已用量的总和是否大于所述可用额度,若否,则向所述代理服务发送doing成功响应,若是,则向所述代理服务发送doing失败响应;periodically sending a doing request carrying the successfully charged amount to the flow control and charging module, so that the flow control and charging module obtains the successfully charged amount from the doing request, and sends the user The current estimated billing amount in the corresponding estimated billing amount is updated to the obtained successfully billed amount, and it is judged whether the sum of the current estimated billing amount and the used amount corresponding to the user identification is greater than the available Quota, if no, then send a doing success response to the proxy service, if so, then send a doing failure response to the proxy service;若接收到所述流控计费模块发送的doing失败响应,则终止所述算子服务处理所述业务请求,并确定实际计费量为所述算子服务当前处理所述业务请求所消耗的已成功计费量,基于确定的实际计费量生成end请求,并向所述流控计费模块发送生成的end请求。If the doing failure response sent by the flow control and charging module is received, the operator service is terminated to process the business request, and the actual billing amount is determined to be the amount consumed by the operator service currently processing the business request The successfully billed amount generates an end request based on the determined actual billed amount, and sends the generated end request to the flow control billing module.
- 一种流控计费装置,应用于流控计费模块,包括:A flow control billing device, applied to a flow control billing module, comprising:第一接收模块,用于接收代理服务发送的开始begin请求,所述begin请求为所述代理服务在接收到终端发送的业务请求后发送,所述begin请求包括触发所述业务请求的用户标识和处理所述业务请求的本次预计费量;The first receiving module is configured to receive a start request sent by the proxy service, the begin request is sent by the proxy service after receiving the service request sent by the terminal, and the begin request includes the user identifier and the user ID that triggered the service request The current estimated fee for processing the business request;判断模块,用于判断所述本次预计费量、所述用户标识对应的已预计费量和已用量的总和是否大于可用额度,得到判断结果;所述用户标识对应的已预计费量为所述用户标识对应的正在被处理的各业务请求的本次预计费量总和;A judging module, configured to judge whether the sum of the expected billing amount, the estimated billing amount corresponding to the user identifier, and the used amount is greater than the available amount, and obtain a judgment result; the estimated billing amount corresponding to the user identifier is The sum of the current estimated charges for each service request being processed corresponding to the above user ID;累加模块,用于基于判断模块的判断结果,确定是否响应所述业务请求,并基于所述业务请求的响应结果累加所述用户标识对应的已用量。The accumulation module is configured to determine whether to respond to the service request based on the judgment result of the judgment module, and to accumulate the used amount corresponding to the user identifier based on the response result of the service request.
- 一种流控计费装置,应用于代理服务,包括:A flow control billing device, applied to proxy services, comprising:第二接收模块,用于接收终端发送的业务请求,所述业务请求中包括触发所述业务请求的用户标识;The second receiving module is configured to receive a service request sent by a terminal, where the service request includes a user identifier triggering the service request;本次预计费量确定模块,用于确定所述业务请求的本次预计费量;The current estimated fee amount determination module is used to determine the current estimated fee amount of the service request;第二发送模块,用于向所述流控计费模块发送携带所述用户标识和所述预计费量的开始begin请求,以使得所述流控计费模块判断所述本次预计费量、所述用户标识对应的已预计费量和已用量的总和是否大于可用额度,得到判断结果,基于判断结果,确定是否响 应所述业务请求,并基于所述业务请求的响应结果累加所述用户标识对应的已用量,所述用户标识对应的已预计费量为所述用户标识对应的正在被处理的各业务请求的本次预计费量总和。The second sending module is configured to send a begin request carrying the user identifier and the expected charge amount to the flow control and charging module, so that the flow control and charge module can judge the current estimate charge amount, Whether the sum of the estimated charge amount and the used amount corresponding to the user identifier is greater than the available amount is obtained as a judgment result, and based on the judgment result, it is determined whether to respond to the service request, and the user identifier is accumulated based on the response result of the service request The corresponding used amount, the estimated billed amount corresponding to the user ID is the sum of the current estimated billed amount of each service request being processed corresponding to the user ID.
- 一种流控计费系统,包括代理服务、流控计费模块和算子服务;A flow control billing system, including a proxy service, a flow control billing module, and an operator service;所述流控计费模块,用于执行权利要求1-8任一项所述的方法;The flow control and billing module is configured to execute the method according to any one of claims 1-8;所述代理服务,用于执行权利要求9-11任一项所述的方法;The proxy service is used to execute the method according to any one of claims 9-11;所述算子服务,用于处理业务请求。The operator service is used to process business requests.
- 一种电子设备,包括:An electronic device comprising:至少一个处理器;以及at least one processor; and与所述至少一个处理器通信连接的存储器;其中,a memory communicatively coupled to the at least one processor; wherein,所述存储器存储有可被所述至少一个处理器执行的指令,所述指令被所述至少一个处理器执行,以使所述至少一个处理器能够执行权利要求1-8或者9-11中任一项所述的方法。The memory stores instructions executable by the at least one processor, the instructions are executed by the at least one processor, so that the at least one processor can perform any of claims 1-8 or 9-11 one of the methods described.
- 一种存储有计算机指令的非瞬时计算机可读存储介质,其中,所述计算机指令用于使所述计算机执行根据权利要求1-8或者9-11中任一项所述的方法。A non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to make the computer execute the method according to any one of claims 1-8 or 9-11.
- 一种计算机程序产品,包括计算机程序,所述计算机程序在被处理器执行时实现根据权利要求1-8或者9-11中任一项所述的方法。A computer program product comprising a computer program which, when executed by a processor, implements the method according to any one of claims 1-8 or 9-11.
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210116365.5 | 2022-02-07 | ||
CN202210116365.5A CN114500128B (en) | 2022-02-07 | 2022-02-07 | Flow control charging method, device, system, electronic equipment, medium and product |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2023147716A1 true WO2023147716A1 (en) | 2023-08-10 |
Family
ID=81477768
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2022/106800 WO2023147716A1 (en) | 2022-02-07 | 2022-07-20 | Flow control and billing methods, apparatuses and system, electronic device, medium and product |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN114500128B (en) |
WO (1) | WO2023147716A1 (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN118138384A (en) * | 2024-02-22 | 2024-06-04 | 百融至信(北京)科技有限公司 | Charging method and device based on array structure |
Families Citing this family (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115665674B (en) * | 2022-11-11 | 2023-03-10 | 上海大汉三通通信股份有限公司 | 5G message processing method, device, equipment and storage medium |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20080008090A1 (en) * | 2006-07-10 | 2008-01-10 | International Business Machines Corporation | Method for Distributed Hierarchical Admission Control across a Cluster |
CN102065057A (en) * | 2009-11-18 | 2011-05-18 | 华为技术有限公司 | Method and server applied to agency service of Widget |
CN110198275A (en) * | 2018-03-28 | 2019-09-03 | 腾讯科技(深圳)有限公司 | A kind of flow control methods, system, server and storage medium |
CN113285884A (en) * | 2021-07-19 | 2021-08-20 | 阿里云计算有限公司 | Flow control method and system |
Family Cites Families (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN100466526C (en) * | 2007-01-10 | 2009-03-04 | 华为技术有限公司 | Credit control client terminal, credit control server, charging system and charging method |
EP2406928B1 (en) * | 2009-03-10 | 2017-01-04 | Telefonaktiebolaget LM Ericsson (publ) | Traffic control by ip multimedia subsystem |
CN102149063B (en) * | 2010-06-29 | 2013-10-09 | 华为技术有限公司 | Method, device and system for charging prepayment |
CN102802145B (en) * | 2012-08-08 | 2015-04-29 | 中国联合网络通信集团有限公司 | Network service billing method, device and system |
CN109547956B (en) * | 2017-09-21 | 2021-05-07 | 中国移动通信集团天津有限公司 | Multi-service concurrent processing method |
CN108833590B (en) * | 2018-07-11 | 2021-10-26 | 北京百度网讯科技有限公司 | Voice recognition service proxy server and proxy method |
CN113938851A (en) * | 2020-06-29 | 2022-01-14 | 中兴通讯股份有限公司 | Flow charging method, network equipment and storage medium |
CN112769788B (en) * | 2020-12-29 | 2022-08-12 | 中国移动通信集团江苏有限公司 | Charging service data processing method and device, electronic equipment and storage medium |
-
2022
- 2022-02-07 CN CN202210116365.5A patent/CN114500128B/en active Active
- 2022-07-20 WO PCT/CN2022/106800 patent/WO2023147716A1/en unknown
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20080008090A1 (en) * | 2006-07-10 | 2008-01-10 | International Business Machines Corporation | Method for Distributed Hierarchical Admission Control across a Cluster |
CN102065057A (en) * | 2009-11-18 | 2011-05-18 | 华为技术有限公司 | Method and server applied to agency service of Widget |
CN110198275A (en) * | 2018-03-28 | 2019-09-03 | 腾讯科技(深圳)有限公司 | A kind of flow control methods, system, server and storage medium |
CN113285884A (en) * | 2021-07-19 | 2021-08-20 | 阿里云计算有限公司 | Flow control method and system |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN118138384A (en) * | 2024-02-22 | 2024-06-04 | 百融至信(北京)科技有限公司 | Charging method and device based on array structure |
Also Published As
Publication number | Publication date |
---|---|
CN114500128B (en) | 2023-05-23 |
CN114500128A (en) | 2022-05-13 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
WO2023147716A1 (en) | Flow control and billing methods, apparatuses and system, electronic device, medium and product | |
CN109684358B (en) | Data query method and device | |
CN111277639B (en) | Method and device for maintaining data consistency | |
CN108304554B (en) | File splitting method and device, computer equipment and storage medium | |
US20240284158A1 (en) | Method and system for performing charging on network resource, and related device | |
CN113162848B (en) | Method, device, gateway and medium for realizing block chain gateway | |
EP2723017A1 (en) | Method, apparatus and system for implementing distributed auto-incrementing counting | |
EP3937022B1 (en) | Method and apparatus of monitoring interface performance of distributed application, device and storage medium | |
US20230269304A1 (en) | Method and apparatus for processing notification trigger message | |
CN113127564B (en) | Parameter synchronization method and device | |
WO2020220780A1 (en) | Method and system for performing charging processing on network resource, and device | |
EP4187882A1 (en) | Data transmission method and apparatus, device, storage medium, and computer program product | |
WO2017114180A1 (en) | Component logical threads quantity adjustment method and device | |
CN114661510B (en) | Method, device, equipment and storage medium for detecting overtime request | |
CN113238815A (en) | Interface access control method, device, equipment and storage medium | |
WO2020143502A1 (en) | Method and system for performing billing processing on network slice instances and related device | |
CN114398520A (en) | Data retrieval method, system, device, electronic equipment and storage medium | |
CN111400283B (en) | Data processing method, system, electronic equipment and storage medium | |
CN113051332A (en) | Multi-source data integration method and system based on big data technology | |
US20230283655A1 (en) | Data download method and apparatus, electronic device, and readable storage medium | |
WO2023109238A1 (en) | Data synchronization method and system, and storage medium | |
CN109670952B (en) | Collecting and paying transaction platform | |
CN115168440A (en) | Data read-write method, distributed storage system, device, equipment and storage medium | |
CN112508710B (en) | Account checking system and corresponding computer equipment | |
CN114647701A (en) | Load balancing method and device for distributed database, electronic equipment and medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 22924644 Country of ref document: EP Kind code of ref document: A1 |
|
NENP | Non-entry into the national phase |
Ref country code: DE |