Disclosure of Invention
The embodiment of the disclosure at least provides a flow control method and a flow control device.
In a first aspect, an embodiment of the present disclosure provides a flow control method, including:
monitoring a flow value generated in a unit time of a target system;
recording the monitored flow value which is greater than or equal to a first preset threshold value and the time interval between the monitored flow value and the target flow value recorded last time is smaller than a preset time interval as a target flow value;
when the number of the target flow values is larger than or equal to a preset number, adjusting the upper flow limit of the target system based on the target flow values; wherein the traffic cap is used to control the number of users accessing the target system; the upper flow limit is greater than the first preset threshold.
In an optional embodiment, the recording the monitored flow value greater than or equal to the first preset threshold and having a time interval with the last recorded target flow value smaller than a preset time interval as the target flow value comprises:
sequentially writing the monitored flow values to be written which are greater than or equal to the first preset threshold value into a target queue for recording target flow values;
when monitoring a new flow value to be written, if the number of the target flow values stored in the target queue reaches the preset number, deleting the target flow value written first in the target queue, and then writing the new flow value to be written into the target queue;
and if the time interval between the new flow value to be written and the latest target flow value in the target queue is monitored to be larger than the preset time interval, emptying the target queue, and writing the new flow value to be written into the emptied target queue.
In an optional embodiment, the adjusting the upper flow limit of the target system based on the target flow value includes:
determining the average value of the latest preset number of target flow values in the target flow values;
determining a target flow upper limit value corresponding to the average value based on the average value;
and adjusting the flow upper limit of the target system based on the target flow upper limit value.
In an optional implementation manner, the determining, based on the average value, a target upper flow limit value corresponding to the average value includes:
and determining the target flow upper limit value corresponding to the average value based on the threshold value interval where the average value is located and the target flow upper limit values corresponding to different threshold value intervals.
In an optional implementation manner, the determining, based on the average value, a target upper flow limit value corresponding to the average value includes:
determining a correction weight of the upper flow limit based on the average value;
and determining the target flow upper limit based on the correction weight and the first preset threshold.
In an optional implementation manner, the determining, based on the average value, a target upper flow limit value corresponding to the average value includes:
and if the average value is larger than a second preset threshold, taking a preset flow upper limit value corresponding to the second preset threshold as the target flow upper limit value.
In a second aspect, an embodiment of the present disclosure further provides a flow control device, including:
the monitoring module is used for monitoring a flow value generated in unit time of a target system;
the recording module is used for recording the monitored flow value which is greater than or equal to a first preset threshold value and the time interval between the monitored flow value and the target flow value recorded last time is smaller than the preset time interval as the target flow value;
the adjusting module is used for adjusting the upper flow limit of the target system based on the target flow value when the number of the target flow values is larger than or equal to the preset number; wherein the traffic cap is used to control the number of users accessing the target system; the upper flow limit is greater than the first preset threshold.
In an optional implementation manner, the recording module is specifically configured to:
sequentially writing the monitored flow values to be written which are greater than or equal to the first preset threshold value into a target queue for recording target flow values;
when monitoring a new flow value to be written, if the number of the target flow values stored in the target queue reaches the preset number, deleting the target flow value written first in the target queue, and then writing the new flow value to be written into the target queue;
and if the time interval between the new flow value to be written and the latest target flow value in the target queue is monitored to be larger than the preset time interval, emptying the target queue, and writing the new flow value to be written into the emptied target queue.
In an optional implementation manner, the adjusting module is specifically configured to:
determining the average value of the latest preset number of target flow values in the target flow values;
determining a target flow upper limit value corresponding to the average value based on the average value;
and adjusting the flow upper limit of the target system based on the target flow upper limit value.
In an optional implementation manner, when determining the target flow upper limit value corresponding to the average value based on the average value, the adjusting module is specifically configured to:
and determining the target flow upper limit value corresponding to the average value based on the threshold value interval where the average value is located and the target flow upper limit values corresponding to different threshold value intervals.
In an optional implementation manner, when determining the target flow upper limit value corresponding to the average value based on the average value, the adjusting module is specifically configured to:
determining a correction weight of the upper flow limit based on the average value;
and determining the target flow upper limit based on the correction weight and the first preset threshold.
In an optional implementation manner, when determining the target flow upper limit value corresponding to the average value based on the average value, the adjusting module is specifically configured to:
and if the average value is larger than a second preset threshold, taking a preset flow upper limit value corresponding to the second preset threshold as the target flow upper limit value.
In a third aspect, an embodiment of the present disclosure further provides a computer device, including: a processor, a memory and a bus, the memory storing machine-readable instructions executable by the processor, the processor and the memory communicating via the bus when the computer device is running, the machine-readable instructions when executed by the processor performing the steps of the first aspect described above, or any possible implementation of the first aspect.
In a fourth aspect, this disclosed embodiment also provides a computer-readable storage medium, on which a computer program is stored, where the computer program is executed by a processor to perform the steps in the first aspect or any one of the possible implementation manners of the first aspect.
For the description of the effects of the flow control device, the computer device, and the computer readable storage medium, reference is made to the description of the flow control method, which is not repeated herein.
The flow control method and the flow control device provided by the embodiment of the disclosure can detect the flow value generated in the unit time of the target system, record the flow value which is greater than or equal to the first preset threshold and has the time interval with the target flow value recorded last time smaller than the preset time interval as the target flow value, and adjust the upper flow limit of the target system based on the target flow value when the number of the target flow values is greater than or equal to the preset number. Because the time interval between the recorded adjacent target flow values is smaller than the preset time interval and is greater than or equal to the first preset threshold, the high flow rate of the target system in a short time can be effectively reflected and the target system is in a risk state; furthermore, when the number of the target flow values is greater than or equal to the preset number, the upper flow limit of the target system is adjusted according to the recorded target flow values, so that the situation that the upper flow limit of the target system is reduced due to transient fluctuation of the flow can be reduced, and the target system can provide more stable service.
In order to make the aforementioned objects, features and advantages of the present disclosure more comprehensible, preferred embodiments accompanied with figures are described in detail below.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present disclosure more clear, the technical solutions of the embodiments of the present disclosure will be described clearly and completely with reference to the drawings in the embodiments of the present disclosure, and it is obvious that the described embodiments are only a part of the embodiments of the present disclosure, not all of the embodiments. The components of the embodiments of the present disclosure, generally described and illustrated in the figures herein, can be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present disclosure, presented in the figures, is not intended to limit the scope of the claimed disclosure, but is merely representative of selected embodiments of the disclosure. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the disclosure without making creative efforts, shall fall within the protection scope of the disclosure.
Research shows that in order to protect the normal operation of the system, the flow of the system is generally limited when a large number of access or call requests exist, and the upper limit value of the processing request of the system in unit time is reduced, so that the system processes the limited request in the same time, and the operation pressure of the system is further reduced. The upper limit of the flow is limited to cause that the processing of some requests is delayed, the efficiency of the system for processing the requests is reduced, when the flow control is performed, the flow of the system is usually monitored, and when the flow higher than the safety threshold is monitored, the upper limit of the flow of the system is adjusted, the flow of the system often fluctuates briefly, and suddenly increases in a short period of time and then returns to normal, at this time, the system is usually judged to be in a risk state, and the upper limit of the flow is adjusted, but the system is not actually in the risk state, so that the working efficiency of the system is reduced. Therefore, how to ensure the working efficiency and safety of the system at the same time becomes an important problem in the technical field.
Based on the above research, the embodiments of the present disclosure provide a flow control method, where a time interval between adjacent recorded target flow values is smaller than a preset time interval and greater than or equal to a first preset threshold, so that it can be effectively reflected that a target system is at a risk state and has a high flow rate in a short time; furthermore, when the number of the target flow values is greater than or equal to the preset number, the upper flow limit of the target system is adjusted according to the recorded target flow values, so that the situation that the upper flow limit of the target system is reduced due to transient fluctuation of the flow can be reduced, and the target system can provide more stable service.
The above-mentioned drawbacks are the results of the inventor after practical and careful study, and therefore, the discovery process of the above-mentioned problems and the solutions proposed by the present disclosure to the above-mentioned problems should be the contribution of the inventor in the process of the present disclosure.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures.
To facilitate understanding of the present embodiment, first, a flow control method disclosed in an embodiment of the present disclosure is described in detail, where an execution subject of the flow control method provided in an embodiment of the present disclosure is generally a computer device with certain computing capability, and the computer device includes, for example: terminal devices or servers or other processing devices, and the servers may be distributed servers. The following describes a flow control method provided in the embodiments of the present disclosure by taking an execution subject as a server.
Referring to fig. 1, a flowchart of a flow control method provided in the embodiment of the present disclosure is shown, where the method includes steps S101 to S103, where:
s101: and monitoring the flow value generated by the target system in unit time.
In this step, the flow value generated by the target system in a unit time may be continuously monitored, where the unit time may be 1 second, and the flow value may be the number of access or call requests received by the target system in the unit time.
Here, the target system may be a distributed system, and the monitoring range may include a plurality of terminal devices in a cluster of the distributed system, and the plurality of terminal devices may be monitored by the same monitoring process.
S102: and recording the monitored flow value which is greater than or equal to the first preset threshold value and the time interval between the monitored flow value and the target flow value recorded last time is less than the preset time interval as the target flow value.
In this step, a monitored flow value that is greater than or equal to a first preset threshold and a time interval between the monitored flow value and a last recorded target flow value that is less than a preset time interval may be recorded as a target flow value, where the first preset threshold may be determined according to a flow value range that can be carried by a target system, for example, if the flow of the target system continues to exceed 5000 for a period of time and there is a risk of system crash, the first preset threshold may be set to a value lower than 5000, such as 4000, 4500, and the like.
In one possible implementation, step S102 may include:
sequentially writing the monitored flow values to be written which are greater than or equal to the first preset threshold value into a target queue for recording target flow values;
when monitoring a new flow value to be written, if the number of the target flow values stored in the target queue reaches the preset number, deleting the target flow value written first in the target queue, and then writing the new flow value to be written into the target queue;
and if the time interval between the new flow value to be written and the latest target flow value in the target queue is monitored to be larger than the preset time interval, emptying the target queue, and writing the new flow value to be written into the emptied target queue.
In this step, when the traffic value to be written which is greater than or equal to the first preset threshold value is monitored, the traffic value to be written may be written into the target queue, and the traffic value stored in the target queue is the target traffic value. The target queue may store a plurality of target traffic values, and the target traffic values in the target queue may be in chronological order.
For example, the upper limit (team) of the target queue capable of storing the traffic value may be set to 3 or 5, and when the length of team is 5, the target queue may occupy 7 storage spaces, where 5 storage spaces may be used to store the traffic value respectively, 1 storage space may be used to store the average value of the target traffic value, 1 storage space may be used to store the timestamp of the latest recorded target traffic value, each storage space may be of a positive type int, and occupies 4 bytes, and the space complexity is low.
Here, the number of storage spaces in the target queue for storing the traffic value may coincide with a preset number. When a new flow to be written is monitored, if the storage space of the target queue is full, the target flow which is written into the target queue firstly can be deleted, so that the target flow value stored in the target queue is kept in the latest state.
Further, if the time interval between the new flow value to be written and the latest target flow value in the target queue is monitored to be larger than the preset time interval, emptying the target queue, and writing the new flow value to be written into the target queue.
Illustratively, the preset time interval may be 30 minutes. When the time interval between the flow value to be written and the latest target flow value is greater than the preset time interval, the time span between the two is considered to be too large, and pressure cannot be caused on the target system.
S103: when the number of the target flow values is larger than or equal to a preset number, adjusting the upper flow limit of the target system based on the target flow values; wherein the traffic cap is used to control the number of users accessing the target system; the upper flow limit is greater than the first preset threshold.
In this step, when the number of the target flow values is greater than or equal to the preset number, the upper limit of the flow of the target system may be adjusted according to the recorded target flow values.
When the number of the target flow values is larger than or equal to the preset number, the system is considered to have high flow for many times in a short time, and the system may be affected, and then flow control is started, and the upper limit of the flow of the target system is adjusted to protect the target system, so that the target system is prevented from being incapable of normally operating due to overhigh load.
In one possible embodiment, adjusting the upper flow limit of the target system based on the target flow value includes:
determining the average value of the latest preset number of target flow values in the target flow values;
determining a target flow upper limit value corresponding to the average value based on the average value;
and adjusting the flow upper limit of the target system based on the target flow upper limit value.
In the step, the average value of the target flow value is calculated, and then the target flow upper limit value is determined based on the average value, so that the average value can integrally reflect the overall flow level of the target system in a period of time, and the problem of error flow limitation caused by uneven instantaneous flow can be reduced.
In a possible implementation manner, determining, based on the average value, a target flow upper limit value corresponding to the average value may include:
and determining the target flow upper limit value corresponding to the average value based on the threshold value interval where the average value is located and the target flow upper limit values corresponding to different threshold value intervals.
In this way, different threshold intervals may be set according to the risk degree of the flow rate of different thresholds to the system, each threshold interval may correspond to a flow rate upper limit value, and when the average value of the target flow rate is in one threshold interval, the flow rate upper limit value corresponding to the threshold interval may be used as the target flow rate upper limit value.
In a possible implementation manner, determining, based on the average value, a target flow upper limit value corresponding to the average value may include:
determining a correction weight of the upper flow limit based on the average value;
and determining the target flow upper limit based on the correction weight and the first preset threshold.
In this way, the correction weight of the upper flow limit may be determined based on the ratio between the average value and the risk flow, and the correction weight may be smaller when the average value is larger, and the flow limit to the target system may be stronger when the average value is high.
Compared with a mode of determining the target flow upper limit value according to different threshold intervals, the target flow upper limit value determined by the mode can be better adapted to the current flow of the target system, and the system safety and the working efficiency can be better coordinated.
In a possible implementation manner, determining, based on the average value, a target flow upper limit value corresponding to the average value may include:
and if the average value is larger than a second preset threshold, taking a preset flow upper limit value corresponding to the second preset threshold as the target flow upper limit value.
In this step, the average value may be directly compared with a second preset threshold, and if the average value is greater than the second preset threshold, a preset upper flow limit corresponding to the second preset threshold is used as the target upper flow limit.
Compared with the mode of determining the target flow upper limit value according to different threshold intervals and the mode of determining the target flow upper limit value according to the correction weight, the mode needs less setting, and the second preset threshold and the preset flow upper limit value can be set to relatively conservative values, so that the safety of the system can be protected better.
The flow control method provided by the embodiment of the disclosure can detect the flow value generated in the unit time of the target system, record the flow value which is greater than or equal to the first preset threshold and has the time interval with the last recorded target flow value smaller than the preset time interval as the target flow value, and adjust the upper flow limit of the target system based on the target flow value when the number of the target flow values is greater than or equal to the preset number. Because the time interval between the recorded adjacent target flow values is smaller than the preset time interval and is greater than or equal to the first preset threshold, the high flow rate of the target system in a short time can be effectively reflected and the target system is in a risk state; furthermore, when the number of the target flow values is greater than or equal to the preset number, the upper flow limit of the target system is adjusted according to the recorded target flow values, so that the situation that the upper flow limit of the target system is reduced due to transient fluctuation of the flow can be reduced, and the target system can provide more stable service.
It will be understood by those skilled in the art that in the method of the present invention, the order of writing the steps does not imply a strict order of execution and any limitations on the implementation, and the specific order of execution of the steps should be determined by their function and possible inherent logic.
Based on the same inventive concept, a traffic processing device corresponding to the traffic processing method is also provided in the embodiments of the present disclosure, and because the principle of solving the problem of the device in the embodiments of the present disclosure is similar to the traffic processing method in the embodiments of the present disclosure, the implementation of the device may refer to the implementation of the method, and repeated details are not described again.
Referring to fig. 2, which is a schematic diagram of an architecture of a traffic processing apparatus according to an embodiment of the present disclosure, the traffic processing apparatus 200 includes: a monitoring module 210, a recording module 220, and an adjusting module 230; wherein the content of the first and second substances,
a monitoring module 210 for monitoring a flow value generated by the target system in a unit time;
the recording module 220 is configured to record, as a target flow value, a flow value that is greater than or equal to a first preset threshold and has a time interval with a target flow value that is recorded last time that is less than a preset time interval;
an adjusting module 230, configured to adjust an upper flow limit of the target system based on the target flow value when the number of the target flow values is greater than or equal to a preset number; wherein the traffic cap is used to control the number of users accessing the target system; the upper flow limit is greater than the first preset threshold.
In the embodiment of the disclosure, the time interval between the recorded adjacent target flow values is smaller than the preset time interval and is greater than or equal to the first preset threshold, so that the high flow of the target system in a short time can be effectively reflected and the target system is in a risk state; furthermore, when the number of the target flow values is greater than or equal to the preset number, the upper flow limit of the target system is adjusted according to the recorded target flow values, so that the situation that the upper flow limit of the target system is reduced due to transient fluctuation of the flow can be reduced, and the target system can provide more stable service.
In an optional implementation manner, the recording module 220 is specifically configured to:
sequentially writing the monitored flow values to be written which are greater than or equal to the first preset threshold value into a target queue for recording target flow values;
when monitoring a new flow value to be written, if the number of the target flow values stored in the target queue reaches the preset number, deleting the target flow value written first in the target queue, and then writing the new flow value to be written into the target queue;
and if the time interval between the new flow value to be written and the latest target flow value in the target queue is monitored to be larger than the preset time interval, emptying the target queue, and writing the new flow value to be written into the emptied target queue.
In an optional implementation manner, the adjusting module 230 is specifically configured to:
determining the average value of the latest preset number of target flow values in the target flow values;
determining a target flow upper limit value corresponding to the average value based on the average value;
and adjusting the flow upper limit of the target system based on the target flow upper limit value.
In an optional implementation manner, when determining the target flow upper limit value corresponding to the average value based on the average value, the adjusting module 230 is specifically configured to:
and determining the target flow upper limit value corresponding to the average value based on the threshold value interval where the average value is located and the target flow upper limit values corresponding to different threshold value intervals.
In an optional implementation manner, when determining the target flow upper limit value corresponding to the average value based on the average value, the adjusting module 230 is specifically configured to:
determining a correction weight of the upper flow limit based on the average value;
and determining the target flow upper limit based on the correction weight and the first preset threshold.
In an optional implementation manner, when determining the target flow upper limit value corresponding to the average value based on the average value, the adjusting module 230 is specifically configured to:
and if the average value is larger than a second preset threshold, taking a preset flow upper limit value corresponding to the second preset threshold as the target flow upper limit value.
The description of the processing flow of each module in the device and the interaction flow between the modules may refer to the related description in the above method embodiments, and will not be described in detail here.
Based on the same technical concept, the embodiment of the disclosure also provides computer equipment. Referring to fig. 3, a schematic structural diagram of a computer device 300 provided in the embodiment of the present disclosure includes a processor 301, a memory 302, and a bus 303. The memory 302 is used for storing execution instructions and includes a memory 3021 and an external memory 3022; the memory 3021 is also referred to as an internal memory, and is used for temporarily storing operation data in the processor 301 and data exchanged with an external memory 3022 such as a hard disk, the processor 301 exchanges data with the external memory 3022 through the memory 3021, and when the computer device 300 is operated, the processor 301 communicates with the memory 302 through the bus 303, so that the processor 301 executes the following instructions:
monitoring a flow value generated in a unit time of a target system;
recording the monitored flow value which is greater than or equal to a first preset threshold value and the time interval between the monitored flow value and the target flow value recorded last time is smaller than a preset time interval as a target flow value;
when the number of the target flow values is larger than or equal to a preset number, adjusting the upper flow limit of the target system based on the target flow values; wherein the traffic cap is used to control the number of users accessing the target system; the upper flow limit is greater than the first preset threshold.
In one possible embodiment, the instructions executed by the processor 301 to record, as the target flow value, the monitored flow value that is greater than or equal to the first preset threshold and whose time interval with the last recorded target flow value is smaller than the preset time interval include:
sequentially writing the monitored flow values to be written which are greater than or equal to the first preset threshold value into a target queue for recording target flow values;
when monitoring a new flow value to be written, if the number of the target flow values stored in the target queue reaches the preset number, deleting the target flow value written first in the target queue, and then writing the new flow value to be written into the target queue;
and if the time interval between the new flow value to be written and the latest target flow value in the target queue is monitored to be larger than the preset time interval, emptying the target queue, and writing the new flow value to be written into the emptied target queue.
In one possible embodiment, the processor 301 executes instructions that, when adjusting the upper flow limit of the target system based on the target flow value, include:
determining the average value of the latest preset number of target flow values in the target flow values;
determining a target flow upper limit value corresponding to the average value based on the average value;
and adjusting the flow upper limit of the target system based on the target flow upper limit value.
In a possible implementation, the determining, by the processor 301, the target upper flow limit value corresponding to the average value based on the average value includes:
and determining the target flow upper limit value corresponding to the average value based on the threshold value interval where the average value is located and the target flow upper limit values corresponding to different threshold value intervals.
In a possible implementation, the determining, by the processor 301, the target upper flow limit value corresponding to the average value based on the average value includes:
determining a correction weight of the upper flow limit based on the average value;
and determining the target flow upper limit based on the correction weight and the first preset threshold.
In a possible implementation, the determining, by the processor 301, the target upper flow limit value corresponding to the average value based on the average value includes:
and if the average value is larger than a second preset threshold, taking a preset flow upper limit value corresponding to the second preset threshold as the target flow upper limit value.
The embodiments of the present disclosure also provide a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the computer program performs the steps of the flow control method in the foregoing method embodiments. The storage medium may be a volatile or non-volatile computer-readable storage medium.
The embodiments of the present disclosure also provide a computer program product, where the computer program product carries a program code, and instructions included in the program code may be used to execute the steps of the flow control method in the foregoing method embodiments, which may be referred to specifically for the foregoing method embodiments, and are not described herein again.
The computer program product may be implemented by hardware, software or a combination thereof. In an alternative embodiment, the computer program product is embodied in a computer storage medium, and in another alternative embodiment, the computer program product is embodied in a Software product, such as a Software Development Kit (SDK), or the like.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the system and the apparatus described above may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again. In the several embodiments provided in the present disclosure, it should be understood that the disclosed system, apparatus, and method may be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one logical division, and there may be other divisions when actually implemented, and for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection of devices or units through some communication interfaces, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present disclosure may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a non-volatile computer-readable storage medium executable by a processor. Based on such understanding, the technical solution of the present disclosure may be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present disclosure. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
Finally, it should be noted that: the above-mentioned embodiments are merely specific embodiments of the present disclosure, which are used for illustrating the technical solutions of the present disclosure and not for limiting the same, and the scope of the present disclosure is not limited thereto, and although the present disclosure is described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: any person skilled in the art can modify or easily conceive of the technical solutions described in the foregoing embodiments or equivalent technical features thereof within the technical scope of the present disclosure; such modifications, changes or substitutions do not depart from the spirit and scope of the embodiments of the present disclosure, and should be construed as being included therein. Therefore, the protection scope of the present disclosure shall be subject to the protection scope of the claims.