CN110430142B - Method and device for controlling flow - Google Patents

Method and device for controlling flow Download PDF

Info

Publication number
CN110430142B
CN110430142B CN201910758905.8A CN201910758905A CN110430142B CN 110430142 B CN110430142 B CN 110430142B CN 201910758905 A CN201910758905 A CN 201910758905A CN 110430142 B CN110430142 B CN 110430142B
Authority
CN
China
Prior art keywords
counting
terminal
traffic
current
consumption
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910758905.8A
Other languages
Chinese (zh)
Other versions
CN110430142A (en
Inventor
付胜博
王华勇
周文静
严彪
周飞龙
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Baidu Netcom Science and Technology Co Ltd
Original Assignee
Beijing Baidu Netcom Science and Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Baidu Netcom Science and Technology Co Ltd filed Critical Beijing Baidu Netcom Science and Technology Co Ltd
Priority to CN201910758905.8A priority Critical patent/CN110430142B/en
Publication of CN110430142A publication Critical patent/CN110430142A/en
Application granted granted Critical
Publication of CN110430142B publication Critical patent/CN110430142B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L47/00Traffic control in data switching networks
    • H04L47/10Flow control; Congestion control
    • H04L47/29Flow control; Congestion control using a combination of thresholds
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L47/00Traffic control in data switching networks
    • H04L47/10Flow control; Congestion control
    • H04L47/32Flow control; Congestion control by discarding or delaying data units, e.g. packets or frames
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D30/00Reducing energy consumption in communication networks
    • Y02D30/50Reducing energy consumption in communication networks in wire-line communication networks, e.g. low power modes or reduced link rate

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

Embodiments of the present disclosure disclose methods and apparatus for controlling flow. The method is applied to the service instance of the portal service in the multi-level service, and one embodiment of the method comprises the following steps: in response to receiving user request data sent by a terminal, determining whether the current load exceeds a load threshold; and responding to the fact that the current load exceeds the load threshold, obtaining the current flow consumption of the terminal, and determining whether to discard the user request data according to the relation between the current flow consumption of the terminal and the signed flow. In the embodiment, the flow can be controlled from the source of the flow, so that the flow load of each service instance of the entrance service can be ensured to be kept in a relatively stable range, the flow load of each service after the entrance service can be ensured to be kept in a relatively stable range, and the stability of the system is improved.

Description

Method and device for controlling flow
Technical Field
Embodiments of the present disclosure relate to the field of computer technology, and in particular, to a method and apparatus for controlling flow.
Background
In a distributed system, multiple services are typically deployed, and each service may have a large number of service instances. When a system receives a user request, each service in the multi-level service is generally required to respond to the received user request according to a preset processing sequence and processing rule.
In the related art, when service flow is increased suddenly, call frequency, resource occupation and service delay between services are increased correspondingly, and system breakdown is caused when serious, so that system stability is not high.
Disclosure of Invention
Embodiments of the present disclosure propose methods and apparatus for controlling flow.
In a first aspect, embodiments of the present disclosure provide a method for controlling a flow, applied to a service instance of an ingress service in a multi-level service, the method comprising: in response to receiving user request data sent by a terminal, determining whether the current load exceeds a load threshold; and responding to the fact that the current load exceeds the load threshold, obtaining the current flow consumption of the terminal, and determining whether to discard the user request data according to the relation between the current flow consumption of the terminal and the signed flow.
In some embodiments, the current flow consumption includes: global flow consumption of the terminal in the previous counting period and local flow consumption of the terminal in the current counting period; the global traffic consumption is traffic consumption of user request data submitted to the portal service by the terminal in the last counting period, and the local traffic consumption is traffic consumption of user request data submitted to the service instance by the terminal in the current counting period.
In some embodiments, obtaining the current traffic consumption of the terminal comprises: an asynchronous query request is sent to a counting service node to acquire global traffic consumption of a terminal sent by the counting service node based on the asynchronous query request in a last counting period; and acquiring the local traffic consumption of the terminal in the current counting period from a preset storage position.
In some embodiments, determining whether to discard the user request data according to the size relationship between the current traffic consumption of the terminal and the subscription traffic includes: responsive to determining that the global traffic consumption is empty and the local traffic consumption is greater than the contracted traffic, determining to discard the user request data; responsive to determining that the global traffic consumption is non-null and the global traffic consumption is greater than the subscription traffic, it is determined to discard the user request data.
In some embodiments, the load threshold includes a first threshold, a second threshold, and a third threshold, and the current traffic consumption further includes a plurality of backup traffic consumption, the plurality of backup traffic consumption being traffic consumption of user request data submitted by the terminal to the portal service in a plurality of historical count periods other than the last count period, respectively; and in response to determining that the current load exceeds the load threshold, obtaining current flow consumption of the terminal, determining whether to discard the user request data according to the magnitude relation between the current flow consumption of the terminal and the contracted flow, including: discarding the user request data in response to determining that the current load is greater than the first threshold and less than the second threshold and that the global traffic consumption and/or the local traffic consumption in the current traffic consumption is greater than the contracted traffic; and discarding the user request data in response to determining that the current load is greater than the second threshold and less than the third threshold and that the backup traffic consumption is greater than the subscription traffic or the global traffic consumption is greater than the subscription traffic among the plurality of backup traffic consumptions in the current traffic consumption.
In some embodiments, the method further comprises: in response to determining that the current load amount does not exceed the load threshold, it is determined not to discard the user request data.
In some embodiments, the method further comprises: in response to determining not to discard the user request data, performing the steps of: updating the current load; determining a required flow required by a user to request the requested content in the data, and updating the local flow consumption of the current counting period according to the required flow; based on terminal identity and demand flow of the terminal, coding to obtain counting information, storing the obtained counting information into a counting information queue, wherein the counting information queue is a lock-free queue with a fixed-length memory, and sending the counting information in the counting information queue to a counting service node for counting so as to obtain global flow consumption of a current counting period.
In some embodiments, sending the count information in the count information queue to the count service node for counting includes: based on a preset processing period, merging all counting information corresponding to the terminal identity in the counting information queue to obtain the counting information of the corresponding terminal, and sending the counting information of the terminal to a counting service node.
In some embodiments, the global traffic consumption for the current count period is counted via the count service node by: receiving counting information, and storing the received counting information to a preset first data storage structure which is a lock-free data structure by taking a terminal as granularity; and in response to determining that the current moment is the end of the counting period, counting the total flow of the terminal in the first data storage structure, taking the total flow as the global flow consumption of the current counting period, storing the data stored in the first data storage structure into a second data storage structure in a preset second data storage structure group, deleting the data stored in the first data storage structure, wherein the second data storage structure in the second data storage structure group is a lock-free data structure.
In some embodiments, before storing the data stored by the first data storage structure in the second data storage structure of the set of predetermined second data storage structures, further comprising: in response to determining that the number of occupied second data storage structures in the second set of data storage structures exceeds a preset number threshold, deleting data stored in a second data storage structure in the second set of data storage structures that is currently occupied for a longest period of time.
In a second aspect, embodiments of the present disclosure provide an apparatus for controlling a flow, applied to any service instance processing unit of a service node, the service instance processing unit being configured to execute a service instance of an ingress service in a multi-level service, wherein the apparatus includes: a first determining unit configured to determine whether a current load amount exceeds a load threshold in response to receiving user request data transmitted by a terminal; and the second determining unit is configured to respond to the determination that the current load exceeds the load threshold value, acquire the current flow consumption of the terminal, and determine whether to discard the user request data according to the magnitude relation between the current flow consumption of the terminal and the contracted flow.
In some embodiments, the current flow consumption includes: global flow consumption of the terminal in the previous counting period and local flow consumption of the terminal in the current counting period; the global traffic consumption is traffic consumption of user request data submitted to the portal service by the terminal in the last counting period, and the local traffic consumption is traffic consumption of user request data submitted to the service instance by the terminal in the current counting period.
In some embodiments, in the second determining unit, obtaining the current traffic consumption of the terminal includes: an asynchronous query request is sent to a counting service node to acquire global traffic consumption of a terminal sent by the counting service node based on the asynchronous query request in a last counting period; and acquiring the local traffic consumption of the terminal in the current counting period from a preset storage position.
In some embodiments, the second determining unit determines whether to discard the user request data according to a size relationship between the current traffic consumption of the terminal and the subscription traffic, including: responsive to determining that the global traffic consumption is empty and the local traffic consumption is greater than the contracted traffic, determining to discard the user request data; responsive to determining that the global traffic consumption is non-null and the global traffic consumption is greater than the subscription traffic, it is determined to discard the user request data.
In some embodiments, the load threshold includes a first threshold, a second threshold, and a third threshold, and the current traffic consumption further includes a plurality of backup traffic consumption, the plurality of backup traffic consumption being traffic consumption of user request data submitted by the terminal to the portal service in a plurality of historical count periods other than the last count period, respectively; and the second determining unit is further configured to: discarding the user request data in response to determining that the current load is greater than the first threshold and less than the second threshold and that the global traffic consumption and/or the local traffic consumption in the current traffic consumption is greater than the contracted traffic; and discarding the user request data in response to determining that the current load is greater than the second threshold and less than the third threshold and that the backup traffic consumption is greater than the subscription traffic or the global traffic consumption is greater than the subscription traffic among the plurality of backup traffic consumptions in the current traffic consumption.
In some embodiments, the apparatus further comprises: and a third determining unit configured to determine not to discard the user request data in response to determining that the current load amount does not exceed the load threshold.
In some embodiments, the apparatus further comprises: a step execution unit configured to execute, in response to determining not to discard the user request data, the steps of: updating the current load; determining a required flow required by a user to request the requested content in the data, and updating the local flow consumption of the current counting period according to the required flow; based on terminal identity and demand flow of the terminal, coding to obtain counting information, storing the obtained counting information into a counting information queue, wherein the counting information queue is a lock-free queue with a fixed-length memory, and sending the counting information in the counting information queue to a counting service node for counting so as to obtain global flow consumption of a current counting period.
In some embodiments, the step of sending the count information in the count information queue to the count service node for counting includes: based on a preset processing period, merging all counting information corresponding to the terminal identity in the counting information queue to obtain the counting information of the corresponding terminal, and sending the counting information of the terminal to a counting service node.
In some embodiments, the global traffic consumption for the current count period is counted via the count service node by: receiving counting information, and storing the received counting information to a preset first data storage structure which is a lock-free data structure by taking a terminal as granularity; and in response to determining that the current moment is the end of the counting period, counting the total flow of the terminal in the first data storage structure, taking the total flow as the global flow consumption of the current counting period, storing the data stored in the first data storage structure into a second data storage structure in a preset second data storage structure group, deleting the data stored in the first data storage structure, wherein the second data storage structure in the second data storage structure group is a lock-free data structure.
In some embodiments, before storing the data stored by the first data storage structure in the second data storage structure of the set of predetermined second data storage structures, further comprising: in response to determining that the number of occupied second data storage structures in the second set of data storage structures exceeds a preset number threshold, deleting data stored in a second data storage structure in the second set of data storage structures that is currently occupied for a longest period of time.
In a third aspect, embodiments of the present disclosure provide an electronic device comprising: one or more processors; a storage device having one or more programs stored thereon; the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the method as described in any of the implementations of the first aspect.
In a fourth aspect, embodiments of the present disclosure provide a computer readable medium having stored thereon a computer program which, when executed by a processor, implements a method as described in any of the implementations of the first aspect.
The method and the device for controlling the flow provided by the embodiment of the disclosure can be used for determining whether the current load exceeds the load threshold or not in response to receiving the user request data sent by the terminal. Then, in response to determining that the current load exceeds the load threshold, current flow consumption of the terminal is obtained, and whether to discard the user request data is determined according to the magnitude relation between the current flow consumption of the terminal and the signed flow. According to the method and the device provided by the embodiment of the disclosure, the portal service is the service which responds to the user request data first in the multi-stage service, and each service instance of the portal service determines whether to discard the user request data, so that the flow can be controlled from the source of the flow, the flow load of each service instance of the portal service can be ensured to be kept in a relatively stable range, the flow load of each service after the portal service can be ensured to be kept in a relatively stable range, and the stability of the system is improved. In addition, each service instance of the portal service determines whether to discard the user request data by combining two factors of the current load capacity of the service instance and the current flow consumption of the terminal, ensures the use of the subscription flow of the user as much as possible in the processing capacity range of the service instance, can realize fair and reasonable discarding of the user request data, and is beneficial to realizing effective utilization of data processing resources.
Drawings
Other features, objects and advantages of the present disclosure will become more apparent upon reading of the detailed description of non-limiting embodiments, made with reference to the following drawings:
FIG. 1 is an exemplary system architecture diagram in which an embodiment of the present disclosure may be applied;
FIG. 2 is a flow chart of one embodiment of a method for controlling flow according to the present disclosure;
FIG. 3 is a schematic illustration of one application scenario of a method for controlling flow in accordance with an embodiment of the present disclosure;
FIG. 4 is a flow chart of yet another embodiment of a method for controlling flow according to the present disclosure;
FIG. 5 is a schematic structural view of one embodiment of an apparatus for controlling flow according to the present disclosure;
fig. 6 is a schematic structural diagram of an electronic device suitable for use in implementing embodiments of the present disclosure.
Detailed Description
The present disclosure is described in further detail below with reference to the drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be noted that, for convenience of description, only the portions related to the present invention are shown in the drawings.
It should be noted that, without conflict, the embodiments of the present disclosure and features of the embodiments may be combined with each other. The present disclosure will be described in detail below with reference to the accompanying drawings in conjunction with embodiments.
Fig. 1 illustrates an exemplary system architecture 100 for a method of controlling flow or an apparatus for controlling flow to which embodiments of the present disclosure may be applied.
As shown in fig. 1, a system architecture 100 may include a user terminal 101, a network 102, and a service node 103. Network 102 is the medium used to provide communication links between user terminals 101 and serving nodes 103. Network 102 may include various connection types such as wired, wireless communication links, or fiber optic cables, among others.
The user terminal 101 may interact with the service node 103 via the network 102 to receive or send messages or the like. The user terminal 101 may have various applications installed thereon, such as a search-type application, an error-checking-type application, a shopping-type application, and the like.
The user terminal 101 may be hardware or software. When the user terminal 101 is hardware, it may be a variety of electronic devices that support user-requested data input, including but not limited to smartphones, tablets, laptop and desktop computers, and the like. When the user terminal 101 is software, it can be installed in the above-listed electronic device. Which may be implemented as multiple software or software modules (e.g., multiple software or software modules for providing distributed services) or as a single software or software module. The present invention is not particularly limited herein.
Service node 103 may be a server running service instances of portal services in a multi-level service. The service instance running on the service node 103 may determine, when receiving user request data sent by the user terminal 101, whether the current load exceeds a load threshold, and in response to determining that the current load exceeds the load threshold, obtain current traffic consumption of the terminal, and determine whether to discard the user request data according to a size relationship between the current traffic consumption of the terminal and the subscription traffic.
The server may be hardware or software. When the server is hardware, the server may be implemented as a distributed server cluster formed by a plurality of servers, or may be implemented as a single server. When the server is software, it may be implemented as a plurality of software or software modules (e.g., a plurality of software or software modules for providing distributed services), or as a single software or software module. The present invention is not particularly limited herein.
It should be noted that, the method for controlling a flow provided by the embodiments of the present disclosure is generally performed by a service instance running on the service node 103, and accordingly, the device for controlling a flow is generally disposed in a service instance processing unit of the service node 103 for running a service instance of an ingress service.
It should be understood that the number of user terminals, networks and service nodes in fig. 1 is merely illustrative. There may be any number of user terminals, networks and service nodes, as desired for implementation.
With continued reference to fig. 2, a flow 200 of one embodiment of a method for controlling flow in accordance with the present disclosure is shown. The method for controlling the flow is applied to a service instance of an ingress service in a multi-level service, and comprises the following steps:
in step 201, in response to receiving user request data sent by the terminal, it is determined whether the current load exceeds a load threshold.
The portal service in the multi-level service generally refers to a service that responds to the user request data first in the multi-level service. As an example, if the multi-level service includes an a service and a B service, and the user request data needs to be processed by the a service and then processed by the B service, the process of responding to the user request data by the multi-level service may be: terminal to a service, a service to B service, B service to a service, a service to terminal. At this time, since the a service is a service that first responds to the user request data (or, the a service is a service that directly interacts with the terminal), the a service is an entry service in the multi-level service. It should be noted that service instances of each service in the multi-level service are typically processes.
The user request data may be data for requesting a service transmitted by the terminal. As an example, the user request data may be data of a service for requesting read data transmitted by the terminal, or data of a service for requesting write data transmitted by the terminal.
The current load amount generally refers to the number of requests currently processed by the execution body. The load threshold may be a preset data value.
In this embodiment, the execution body of the method for controlling a flow may determine, when receiving user request data sent by a terminal, whether the current load amount exceeds a load threshold. Here, the execution body may compare the current load amount with the load threshold value, so as to determine whether the current load amount exceeds the load threshold value.
Step 202, in response to determining that the current load exceeds the load threshold, obtaining current flow consumption of the terminal, and determining whether to discard the user request data according to the magnitude relation between the current flow consumption of the terminal and the contracted flow.
The current traffic consumption of the terminal generally refers to the current recorded traffic consumption of the terminal. As an example, the current traffic consumption of the terminal may include, but is not limited to, traffic consumption of the terminal in the current counting period, traffic consumption of the terminal in the last two counting periods, and so on. The counting period may be a preset data value, such as 10 seconds. The subscription traffic generally refers to traffic consumption preselected by the terminal.
In this embodiment, when it is determined that the current load amount exceeds the load threshold, the execution body may acquire the current flow consumption of the terminal. Here, as an example, the above-described execution subject may directly acquire the current traffic consumption of the terminal from a storage address set in advance for storing the current traffic consumption of the terminal.
In this embodiment, after obtaining the current traffic consumption of the terminal, the executing body may compare the current traffic consumption with the subscription traffic, so as to determine whether to discard the user request data based on the size relationship between the current traffic consumption and the subscription traffic. As an example, it may be determined to discard user request data when the current traffic consumption is greater than the contracted traffic.
According to the method provided by the embodiment of the disclosure, the portal service is the service which responds to the user request data first in the multi-stage service, and each service instance of the portal service of the multi-stage service determines whether to discard the user request data, so that the flow can be controlled from the source of the flow, the flow load of each service instance of the portal service can be ensured to be kept in a relatively stable range, the flow load of each service after the portal service can be ensured to be kept in a relatively stable range, and the stability of the system is improved. In addition, each service instance of the portal service determines whether to discard the user request data by combining two factors of the current load capacity of the service instance and the current flow consumption of the terminal, ensures the use of the subscription flow of the user as much as possible in the processing capacity range of the service instance, can realize fair and reasonable discarding of the user request data, and is beneficial to realizing effective utilization of data processing resources.
In an alternative implementation of various embodiments of the present disclosure, the current flow consumption may include: the global traffic consumption of the terminal in the last counting period and the local traffic consumption of the terminal in the current counting period. The global traffic consumption is traffic consumption of user request data submitted to the portal service by the terminal in the last counting period, and the local traffic consumption is traffic consumption of user request data submitted to the service instance by the terminal in the current counting period.
In the implementation manner, the global flow consumption can reflect the latest flow consumption condition of the terminal from the whole service angle, so that the method has a stronger reference value to the current whole flow consumption condition, in addition, the local flow consumption can reflect the current local flow consumption condition of the terminal from the current service instance angle, and meanwhile, the method can better ensure fair and reasonable discarding of the user request data and further improve the effective utilization of the data processing resources by considering the global flow consumption and the local flow consumption.
In the implementation manner, the acquiring the current traffic consumption of the terminal may include:
acquiring global traffic consumption: and sending an asynchronous query request to the counting service node to acquire the global traffic consumption of the terminal sent by the counting service node based on the asynchronous query request in the last counting period.
The counting service node is generally used for counting the traffic consumption of user request data submitted by the terminal to the entry service in a counting period. The counting service node can be a process or an independent server. The above-described asynchronous query request is generally request information for requesting an asynchronous query.
Here, the execution body may send an asynchronous query request to the counting service node. In this way, the counting service node can send the global traffic consumption of the terminal in the last counting period to the execution body when receiving the asynchronous query request.
In addition, as another implementation manner, the execution body may send asynchronous query requests to other service instances except the execution body in the portal service respectively to obtain local traffic consumption of the terminal in each service instance, so that the obtained sum of the local traffic consumption of each service instance is taken as global traffic consumption, and global traffic consumption of the terminal is obtained.
Obtaining local traffic consumption: and acquiring the local traffic consumption of the terminal in the current counting period from a preset storage position.
The preset storage location may be a storage address preset in the execution body and used for storing local traffic consumption of the terminal in a current counting period.
Here, the executing body may directly obtain the local traffic consumption of the terminal in the current counting period from the preset storage location.
In the implementation manner, the global flow consumption is acquired in an asynchronous query mode, so that the global flow consumption can be acquired in time without affecting other operations of the execution main body, and the data processing efficiency is improved.
In the implementation manner, determining whether to discard the user request data according to the size relationship between the current traffic consumption and the subscription traffic of the terminal includes:
responsive to determining that the global traffic consumption is empty and the local traffic consumption is greater than the subscription traffic, it is determined to discard the user request data. Responsive to determining that the global traffic consumption is non-null and the global traffic consumption is greater than the subscription traffic, it is determined to discard the user request data.
In this implementation, since the counting service node needs a certain time to respond to the asynchronous query request, it usually needs to wait for a period of time to obtain the global traffic consumption. Here, in order to increase the data processing speed, the executing body may compare the local traffic consumption with the subscription traffic when the global traffic consumption has not been obtained, that is, the global traffic consumption is empty, and determine to discard the user request data when the local traffic consumption is greater than the subscription traffic. Otherwise, when the local traffic consumption is smaller than the subscription traffic, it is determined that the user request data is not discarded.
In addition, after the global traffic consumption is obtained, the executing entity may compare the global traffic consumption with the subscription traffic, and determine to discard the user request data when the global traffic consumption is greater than the subscription traffic. Otherwise, when the global traffic consumption is smaller than the subscription traffic, it is determined that the user request data is not discarded.
It should be noted that, because the local traffic consumption is the traffic consumption of the terminal counted by the executing body in the current counting period, the executing body can always obtain the local traffic consumption, and even if the communication between the executing body and the counting service node fails, the system can still be ensured to stably operate, thereby being beneficial to improving the system stability.
In some optional implementations of the present embodiment, the load threshold includes a first threshold, a second threshold, and a third threshold, and the current traffic consumption includes a global traffic consumption, a local traffic consumption, and a plurality of backup traffic consumptions. The plurality of backup traffic consumptions are traffic consumptions of user request data submitted by the terminal to the portal service in a plurality of history counting periods except for the last counting period, respectively. The first threshold, the second threshold and the third threshold may be preset values of the load, where the first threshold is smaller than the second threshold, and the second threshold is smaller than the third threshold.
At this time, the step of obtaining the current flow consumption of the terminal in response to determining that the current load exceeds the load threshold, and determining whether to discard the user request data according to the magnitude relation between the current flow consumption and the contracted flow of the terminal includes: first, responsive to determining that the current load is greater than a first threshold and less than a second threshold, and that global traffic consumption and/or local traffic consumption in the current traffic consumption is greater than the contracted traffic, user request data is discarded. Then, responsive to determining that the current load is greater than the second threshold and less than the third threshold, and that the backup traffic consumption is greater than the subscription traffic or the global traffic consumption is greater than the subscription traffic among the plurality of backup traffic consumptions in the current traffic consumption, discarding the user request data. Responsive to determining that the current load is greater than the third threshold, the user request data is discarded.
Here, for example, if the maximum request amount that the execution body can process is 100, the first threshold is 80, the second threshold is 90, and the third threshold is 100. When the executing body receives the current user request data, if the current load amount is 60, the executing body may not consider whether to discard the current user request data. If the current load is 85, the executing body may discard the current user request data when it is determined that the global traffic consumption and/or the local traffic consumption is greater than the subscription traffic. If the current load is 96, the executing body may discard the current user request data when the backup traffic consumption is greater than the subscription traffic or the global traffic consumption is greater than the subscription traffic among the backup traffic consumptions. If the current load is 100, the executing body may directly discard the current user request data.
In this implementation manner, the execution body may combine its own request processing capability to discard user request data hierarchically. The method can better ensure fair and reasonable discarding of the user request data and further improve the effective utilization of the data processing resources.
With continued reference to fig. 3, fig. 3 is a schematic diagram of an application scenario 300 of the method for controlling flow according to the present embodiment. In the application scenario of fig. 3, the service instance 3011 of the portal service 301 receives user request data sent by the terminal 302, and performs the following steps:
first, the service instance 3011 may compare the current load amount X1 to the load threshold T1 to determine whether the current load amount X1 exceeds the load threshold T1.
Then, upon determining that the current load amount X1 exceeds the load threshold T1, the service instance 3011 may acquire the current traffic consumption X2 of the terminal 302.
Finally, the service instance 3011 may compare the current traffic consumption X2 with the contracted traffic T2 to determine a size relationship between the current traffic consumption X2 and the contracted traffic T2, thereby determining whether to discard the user request data.
According to the method for controlling the flow, the service instance of the entrance service of the multi-stage service determines whether to discard the user request data or not, so that the flow can be controlled from the source of the flow, the flow load of each service instance of the entrance service can be ensured to be kept in a relatively stable range, the flow load of each service after the entrance service can be ensured to be kept in a relatively stable range, and the stability of the system is improved. In addition, each service instance of the portal service determines whether to discard the user request data by combining two factors of the current load capacity of the service instance and the current flow consumption of the terminal, ensures the use of the subscription flow of the user as much as possible in the processing capacity range of the service instance, can realize fair and reasonable discarding of the user request data, and is beneficial to realizing effective utilization of data processing resources.
With further reference to fig. 4, a flow 400 of yet another embodiment of a method for controlling flow is shown. The flow 400 of the method for controlling flow comprises the steps of:
in step 401, it is determined whether the current load exceeds a load threshold in response to receiving user request data sent by the terminal.
Step 402, in response to determining that the current load exceeds the load threshold, obtaining current flow consumption of the terminal, and determining whether to discard the user request data according to the magnitude relation between the current flow consumption and the subscription flow of the terminal.
In this embodiment, the specific operations of steps 401 to 402 are substantially the same as those of steps 201 to 202 in the embodiment shown in fig. 2, and will not be described herein.
In step 403, it is determined not to discard the user request data in response to determining that the current load amount does not exceed the load threshold.
In this embodiment, when the current load amount does not exceed the load threshold, the user request data is not discarded. Therefore, the service requirement of the terminal can be guaranteed within the processing capacity range of the execution main body, the fair and reasonable discarding of the user request data can be better guaranteed, and the effective utilization of the data processing resources can be further improved.
In response to determining not to discard the user request data, step 404, the execution body may perform steps 4041-4043:
step 4041, updating the current load.
In this embodiment, the execution body may add a preset increment value to the current load amount to implement updating the current load amount and obtain the updated current load amount. The preset increment value may be a preset value. As an example, the preset increment value may be 1 or 2.
Step 4042, determining the required traffic for the user to request the requested content in the data, and updating the local traffic consumption of the current counting period according to the required traffic.
In this embodiment, the execution body may parse the user request data to obtain the content requested by the user request data, and obtain the flow required by the requested content, that is, the required flow. After obtaining the required flow, the execution body may add the local flow consumption to the required flow, thereby implementing that the sum of the local flow consumption and the required flow is used as the updated local flow consumption.
Step 4043, based on the terminal identity and the demand flow of the terminal, encoding to obtain count information, storing the obtained count information into a count information queue, wherein the count information queue is a lock-free queue with a fixed-length memory, and sending the count information in the count information queue to a count service node for counting to obtain the global flow consumption of the current count period.
In this embodiment, the executing body may obtain the count information by using a terminal identifier of the terminal and the required traffic code. At this time, the obtained count information includes the terminal identity and the required traffic. After obtaining the count information, the executing body may store the obtained count information in a count information queue. In this way, the counting information in the counting information queue can be sent to the counting service node for counting, so as to obtain the global traffic consumption of the current counting period.
It should be noted that, since the lock-free queue can implement lock-free storing and lock-free reading of data, the counting information queue is a lock-free queue with a fixed-length memory, which is helpful for improving the data reading and writing speed. In addition, since each storage unit in the fixed-length memory generally stores only elements with the same size, and the read data can be directly deleted after the data is read by adopting the fixed-length memory without releasing the storage unit, the time for creating and releasing the storage unit can be reduced, and since the count information generally has a fixed format and is consistent in size, the count information queue in the embodiment is a lock-free queue with the fixed-length memory, which is beneficial to improving the data processing efficiency.
In this embodiment, when it is determined that the user request data is not discarded, the execution body may respond to the user request data, update the current load amount and the local traffic consumption in time, and count the global traffic consumption of the current counting period in time, so as to help ensure stable operation of the system.
In some optional implementations of this embodiment, the sending the count information in the count information queue to the count service node for counting may include: based on a preset processing period, merging all counting information corresponding to the terminal identity in the counting information queue to obtain the counting information of the corresponding terminal, and sending the counting information of the terminal to a counting service node.
The predetermined processing period may be a predetermined time length value. As an example, the processing period described above may be 2 seconds, 5 seconds, or the like. It should be noted that the above processing period is generally less than or equal to the above counting period. The above-mentioned merging of the count information corresponding to the terminal identity in the count information queue generally refers to overlapping the required traffic in the count information corresponding to one terminal identity, and merging to obtain a piece of total count information for the terminal identity. As an example, if there are 2 pieces of count information for the terminal identity 001, count information a and count information B, respectively. Wherein, the counting information A is: 001 20, the count information B is: 001 50, 20 in A and 50 in B are all demand flows. At this time, the count information a and the count information B are combined, and the total count information can be obtained as: 001, 70.
In this implementation manner, the executing body sends the count information to the count service node according to the preset processing period, and the count information is sent as soon as the count information is available, so that the number of communication times between the executing body and the count service node can be reduced, processing resources consumed by communication between the executing body and the count service node can be saved, the utilization rate of the data processing resources can be improved, and meanwhile, the data processing efficiency of the executing body can be improved.
In addition, the execution body combines the counting information from the same terminal and then sends the counting information to the counting service node, so that the size of communication content between the execution body and the counting service node can be reduced, the communication speed is improved, and the data processing efficiency is improved.
In the implementation manner, the global traffic consumption of the current counting period is obtained by counting through the counting service node by the following steps:
the first step, receiving counting information, and storing the received counting information to a preset first data storage structure which is a lock-free data structure by taking a terminal as granularity.
Here, the counting service node may store the received counting information in the first data storage structure at a location corresponding to the terminal of the counting information after receiving the counting information. It is noted that the first data storage structure may store count information of a plurality of terminals.
And secondly, in response to determining that the current moment is the end of the counting period, counting the total flow of the terminals in the first data storage structure, consuming the total flow as the global flow of the current counting period, storing the data stored in the first data storage structure into a second data storage structure in a preset second data storage structure group, deleting the data stored in the first data storage structure, wherein the second data storage structure in the second data storage structure group is a lock-free data structure.
The first data storage structure is generally used for storing counting information of the terminal in a current counting period, and the second data storage structure is generally used for storing traffic consumption of the terminal in a historical counting period.
Here, at the end of the counting period, the counting service node may count the global traffic consumption of each terminal in the current counting period. Thus, the execution body can take the global traffic consumption obtained in the current counting period as the global traffic consumption in the previous counting period when in the next counting period.
In the implementation manner, the first data storage structure and the second data storage structure are both lock-free data structures, so that lock-free reading and lock-free writing of data can be realized, the data reading and writing speed can be improved, and the data processing efficiency can be improved.
Additionally, the form of the first data storage structure may include, but is not limited to, one of: skip list, hash list, tree. The second data storage structure may include, but is not limited to, one of the following: skip list, hash list, tree. It should be noted that, since the skip list structure helps to improve the access efficiency to the data, when the first data storage structure and/or the second data storage structure are skip lists, it helps to improve the access efficiency to the data, thereby helping to improve the data processing speed.
In the implementation manner, before the storing the data stored in the first data storage structure into the second data storage structure in the preset second data storage structure group, the method further includes: in response to determining that the number of occupied second data storage structures in the second set of data storage structures exceeds a preset number threshold, deleting data stored in a second data storage structure in the second set of data storage structures that is currently occupied for a longest period of time.
The preset number threshold may be a preset data value. As an example, the above-mentioned preset number threshold may be 5, 6, 7, etc.
Here, since the second data storage structure of the second data storage structure group is generally used to store traffic consumption of the terminal in the history counting period. And the flow consumption of the historical counting period which is too long in interval has little reference value on the flow consumption condition of the terminal in the current counting period. Therefore, when the number of occupied second data storage structures in the second data storage structure group exceeds the preset number threshold, the second data storage structure with the longest occupied duration is deleted, so that the storage space can be saved.
With further reference to fig. 5, as an implementation of the method shown in the above figures, the present disclosure provides an embodiment of an apparatus for controlling a flow, which corresponds to the method embodiment shown in fig. 2, and which is particularly applicable to various electronic devices.
As shown in fig. 5, the apparatus 500 for controlling a flow rate of the present embodiment includes: a first determining unit 501 configured to determine whether a current load amount exceeds a load threshold in response to receiving user request data transmitted by a terminal; the second determining unit 502 is configured to, in response to determining that the current load amount exceeds the load threshold, obtain current traffic consumption of the terminal, and determine whether to discard the user request data according to a magnitude relation between the current traffic consumption of the terminal and the subscription traffic.
In some alternative implementations of the present embodiment, the current traffic consumption includes: the global traffic consumption of the terminal in the last counting period and the local traffic consumption of the terminal in the current counting period. The global traffic consumption is traffic consumption of user request data submitted to the portal service by the terminal in the last counting period, and the local traffic consumption is traffic consumption of user request data submitted to the service instance by the terminal in the current counting period.
In some optional implementations of this embodiment, in the second determining unit 502, obtaining the current traffic consumption of the terminal includes: and sending an asynchronous query request to the counting service node to acquire the global traffic consumption of the terminal sent by the counting service node based on the asynchronous query request in the last counting period. And acquiring the local traffic consumption of the terminal in the current counting period from a preset storage position.
In some optional implementations of this embodiment, in the second determining unit 502, determining whether to discard the user request data according to the size relationship between the current traffic consumption and the subscription traffic of the terminal includes: responsive to determining that the global traffic consumption is empty and the local traffic consumption is greater than the subscription traffic, it is determined to discard the user request data. Responsive to determining that the global traffic consumption is non-null and the global traffic consumption is greater than the subscription traffic, it is determined to discard the user request data.
In some optional implementations of this embodiment, the load threshold includes a first threshold, a second threshold, and a third threshold, and the current traffic consumption further includes a plurality of backup traffic consumption, where the plurality of backup traffic consumption is traffic consumption of user request data submitted by the terminal to the portal service in a plurality of historical count periods other than the last count period, respectively. And the second determining unit 502 is further configured to: responsive to determining that the current load is greater than the first threshold and less than the second threshold and that the global traffic consumption and/or the local traffic consumption in the current traffic consumption is greater than the contracted traffic, user request data is discarded. And discarding the user request data in response to determining that the current load is greater than the second threshold and less than the third threshold and that the backup traffic consumption is greater than the subscription traffic or the global traffic consumption is greater than the subscription traffic among the plurality of backup traffic consumptions in the current traffic consumption.
In some alternative implementations of the present embodiment, the apparatus may further include a third determining unit (not shown in the figure). The third determining unit may be configured to determine not to discard the user request data in response to determining that the current load amount does not exceed the load threshold.
In some alternative implementations of the present embodiment, the apparatus may further include a step execution unit (not shown in the figures). The step execution unit may be configured to, in response to determining not to discard the user request data, execute the steps of: first, the current load amount is updated. Then, the required flow rate required by the user to request the requested content in the data is determined, and the local flow rate consumption of the current counting period is updated according to the required flow rate. And finally, based on the terminal identity identification and the required traffic of the terminal, encoding to obtain counting information, storing the obtained counting information into a counting information queue, wherein the counting information queue is a lock-free queue with a fixed-length memory, and sending the counting information in the counting information queue to a counting service node for counting so as to obtain the global traffic consumption of the current counting period.
In some optional implementations of this embodiment, in the step execution unit, sending the count information in the count information queue to the count service node for counting includes: based on a preset processing period, merging all counting information corresponding to the terminal identity in the counting information queue to obtain the counting information of the corresponding terminal, and sending the counting information of the terminal to a counting service node.
In some optional implementations of this embodiment, the global traffic consumption for the current counting period is counted via the counting service node by: and receiving counting information, and storing the received counting information to a preset first data storage structure which is a lock-free data structure by taking the terminal as granularity. And in response to determining that the current moment is the end of the counting period, counting the total flow of the terminal in the first data storage structure, taking the total flow as the global flow consumption of the current counting period, storing the data stored in the first data storage structure into a second data storage structure in a preset second data storage structure group, deleting the data stored in the first data storage structure, wherein the second data storage structure in the second data storage structure group is a lock-free data structure.
In some alternative implementations of the present embodiment, before storing the data stored in the first data storage structure in the second data storage structure of the predetermined set of second data storage structures, the method further includes: in response to determining that the number of occupied second data storage structures in the second set of data storage structures exceeds a preset number threshold, deleting data stored in a second data storage structure in the second set of data storage structures that is currently occupied for a longest period of time.
In the apparatus provided in the foregoing embodiments of the present disclosure, the first determining unit 501 determines whether the current load amount exceeds the load threshold in response to receiving the user request data sent by the terminal. The second determining unit 502 obtains the current flow consumption of the terminal in response to determining that the current load exceeds the load threshold, and determines whether to discard the user request data according to the magnitude relation between the current flow consumption of the terminal and the subscription flow. According to the device, the entrance service is the service which responds to the user request data first in the multi-stage service, and each service instance of the entrance service of the multi-stage service determines whether to discard the user request data, so that the flow can be controlled from the source of the flow, the flow load of each service instance of the entrance service can be ensured to be kept in a relatively stable range, the flow load of each service after the entrance service can be ensured to be kept in a relatively stable range, and the stability of the system is improved. In addition, each service instance of the portal service determines whether to discard the user request data by combining two factors of the current load capacity of the service instance and the current flow consumption of the terminal, ensures the use of the subscription flow of the user as much as possible in the processing capacity range of the service instance, can realize fair and reasonable discarding of the user request data, and is beneficial to realizing effective utilization of data processing resources.
Referring now to fig. 6, a schematic diagram of an architecture of an electronic device (e.g., service node in fig. 1) 600 suitable for use in implementing embodiments of the present disclosure is shown. The electronic device shown in fig. 6 is merely an example and should not impose any limitations on the functionality and scope of use of embodiments of the present disclosure.
As shown in fig. 6, the electronic device 600 may include a processing means (e.g., a Central Processing Unit (CPU), a graphics processor, etc.) 601, which may perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 602 or a program loaded from a storage means 608 into a Random Access Memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the electronic apparatus 600 are also stored. The processing device 601, the ROM 602, and the RAM 603 are connected to each other through a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
In general, the following devices may be connected to the I/O interface 605: input devices 606 including, for example, a touch screen, touchpad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, and the like; an output device 607 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage 608 including, for example, magnetic tape, hard disk, etc.; and a communication device 609. The communication means 609 may allow the electronic device 600 to communicate with other devices wirelessly or by wire to exchange data. While fig. 6 shows an electronic device 600 having various means, it is to be understood that not all of the illustrated means are required to be implemented or provided. More or fewer devices may be implemented or provided instead. Each block shown in fig. 6 may represent one device or a plurality of devices as needed.
In particular, according to embodiments of the present disclosure, the processes described above with reference to flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method shown in the flowcharts. In such an embodiment, the computer program may be downloaded and installed from a network via communication means 609, or from storage means 608, or from ROM 602. The above-described functions defined in the methods of the embodiments of the present disclosure are performed when the computer program is executed by the processing means 601. It should be noted that the computer readable medium of the embodiments of the present disclosure may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In an embodiment of the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. Whereas in embodiments of the present disclosure, the computer-readable signal medium may comprise a data signal propagated in baseband or as part of a carrier wave, with computer-readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, fiber optic cables, RF (radio frequency), and the like, or any suitable combination of the foregoing.
The computer readable medium may be contained in the electronic device; or may exist alone without being incorporated into the electronic device. The computer readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to: in response to receiving user request data sent by a terminal, determining whether the current load exceeds a load threshold; and responding to the fact that the current load exceeds the load threshold, obtaining the current flow consumption of the terminal, and determining whether to discard the user request data according to the relation between the current flow consumption of the terminal and the signed flow.
Computer program code for carrying out operations of embodiments of the present disclosure may be written in one or more programming languages, including an object oriented programming language such as Java, smalltalk, C ++ and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computer (for example, through the Internet using an Internet service provider).
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units involved in the embodiments described in the present disclosure may be implemented by means of software, or may be implemented by means of hardware. The described units may also be provided in a processor, for example, described as: a processor includes a first determination unit and a second determination unit. The names of these units do not constitute a limitation on the unit itself in some cases, for example, the first determining unit may also be described as "a unit that determines whether the current load amount exceeds the load threshold value in response to receiving user request data transmitted by the terminal".
The foregoing description is only of the preferred embodiments of the present disclosure and description of the principles of the technology being employed. It will be appreciated by those skilled in the art that the scope of the invention referred to in this disclosure is not limited to the specific combination of features described above, but encompasses other embodiments in which features described above or their equivalents may be combined in any way without departing from the spirit of the invention. Such as those described above, are mutually substituted with the technical features having similar functions disclosed in the present disclosure (but not limited thereto).

Claims (18)

1. A method for controlling traffic, applied to a service instance of an ingress service in a multi-level service, wherein the method comprises:
in response to receiving user request data sent by a terminal, determining whether the current load exceeds a load threshold;
in response to determining that the current load exceeds a load threshold, acquiring current flow consumption of the terminal, and determining whether to discard the user request data according to the magnitude relation between the current flow consumption of the terminal and the contracted flow;
wherein, the obtaining the current traffic consumption of the terminal includes: sending an asynchronous query request to a counting service node to acquire global traffic consumption of the terminal sent by the counting service node based on the asynchronous query request in the last counting period; and acquiring local traffic consumption of the terminal in the current counting period from a preset storage position, wherein the global traffic consumption is traffic consumption of user request data submitted to an entrance service by the terminal in the last counting period, and the local traffic consumption is traffic consumption of user request data submitted to the service instance by the terminal in the current counting period.
2. The method of claim 1, wherein the determining whether to discard the user request data according to the size relationship between the current traffic consumption of the terminal and the subscription traffic comprises:
responsive to determining that global traffic consumption is empty and local traffic consumption is greater than the contracted traffic, determining to discard the user request data;
responsive to determining that global traffic consumption is non-null and global traffic consumption is greater than the subscription traffic, it is determined to discard the user request data.
3. The method of claim 1, wherein the load threshold comprises a first threshold, a second threshold, and a third threshold, the current traffic consumption further comprising a plurality of backup traffic consumptions, the plurality of backup traffic consumptions being traffic consumptions of user request data submitted by the terminal to an ingress service in a plurality of historical count periods, respectively, other than a last count period; and
the step of responding to the determination that the current load exceeds the load threshold value, obtaining the current flow consumption of the terminal, and determining whether to discard the user request data according to the magnitude relation between the current flow consumption of the terminal and the contracted flow, wherein the step of including:
discarding the user request data in response to determining that the current load is greater than a first threshold and less than a second threshold and that the global traffic consumption and/or the local traffic consumption in the current traffic consumption is greater than the contracted traffic;
And discarding the user request data in response to determining that the current load is greater than a second threshold and less than a third threshold and that backup traffic consumption is greater than the subscription traffic or the global traffic consumption is greater than the subscription traffic among the plurality of backup traffic consumptions in the current traffic consumption.
4. The method of claim 1, wherein the method further comprises: in response to determining that the current load amount does not exceed the load threshold, it is determined not to discard the user request data.
5. The method of claim 4, wherein the method further comprises:
in response to determining not to discard the user request data, performing the steps of:
updating the current load;
determining a required flow of the requested content in the user request data, and updating the local flow consumption of the current counting period according to the required flow;
based on the terminal identity of the terminal and the demand flow, coding to obtain counting information, storing the obtained counting information into a counting information queue, wherein the counting information queue is a lock-free queue with a fixed-length memory, and sending the counting information in the counting information queue to a counting service node for counting so as to obtain global flow consumption of a current counting period.
6. The method of claim 5, wherein the sending the count information in the count information queue to a count service node for counting comprises:
and combining all the counting information corresponding to the terminal identity in the counting information queue based on a preset processing period to obtain the counting information corresponding to the terminal, and sending the counting information of the terminal to the counting service node.
7. Method according to one of claims 5-6, wherein the global traffic consumption of the current counting period is counted via a counting service node by:
receiving counting information, and storing the received counting information to a preset first data storage structure by taking a terminal as granularity, wherein the first data storage structure is a lock-free data structure;
in response to determining that the current time is the end of a counting period, counting the total flow of the terminal in the first data storage structure, taking the total flow as the global flow consumption of the current counting period, storing the data stored in the first data storage structure into a second data storage structure in a preset second data storage structure group, deleting the data stored in the first data storage structure, wherein the second data storage structure in the second data storage structure group is a lock-free data structure.
8. The method of claim 7, wherein prior to said storing the data stored by the first data storage structure in the second data storage structure of the set of predetermined second data storage structures, further comprising:
and deleting the data stored in the second data storage structure with the longest currently occupied duration in the second data storage structure group in response to determining that the number of occupied second data storage structures in the second data storage structure group exceeds a preset number threshold.
9. An apparatus for controlling traffic, applied to any service instance processing unit of a service node, the service instance processing unit being configured to run service instances of ingress services in a multi-level service, wherein the apparatus comprises:
a first determining unit configured to determine whether a current load amount exceeds a load threshold in response to receiving user request data transmitted by a terminal;
the second determining unit is configured to respond to the fact that the current load exceeds a load threshold value, obtain current flow consumption of the terminal, and determine whether to discard the user request data according to the size relation between the current flow consumption of the terminal and the signed flow;
In the second determining unit, the obtaining the current traffic consumption of the terminal includes: sending an asynchronous query request to a counting service node to acquire global traffic consumption of the terminal sent by the counting service node based on the asynchronous query request in the last counting period; obtaining the local traffic consumption of the terminal in the current counting period from a preset storage position, wherein,
the global traffic consumption is the traffic consumption of user request data submitted to the portal service by the terminal in the last counting period, and the local traffic consumption is the traffic consumption of user request data submitted to the service instance by the terminal in the current counting period.
10. The apparatus of claim 9, wherein the determining, in the second determining unit, whether to discard the user request data according to a magnitude relation between current traffic consumption of the terminal and subscription traffic, includes:
responsive to determining that global traffic consumption is empty and local traffic consumption is greater than the contracted traffic, determining to discard the user request data;
responsive to determining that global traffic consumption is non-null and global traffic consumption is greater than the subscription traffic, it is determined to discard the user request data.
11. The apparatus of claim 9, wherein the load threshold comprises a first threshold, a second threshold, and a third threshold, the current traffic consumption further comprising a plurality of backup traffic consumptions, the plurality of backup traffic consumptions being traffic consumptions of user request data submitted by the terminal to an ingress service in a plurality of historical count periods, respectively, other than a last count period; and
the second determination unit is further configured to:
discarding the user request data in response to determining that the current load is greater than a first threshold and less than a second threshold and that the global traffic consumption and/or the local traffic consumption in the current traffic consumption is greater than the contracted traffic;
and discarding the user request data in response to determining that the current load is greater than a second threshold and less than a third threshold and that backup traffic consumption is greater than the subscription traffic or the global traffic consumption is greater than the subscription traffic among the plurality of backup traffic consumptions in the current traffic consumption.
12. The apparatus of claim 9, wherein the apparatus further comprises:
and a third determining unit configured to determine not to discard the user request data in response to determining that the current load amount does not exceed the load threshold.
13. The apparatus of claim 12, wherein the apparatus further comprises:
a step execution unit configured to execute, in response to determining not to discard the user request data, the steps of:
updating the current load;
determining a required flow of the requested content in the user request data, and updating the local flow consumption of the current counting period according to the required flow;
based on the terminal identity of the terminal and the demand flow, coding to obtain counting information, storing the obtained counting information into a counting information queue, wherein the counting information queue is a lock-free queue with a fixed-length memory, and sending the counting information in the counting information queue to a counting service node for counting so as to obtain global flow consumption of a current counting period.
14. The apparatus of claim 13, wherein the step of sending the count information in the count information queue to a count service node for counting comprises:
and combining all the counting information corresponding to the terminal identity in the counting information queue based on a preset processing period to obtain the counting information corresponding to the terminal, and sending the counting information of the terminal to the counting service node.
15. The apparatus according to one of claims 13-14, wherein the global traffic consumption of the current counting period is counted via a counting service node by:
receiving counting information, and storing the received counting information to a preset first data storage structure by taking a terminal as granularity, wherein the first data storage structure is a lock-free data structure;
in response to determining that the current time is the end of a counting period, counting the total flow of the terminal in the first data storage structure, taking the total flow as the global flow consumption of the current counting period, storing the data stored in the first data storage structure into a second data storage structure in a preset second data storage structure group, deleting the data stored in the first data storage structure, wherein the second data storage structure in the second data storage structure group is a lock-free data structure.
16. The apparatus of claim 15, wherein prior to said storing the data stored by the first data storage structure into a second data storage structure of a set of predetermined second data storage structures, further comprising:
And deleting the data stored in the second data storage structure with the longest currently occupied duration in the second data storage structure group in response to determining that the number of occupied second data storage structures in the second data storage structure group exceeds a preset number threshold.
17. An electronic device, comprising:
one or more processors;
a storage device having one or more programs stored thereon,
when executed by the one or more processors, causes the one or more processors to implement the method of any of claims 1-8.
18. A computer readable medium having stored thereon a computer program, wherein the program when executed by a processor implements the method of any of claims 1-8.
CN201910758905.8A 2019-08-16 2019-08-16 Method and device for controlling flow Active CN110430142B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910758905.8A CN110430142B (en) 2019-08-16 2019-08-16 Method and device for controlling flow

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910758905.8A CN110430142B (en) 2019-08-16 2019-08-16 Method and device for controlling flow

Publications (2)

Publication Number Publication Date
CN110430142A CN110430142A (en) 2019-11-08
CN110430142B true CN110430142B (en) 2023-07-18

Family

ID=68415105

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910758905.8A Active CN110430142B (en) 2019-08-16 2019-08-16 Method and device for controlling flow

Country Status (1)

Country Link
CN (1) CN110430142B (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114710447B (en) * 2020-12-16 2024-05-03 百寻信息科技(上海)有限公司 Balanced advertisement flow control method and system
CN113965519B (en) * 2021-09-06 2024-01-26 阿里巴巴(中国)有限公司 Flow control and cluster resource guarantee method, equipment and storage medium
CN114590656B (en) * 2022-01-30 2024-03-26 云知声智能科技股份有限公司 Elevator control method, device, electronic equipment and storage medium
CN115134301B (en) * 2022-06-29 2024-04-05 中国工商银行股份有限公司 Flow control method, flow control device, computer equipment and storage medium

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1642136A (en) * 2004-01-17 2005-07-20 华为技术有限公司 Data flow band width control method
CN104303473A (en) * 2013-05-06 2015-01-21 华为技术有限公司 Flow control method and apparatus of operator sharing network
CN105577573A (en) * 2015-12-31 2016-05-11 联想(北京)有限公司 Information processing method and electronic device
CN106059940A (en) * 2016-05-25 2016-10-26 杭州昆海信息技术有限公司 Flow control method and device
CN106302211A (en) * 2016-07-18 2017-01-04 网易无尾熊(杭州)科技有限公司 The request amount control method of a kind of Internet resources and device
CN107770088A (en) * 2017-09-06 2018-03-06 阿里巴巴集团控股有限公司 A kind of flow control methods and device
CN108173938A (en) * 2017-12-28 2018-06-15 泰康保险集团股份有限公司 Server load shunt method and device
CN108768870A (en) * 2018-05-04 2018-11-06 Oppo广东移动通信有限公司 Flow control methods, device and mobile terminal
CN110008050A (en) * 2019-04-11 2019-07-12 北京百度网讯科技有限公司 Method and apparatus for handling information

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107613528B (en) * 2016-07-11 2021-01-29 华为技术有限公司 Method and system for controlling service flow

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1642136A (en) * 2004-01-17 2005-07-20 华为技术有限公司 Data flow band width control method
CN104303473A (en) * 2013-05-06 2015-01-21 华为技术有限公司 Flow control method and apparatus of operator sharing network
CN105577573A (en) * 2015-12-31 2016-05-11 联想(北京)有限公司 Information processing method and electronic device
CN106059940A (en) * 2016-05-25 2016-10-26 杭州昆海信息技术有限公司 Flow control method and device
CN106302211A (en) * 2016-07-18 2017-01-04 网易无尾熊(杭州)科技有限公司 The request amount control method of a kind of Internet resources and device
CN107770088A (en) * 2017-09-06 2018-03-06 阿里巴巴集团控股有限公司 A kind of flow control methods and device
CN108173938A (en) * 2017-12-28 2018-06-15 泰康保险集团股份有限公司 Server load shunt method and device
CN108768870A (en) * 2018-05-04 2018-11-06 Oppo广东移动通信有限公司 Flow control methods, device and mobile terminal
CN110008050A (en) * 2019-04-11 2019-07-12 北京百度网讯科技有限公司 Method and apparatus for handling information

Also Published As

Publication number Publication date
CN110430142A (en) 2019-11-08

Similar Documents

Publication Publication Date Title
CN110430142B (en) Method and device for controlling flow
US20200328984A1 (en) Method and apparatus for allocating resource
US9497288B2 (en) Subscriber based priority of messages in a publisher-subscriber domain
CN111221638B (en) Concurrent task scheduling processing method, device, equipment and medium
CN111240834B (en) Task execution method, device, electronic equipment and storage medium
CN112035529B (en) Caching method, caching device, electronic equipment and computer readable storage medium
CN111432001B (en) Method, apparatus, electronic device and computer readable medium for jumping scenes
CN112379982B (en) Task processing method, device, electronic equipment and computer readable storage medium
CN114020470A (en) Resource allocation method, device, readable medium and electronic equipment
CN110795446A (en) List updating method and device, readable medium and electronic equipment
CN113760991A (en) Data operation method and device, electronic equipment and computer readable medium
CN111026552B (en) Resource scheduling method and device, electronic equipment and computer readable storage medium
CN110401731B (en) Method and apparatus for distributing content distribution nodes
CN109918381B (en) Method and apparatus for storing data
CN112418389A (en) Data processing method and device, electronic equipment and computer readable storage medium
CN114915663B (en) Request response method, device, system, electronic equipment and medium
CN111756833B (en) Node processing method, node processing device, electronic equipment and computer readable medium
CN111459893B (en) File processing method and device and electronic equipment
CN110825342A (en) Memory scheduling device and system, method and apparatus for processing information
CN110187987B (en) Method and apparatus for processing requests
CN112860439A (en) Application starting method and device, terminal and storage medium
CN110633141A (en) Memory management method and device of application program, terminal equipment and medium
CN115174588B (en) Bandwidth control method, device, apparatus, storage medium and program product
CN117520228B (en) Command processing method, device, equipment and computer readable storage medium
CN116932225B (en) Micro-service resource scheduling method, micro-service resource scheduling device, electronic equipment and computer readable medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant