Bandwidth traffic control method, electronic equipment and storage medium
The Nginx server periodically reports real-time bandwidth traffic and controls the traffic based on the total traffic and speed limit quota. This solves the problem of service processing capacity decline caused by the synchronous blocking method, and realizes efficient asynchronous non-blocking traffic management.
Patent Information
- Application Number
- CN202311244041.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-25
- Publication Date
- 2025-03-25
AI Technical Summary
In the prior art, threads in the server thread pool in the synchronous blocking method will be occupied by current-limited requests for a long time, resulting in a decrease in service processing capabilities.
The Nginx server periodically reports the current real-time bandwidth traffic associated with the target user to the flow control center of each node in the cluster. The flow control center feedbacks the total traffic of the cluster and the speed limit quota of the target user. The Nginx server controls the traffic associated with each node in the cluster and the target user based on this information in the next cycle.
It realizes an asynchronous non-blocking flow control process, improves the processing capability of request services, and avoids the problem of long-term thread occupation.
Smart Images

Figure CN119697119A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a bandwidth flow control method, electronic device and storage medium. Background Art
[0002] Currently, bandwidth flow control is developed based on the application framework. The speed limit process is synchronous blocking, which means putting the current thread to sleep, pausing the upload and download of the request. For the blocking speed limit process, the threads in the server thread pool will be occupied by the flow-limited requests for a long time, resulting in a decrease in service processing capacity. Summary of the invention
[0003] The present application provides a bandwidth flow control method, an electronic device and a storage medium to solve the problem in the prior art that threads of a server thread pool in a synchronous blocking manner may be occupied for a long time by flow-limited requests, resulting in a decrease in service processing capacity.
[0004] In a first aspect, the present application provides a method for controlling bandwidth flow, comprising: an Nginx server periodically reports to a flow control center the real-time bandwidth flow of each node in a cluster currently associated with a target user; wherein the cluster comprises one or more Nginx servers and one or more flow control centers, and one Nginx server is associated with one or more nodes; the Nginx server receives the total cluster flow and the speed limit quota of the target user fed back by the flow control center; and the Nginx server controls the flow associated with each node in the cluster with the target user based on the total cluster flow and the speed limit quota in the next cycle.
[0005] In the second aspect, the present application provides a method for controlling bandwidth flow, including: a flow control center receives the real-time bandwidth flow of each node in the cluster currently associated with the target user, which is periodically reported by the Nginx server; wherein the cluster includes one or more Nginx servers and one or more flow control centers, and one Nginx server is associated with one or more nodes; the flow control center feeds back the total cluster flow and the speed limit quota of the target user to the Nginx server.
[0006] In a third aspect, the present application provides an electronic device comprising: at least one communication interface; at least one bus connected to the at least one communication interface; at least one processor connected to the at least one bus; and at least one memory connected to the at least one bus, wherein the processor is configured to execute the traffic control method described in the first or second aspect of the present application.
[0007] In a fourth aspect, the present application further provides a computer storage medium storing computer executable instructions, wherein the computer executable instructions are used to execute the flow control method described in the first aspect or the second aspect of the present application.
[0008] The above technical solution provided by the embodiment of the present application has the following advantages compared with the prior art: through the method provided by the embodiment of the present application, the Nginx server can periodically report the real-time bandwidth flow of each node in the cluster currently associated with the target user to the flow control center, and then in the next cycle, the flow associated with the target user of each node in the cluster can be controlled; it can be seen that in the embodiment of the present application, the flow of each node in the group is periodically controlled by the Nginx server. If the balance between the total flow of the cluster and the speed limit quota is still not reached in the current cycle, the flow control is performed again in the next cycle after the Nginx server periodically reports. It can be seen that in the embodiment of the present application, the flow control process is an asynchronous non-blocking processing process, which improves the processing capacity of the request service and avoids the problem that the threads of the server thread pool in the synchronous blocking mode in the prior art will be occupied by the flow-limited request for a long time, resulting in a decrease in the service processing capacity. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0010] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0011] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and unless otherwise stated, the figures in the drawings do not constitute proportional limitations.
[0012] Figure 1 One of the flow charts of a bandwidth flow control method provided in an embodiment of the present application;
[0013] Figure 2 A schematic diagram of the structure of the Nginx server and the flow control center provided in the embodiment of the present application;
[0014] Figure 3 A schematic diagram of the structure of the Nginx server provided in the embodiment of the present application;
[0015] Figure 4 A schematic diagram of the structure of the flow control center provided in the embodiment of the present application;
[0016] Figure 5 A schematic diagram of a structure in which a shared memory is divided into zones according to an embodiment of the present application;
[0017] Figure 6 A schematic diagram of parsing a quadruple from a shared memory provided in an embodiment of the present application;
[0018] Figure 7 A schematic diagram of speed limit based on Nginx server provided in an embodiment of the present application;
[0019] Figure 8 A second flowchart of a method for controlling bandwidth flow provided in an embodiment of the present application;
[0020] Fig. 9 One of the structural schematic diagrams of a bandwidth flow control device provided in an embodiment of the present application;
[0021] Fig.10 A second structural diagram of a bandwidth flow control device provided in an embodiment of the present application;
[0022] Fig.11 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0023] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0024] The disclosure below provides many different embodiments or examples to implement different structures of the present invention. In order to simplify the disclosure of the present invention, the parts and settings of specific examples are described below. Of course, they are only examples, and the purpose is not to limit the present invention. In addition, the present invention can repeat reference numbers and / or letters in different examples. This repetition is for the purpose of simplification and clarity, and does not itself indicate the relationship between the various embodiments and / or settings discussed.
[0025] Figure 1 A flow chart of a method for controlling bandwidth flow provided in an embodiment of the present application is shown in FIG. Figure 1 As shown, the steps of the method include:
[0026] Step 101, the Nginx server periodically reports the real-time bandwidth traffic currently associated with the target user of each node in the cluster to the traffic control center; wherein the cluster includes one or more Nginx servers and one or more traffic control centers, and one Nginx server is associated with one or more nodes;
[0027] It should be noted that the Nginx server is a lightweight Web server / reverse proxy server and email (IMAP / POP3) proxy server, which is characterized by small memory usage and strong concurrency capabilities.
[0028] In addition, the node in the embodiment of the present application may refer to a specific user device or a server. In the specific example, the structure of the Nginx server and the flow control center is as follows: Figure 2 As shown in the figure, there are multiple Nginx servers in a cluster, and all of them are connected to the flow control center (Flowcenter). Zookeeper is the configuration center and the master selection function of FlowCenter. Figure 3 As shown in Figure 2, the structure of the flow control center is as follows: Figure 4 shown.
[0029] Step 102: The Nginx server receives the total cluster traffic and the speed limit quota of the target user fed back by the traffic control center;
[0030] It should be noted that the current cluster may involve traffic of multiple users in the cluster, that is, the target user is any user associated with the cluster. Of course, in a specific example, the bandwidth traffic of multiple target users may also be targeted.
[0031] Step 103: The Nginx server controls the traffic associated with the target user at each node in the cluster based on the total traffic of the cluster and the speed limit quota in the next cycle.
[0032] Through the above steps 101 to 103, the Nginx server can periodically report the real-time bandwidth flow of each node in the cluster currently associated with the target user to the flow control center, and then control the flow associated with the target user of each node in the cluster in the next cycle; it can be seen that in the embodiment of the present application, the flow of each node in the group is periodically controlled by the Nginx server. If the balance between the total flow of the cluster and the speed limit quota is still not reached in the current cycle, the flow control is performed again in the next cycle after the Nginx server periodically reports. It can be seen that in the embodiment of the present application, the flow control process is an asynchronous non-blocking processing process, which improves the processing capacity of the request service and avoids the problem that the threads of the server thread pool in the synchronous blocking mode in the prior art will be occupied by the flow-limited request for a long time, resulting in a decrease in the service processing capacity.
[0033] In addition, since the Nginx server in the embodiment of the present application is associated with one or more nodes, the Nginx server associated with one or more nodes can still be correctly limited in the case of uneven user request traffic, so as to avoid the situation where the number of user requests is only dozens but the bandwidth can reach tens of Gb in a cluster of hundreds or thousands of nodes, but the user requests only access a few nodes. That is, through the method of the embodiment of the present application, correct flow limiting can be achieved in the scenario of uneven user traffic, rather than biasing the traffic to some nodes to cause traffic blockage.
[0034] In an optional implementation of the embodiment of the present application, the manner in which the Nginx server involved in the above step 101 periodically reports the real-time bandwidth flow of each node in the cluster currently associated with the target user to the flow control center may further include:
[0035] Step 11, the Nginx server obtains the request sent by the target user from the shared memory, and parses the request to obtain a four-tuple of the request, where the four-tuple includes the target user ID, the bucket name associated with the target user, the path for transmitting data, and the method for transmitting data;
[0036] It should be noted that the path used to transmit data in the embodiment of the present application refers to an upload path or a download path, and the method used to transmit data refers to transmitting data through an intranet or transmitting data through an extranet. In the specific example, taking the abd.jpg in test (bucket name) of user 10000 (user ID) as an example, the link of the access request is wgethttp: / / test.ks3-cn-beijing-internal.ksyun.com / abc.jpg. The four-tuple parsed based on the request link is: 10000:test:DOWNLOAD:LEN.
[0037] It can be seen that the object storage request in the embodiment of the present application includes buckets and file objects. Usually, the speed limit scenario is targeted at buckets or user granularity, and the source can be used to distinguish special identification sources such as public networks and intranets. Therefore, after the Nginx server receives the request, it needs to parse the requested quadruple and then formulate the speed limit rules according to the quadruple.
[0038] Step 12: The Nginx server reports the real-time bandwidth traffic currently associated with the target user of each node in the cluster to the flow control center based on the four-tuple.
[0039] It can be seen that in the embodiment of the present application, the corresponding four-tuple can be obtained by parsing the request, and then the flow control rules can be determined according to the four-tuple. For example, flow control can be performed based on user granularity, or flow control can be performed based on bucket granularity, that is, corresponding flow control can be performed according to actual needs. In addition, the four-tuple also includes the path for transmitting data and the method for transmitting data, so flow control can also be performed in combination with the actual scenario. For example, if the current upload flow is large, the flow based on the upload method can be controlled. If the current user A has a small demand for flow, the flow of user A can be further limited to leave the bandwidth for user B who needs it more; or if the current intranet flow pressure is large, flow control can also be performed for the intranet. For example, if the current intranet has a large demand for user C, the bandwidth of the user with a smaller demand can be further balanced to user C to ensure the normal transmission of user C's flow.
[0040] In an optional implementation manner of the embodiment of the present application, the method in which the Nginx server involved in step 11 in the embodiment of the present application obtains the request sent by the target user from the shared memory may further include:
[0041] Step 21, the Nginx server obtains the request sent by the target user from each area of the shared memory, wherein the shared memory is divided into multiple areas.
[0042] It should be noted that the Nginx shared memory in the embodiment of the present application is used as an efficient way to share data between processes. The shared memory is used to count the bandwidth flow data of each resource every second, and the resources are stored in the form of a red-black tree data structure. Since the shared memory is divided into zones, such as Figure 5 As shown, the data read and write of each zone must be synchronized with locks to ensure data consistency. In order to reduce the competition for different resource locks, multi-zone storage is designed, and resources select the corresponding zone through a consistent hashing algorithm. Based on this, in the specific example of the embodiment of the present application, the process of reporting traffic to the Nginx server is as follows: Figure 6 As shown in the figure, the request is parsed from the shared memory zone to obtain a four-tuple, and the obtained real-time traffic is reported to the flow control center, and then the flow control strategy is started: speed limit or recovery.
[0043] In an optional implementation of the embodiment of the present application, the Nginx server involved in the above step 103 controls the traffic associated with each node in the cluster and the target user based on the total traffic of the cluster and the speed limit quota in the next cycle, which may further include:
[0044] Step 31, the Nginx server controls the traffic associated with the target user at each node in the cluster based on the total traffic of the cluster and the speed limit quota based on the user ID in the next cycle; or,
[0045] Step 32: In the next cycle, the Nginx server controls the traffic associated with the target user on each node in the cluster based on the total traffic of the cluster and the speed limit quota based on the bucket name.
[0046] It can be known from the above steps 31 and 32 that in the embodiment of the present application, flow control can be performed at the user granularity or the bucket granularity. If both granularities exist at the same time, flow control is performed based on the priorities of the two. For example, if the priority of the user granularity is higher than the priority of the bucket granularity, flow control based on the user ID is prioritized. In a specific example, it can be: user 10000, quota is 100MB, of which the bucket test quota is 80MB; the actual bandwidth flow of user 10000 is 120MB, and the bucket test flow is 50MB, then the quota result of user 10000 is further speed limit (120MB: 100MB). In a specific example, Figure 7 As shown in the figure, the total traffic collected by the nodes in the cluster in the current cycle is 130M+100M+100M=330M, and the speed limit quota is 300M. Therefore, the nodes in the cluster need to limit the speed, that is, feedback (330M, 300M), where the first number in the bracket represents the current actual traffic, and the second number represents the quota. After feedback to NG, the traffic collected by each GN in the next cycle is 120M+100M+80M=300M, which meets the quota expectation. Figure 7 It can be seen that when speed limiting is performed, each NG has different speed limits on nodes. For example, some reduce 10M traffic, some reduce 20M traffic, and some do not reduce it. That is, when speed limiting is required, the speed limit can be set for the corresponding node according to the actual situation.
[0047] In an optional implementation of the embodiment of the present application, the Nginx server involved in the above step 103 controls the traffic associated with each node in the cluster and the target user based on the total traffic of the cluster and the speed limit quota in the next cycle, which may further include:
[0048] Step 41: When the total traffic of the cluster is greater than the speed limit quota, the Nginx server limits the speed of the traffic associated with the target user of each node in the cluster based on the total traffic of the cluster and the speed limit quota in the next cycle;
[0049] Step 42: When the total flow of the cluster is less than the speed limit quota, the Nginx server restores the flow associated with the target user of each node in the cluster based on the total flow of the cluster and the speed limit quota in the next cycle.
[0050] It can be seen that in the embodiment of the present application, the flow rate can be limited or restored periodically according to the current real-time flow rate, that is, when the current flow rate exceeds the quota, the flow rate needs to be limited, and when the current flow rate is less than the quota, the speed can be appropriately increased. Therefore, in the embodiment of the present application, balanced control of the flow rate can be achieved through periodic flow control.
[0051] Based on this, the method for the Nginx server involved in the above step 41 to limit the speed of the traffic associated with the target user of each node in the cluster based on the total traffic of the cluster and the speed limit quota in the next cycle may further include:
[0052] Step 51, when the total traffic of the cluster is greater than the first preset threshold, the Nginx server reduces the traffic associated with the target user of each node in the cluster to the first preset ratio based on the total traffic of the cluster and the speed limit quota in the next cycle;
[0053] Step 52, when the total traffic of the cluster is greater than the second preset threshold, the Nginx server continues to reduce the traffic associated with the target user of each node in the cluster to the second preset ratio based on the total traffic of the cluster and the speed limit quota in the next cycle;
[0054] The first preset threshold is greater than the second preset threshold, and the second preset threshold is greater than the total traffic of the cluster; the first preset ratio is less than the second preset ratio, and the second preset ratio is less than 1.
[0055] In a specific example, the first preset threshold may be 1.2, and the second preset threshold may be 1.01; the value of the first preset ratio may be 0.75, and the value of the second preset ratio may be 0.9. Of course, the values of the first preset threshold, the second preset threshold, the first preset ratio, and the second preset ratio are all examples, and may be set accordingly according to actual needs. In addition, it should be noted that in the embodiment of the present application, the speed limiting process may be speed limited based on the token bucket algorithm, and the execution process is: obtain the size of the data stream currently received by the request; obtain the token bucket token, and calculate the speed limit duration; if the speed limit duration > 0, suspend the current request.
[0056] Through the above steps 51 and 52, when the total flow of the cluster exceeds the preset quota, the flow of the current node can be periodically limited. For example, if the current total flow of the cluster exceeds the preset quota by a large amount, a fast convergence speed limit strategy can be executed, that is, the value of the first preset ratio is set lower, such as 0.75, that is, the current flow can be directly limited to the original 0.75. After fast convergence, slow convergence can be performed. Because the current total flow of the cluster is close to the quota, the second convergence ratio can be adjusted at this time. The value of the second preset ratio is set higher, such as 0.9, that is, the current flow can be directly limited to the original 0.9. However, when limiting the speed, the preset ratios are all less than 1.
[0057] In an optional implementation of the embodiment of the present application, the Nginx server involved in the above step 42 restores the traffic associated with each node in the cluster and the target user based on the total traffic of the cluster and the speed limit quota in the next cycle, which may further include:
[0058] Step 61, when the total traffic of the cluster is less than the third preset threshold, the Nginx server increases the traffic associated with the target user of each node in the cluster to a third preset ratio based on the total traffic of the cluster and the speed limit quota in the next cycle;
[0059] Step 62, when the total traffic of the cluster is less than the fourth preset threshold, the Nginx server continues to increase the traffic associated with the target user of each node in the cluster to the fourth preset ratio based on the total traffic of the cluster and the speed limit quota in the next cycle;
[0060] Among them, the third preset threshold is less than the fourth preset threshold, and the fourth preset threshold is less than the total cluster traffic; the third preset ratio is greater than the fourth preset ratio, and the fourth preset ratio is greater than 1.
[0061] In a specific example, the third preset threshold may be 0.5, and the fourth preset threshold may be 0.9; the value of the third preset ratio may be 1.1, and the value of the fourth preset ratio may be 1.05. Of course, the values of the first preset threshold, the second preset threshold, the first preset ratio, and the second preset ratio are all examples, and can be set accordingly according to actual needs.
[0062] Through the above steps 61 and 62, when the total cluster traffic does not exceed the preset quota, the traffic of the current node can be periodically restored. For example, if the current total cluster traffic is much lower than the preset quota, the fast recovery speed limit strategy can be executed, that is, the value of the third preset ratio is set lower, such as 1.1, that is, the current traffic can be directly restored to the original 1.1, and slow recovery can be performed after fast recovery. Because the current total cluster traffic is close to the quota, the second convergence ratio can be adjusted at this time, and the value of the fourth preset ratio is set lower, such as 1.05, that is, the current traffic can be directly restored to the original 1.05, but the preset ratios are all greater than 1 when limiting the speed.
[0063] In the specific example, the values of the various thresholds or ratios of the speed limit and recovery are shown in Table 1.
[0064] Table 1
[0065] Strategy Classification Cluster traffic and thresholds Traffic (node traffic * ratio) Fast Convergence Greater than quota*1.2 0.75 Slow convergence Greater than quota*1.01 0.9 Super Recovery Less than quota*0.5 - Fast recovery Less than quota*0.9 1.1 Slow recovery Less than quota 1.05 Allow floating range Less than quota*1.01 1
[0066] Corresponding to the above Figure 1 The present application also provides a method for controlling bandwidth flow, such as Figure 8 As shown, the steps of the method include:
[0067] Step 801, the flow control center receives the real-time bandwidth flow of each node in the cluster currently associated with the target user, which is periodically reported by the Nginx server; wherein the cluster includes one or more Nginx servers and one or more flow control centers, and one Nginx server is associated with one or more nodes;
[0068] Step 802: The flow control center feeds back the total flow of the cluster and the speed limit quota of the target user to the Nginx server.
[0069] It can be seen that in the embodiment of the present application, the flow of each node in the group is periodically controlled by the Nginx server. If the balance between the total flow of the cluster and the speed limit quota is still not reached in the current cycle, the flow control is performed again in the next cycle after the Nginx server periodically reports. It can be seen that in the embodiment of the present application, the flow control process is an asynchronous non-blocking processing process, which improves the processing capacity of the request service and avoids the problem in the prior art that the threads of the server thread pool in the synchronous blocking mode will be occupied by the flow-limited requests for a long time, resulting in a decrease in the service processing capacity.
[0070] Corresponding to the above Figure 1 The present application embodiment provides a bandwidth flow control device, which is applied to an Nginx server, such as Fig. 9 As shown, the device comprises:
[0071] The reporting module 902 is used to periodically report the real-time bandwidth flow of each node in the cluster currently associated with the target user to the flow control center; wherein the cluster includes one or more Nginx servers and one or more flow control centers, and one Nginx server is associated with one or more nodes;
[0072] The first receiving module 904 is used to receive the total cluster traffic and the speed limit quota of the target user fed back by the flow control center;
[0073] The control module 906 is used to control the traffic associated with the target user of each node in the cluster based on the total traffic of the cluster and the speed limit quota in the next cycle.
[0074] It can be seen that in the embodiment of the present application, the flow of each node in the group is periodically controlled by the Nginx server. If the balance between the total flow of the cluster and the speed limit quota is still not reached in the current cycle, the flow control is performed again in the next cycle after the Nginx server periodically reports. It can be seen that in the embodiment of the present application, the flow control process is an asynchronous non-blocking processing process, which improves the processing capacity of the request service and avoids the problem in the prior art that the threads of the server thread pool in the synchronous blocking mode will be occupied by the flow-limited requests for a long time, resulting in a decrease in the service processing capacity.
[0075] In an optional implementation of an embodiment of the present application, the reporting module 902 in the embodiment of the present application may further include: a processing unit, used to obtain the request sent by the target user from the shared memory, and parse the request to obtain a quadruple of the request, wherein the quadruple includes the target user ID, the bucket name associated with the target user, the path for transmitting data, and the method for transmitting data; a reporting unit, used to report the real-time bandwidth traffic currently associated with the target user of each node in the cluster to the flow control center based on the quadruple.
[0076] In an optional implementation of the embodiment of the present application, the processing unit in the embodiment of the present application may further include: a processing subunit, used to obtain the request sent by the target user from each area of the shared memory, wherein the shared memory is divided into multiple areas.
[0077] In an optional implementation manner of an embodiment of the present application, the control module 906 in the embodiment of the present application may further include: a first control unit, used to control the traffic associated with each node in the cluster and the target user based on the total cluster traffic and the speed limit quota based on the user ID in the next cycle; or, a first control unit, used to control the traffic associated with each node in the cluster and the target user based on the bucket name based on the total cluster traffic and the speed limit quota in the next cycle.
[0078] In an optional implementation manner of an embodiment of the present application, the control module 906 in the embodiment of the present application may further include: a speed limiting unit, which is used to limit the traffic associated with each node in the cluster and the target user based on the total cluster traffic and the speed limit quota in the next cycle when the total cluster traffic is greater than the speed limit quota; and a recovery unit, which is used to restore the traffic associated with each node in the cluster and the target user based on the total cluster traffic and the speed limit quota in the next cycle when the total cluster traffic is less than the speed limit quota.
[0079] In an optional implementation manner of the embodiment of the present application, the speed limiting unit in the embodiment of the present application may further include: a first speed limiting sub-unit, which is used for, when the total cluster traffic is greater than a first preset threshold, the Nginx server to reduce the traffic associated with each node in the cluster and the target user to a first preset ratio based on the total cluster traffic and the speed limit quota in the next cycle; a second speed limiting sub-unit, which is used for, when the total cluster traffic is greater than a second preset threshold, to continue to reduce the traffic associated with each node in the cluster and the target user to a second preset ratio based on the total cluster traffic and the speed limit quota in the next cycle; wherein the first preset threshold is greater than the second preset threshold, and the second preset threshold is greater than the total cluster traffic; the first preset ratio is less than the second preset ratio, and the second preset ratio is less than 1.
[0080] In an optional implementation manner of an embodiment of the present application, the recovery unit in the embodiment of the present application may further include: a first recovery unit, used to increase the traffic associated with each node in the cluster and the target user to a third preset ratio based on the total cluster traffic and the speed limit quota in the next cycle when the total cluster traffic is less than a third preset threshold; a second recovery unit, used to cause the Nginx server to continue to increase the traffic associated with each node in the cluster and the target user to a fourth preset ratio based on the total cluster traffic and the speed limit quota in the next cycle when the total cluster traffic is less than a fourth preset threshold; wherein the third preset threshold is less than the fourth preset threshold, and the fourth preset threshold is less than the total cluster traffic; the third preset ratio is greater than the fourth preset ratio, and the fourth preset ratio is greater than 1.
[0081] Corresponding to the above Figure 8 The present application embodiment provides a bandwidth flow control device, which is applied to a flow control center, such as Fig.10 As shown, the device comprises:
[0082] The second receiving module 1002 is used to receive the real-time bandwidth traffic of each node in the cluster currently associated with the target user, which is periodically reported by the Nginx server; wherein the cluster includes one or more Nginx servers and one or more flow control centers, and one Nginx server is associated with one or more nodes;
[0083] Feedback module 1004 is used to feed back the total cluster traffic and the speed limit quota of the target user to the Nginx server.
[0084] It can be seen that, through the device of the embodiment of the present application, the flow of each node in the group is periodically controlled. If the balance between the total flow of the cluster and the speed limit quota is still not reached in the current cycle, the flow control is performed again in the next cycle after the Nginx server periodically reports. It can be seen that in the embodiment of the present application, the flow control process is an asynchronous non-blocking processing process, which improves the processing capacity of the request service and avoids the problem that the threads of the server thread pool in the synchronous blocking mode in the prior art will be occupied by the flow-limited requests for a long time, resulting in a decrease in the service processing capacity.
[0085] like Fig.11 As shown, an embodiment of the present application provides an electronic device, including a processor 111, a communication interface 112, a memory 113 and a communication bus 114, wherein the processor 111, the communication interface 112, and the memory 113 communicate with each other through the communication bus 114.
[0086] Memory 113, used for storing computer programs;
[0087] In one embodiment of the present application, the processor 111 is used to execute the program stored in the memory 113 to implement the bandwidth flow control method provided by any of the aforementioned method embodiments, and the role it plays is similar and will not be repeated here.
[0088] An embodiment of the present application further provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the bandwidth flow control method provided in any of the aforementioned method embodiments are implemented.
[0089] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0090] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a general hardware platform, and of course, by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0091] It should be understood that the terms used herein are only for the purpose of describing specific example embodiments and are not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms "one", "an" and "said" as used herein may also be meant to include plural forms. The terms "include", "comprise", "contain", and "have" are inclusive, and therefore specify the existence of stated features, steps, operations, elements and / or parts, but do not exclude the existence or addition of one or more other features, steps, operations, elements, parts, and / or combinations thereof. The method steps, processes, and operations described herein are not interpreted as necessarily requiring them to be performed in the specific order described or illustrated, unless the execution order is clearly indicated. It should also be understood that additional or alternative steps may be used.
[0092] The foregoing is merely a specific embodiment of the present invention, which enables those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A method for controlling bandwidth flow, characterized in that: include: The Nginx server periodically reports the real-time bandwidth traffic currently associated with the target user of each node in the cluster to the flow control center; wherein the cluster includes one or more Nginx servers and one or more flow control centers, and one Nginx server is associated with one or more nodes; The Nginx server receives the total cluster traffic and the speed limit quota of the target user fed back by the flow control center; The Nginx server controls the traffic associated with the target user of each node in the cluster based on the total traffic of the cluster and the speed limit quota in the next cycle.
2. The method according to claim 1, characterized in that The Nginx server periodically reports the real-time bandwidth traffic of each node in the cluster currently associated with the target user to the traffic control center, including: The Nginx server obtains the request sent by the target user from the shared memory, and parses the request to obtain a quadruple of the request, wherein the quadruple includes the target user ID, the bucket name associated with the target user, the path for transmitting data, and the method for transmitting data; The Nginx server reports the real-time bandwidth flow of each node in the cluster currently associated with the target user to the flow control center based on the four-tuple.
3. The method according to claim 2, characterized in that The Nginx server obtains the request sent by the target user from the shared memory, including: The Nginx server obtains the request sent by the target user from each area of the shared memory, wherein the shared memory is divided into multiple areas.
4. The method according to claim 2, characterized in that: The Nginx server controls the traffic associated with the target user at each node in the cluster based on the total traffic of the cluster and the speed limit quota in the next cycle, including: The Nginx server controls the traffic associated with the target user at each node in the cluster based on the total traffic of the cluster and the speed limit quota based on the user ID in the next cycle; or, In the next cycle, the Nginx server controls the traffic associated with the target user of each node in the cluster based on the total traffic of the cluster and the speed limit quota based on the bucket name.
5. The method according to claim 1, characterized in that: The Nginx server controls the traffic associated with the target user at each node in the cluster based on the total traffic of the cluster and the speed limit quota in the next cycle, including: When the total traffic of the cluster is greater than the speed limit quota, the Nginx server limits the speed of the traffic associated with the target user of each node in the cluster based on the total traffic of the cluster and the speed limit quota in the next cycle; When the total flow of the cluster is less than the speed limit quota, the Nginx server restores the flow associated with the target user of each node in the cluster based on the total flow of the cluster and the speed limit quota in the next cycle.
6. The method according to claim 5, characterized in that The Nginx server limits the speed of the traffic associated with the target user at each node in the cluster based on the total traffic of the cluster and the speed limit quota in the next cycle, including: When the total traffic of the cluster is greater than the first preset threshold, the Nginx server reduces the traffic associated with the target user of each node in the cluster to a first preset ratio based on the total traffic of the cluster and the speed limit quota in the next cycle; When the total flow of the cluster is greater than the second preset threshold, the Nginx server continues to reduce the flow associated with the target user of each node in the cluster to a second preset ratio based on the total flow of the cluster and the speed limit quota in the next cycle; The first preset threshold is greater than the second preset threshold, and the second preset threshold is greater than the total traffic of the cluster; the first preset ratio is less than the second preset ratio, and the second preset ratio is less than 1.
7. The method according to claim 5, characterized in that The Nginx server restores the traffic associated with the target user at each node in the cluster based on the total traffic of the cluster and the speed limit quota in the next cycle, including: When the total traffic of the cluster is less than the third preset threshold, the Nginx server increases the traffic associated with the target user of each node in the cluster to a third preset ratio based on the total traffic of the cluster and the speed limit quota in the next cycle; When the total flow of the cluster is less than the fourth preset threshold, the Nginx server continues to increase the flow associated with the target user of each node in the cluster to a fourth preset ratio based on the total flow of the cluster and the speed limit quota in the next cycle; The third preset threshold is smaller than the fourth preset threshold, and the fourth preset threshold is smaller than the total traffic of the cluster; the third preset ratio is larger than the fourth preset ratio, and the fourth preset ratio is larger than 1.
8. A method for controlling bandwidth flow, characterized in that: include: The flow control center receives the real-time bandwidth traffic of each node in the cluster currently associated with the target user, which is periodically reported by the Nginx server; wherein the cluster includes one or more Nginx servers and one or more flow control centers, and one Nginx server is associated with one or more nodes; The flow control center feeds back the total cluster flow and the speed limit quota of the target user to the Nginx server.
9. An electronic device, comprising: at least one communication interface; at least one bus connected to the at least one communication interface; at least one processor coupled to the at least one bus; At least one memory connected to the at least one bus, wherein the processor is configured to execute the bandwidth flow control method described in any one of claims 1 to 7 of the present application, or to execute the bandwidth flow control method described in claim 8 of the present application.
10. A computer storage medium storing computer executable instructions, wherein the computer executable instructions are used to execute the bandwidth flow control method described in any one of claims 1 to 7 of the present application, or to execute the bandwidth flow control method described in claim 8 of the present application.