Server CPU current limiting method and device
By monitoring the CPU utilization rate of the server and adjusting the request quota value using the harmony multiplication, generating a random number to control request access, the problem of unstable current limiting effect in the existing technology is solved, and the smooth control of the server request volume is achieved , improves the stability and user experience of the server.
Patent Information
- Application Number
- CN202411103798.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-12
- Publication Date
- 2024-12-03
AI Technical Summary
The existing server-side current limiting method is difficult to implement when facing complex online environments, has a narrow scope of application, and cannot achieve stable current limiting effect, and cannot effectively control the server CPU load.
By monitoring the CPU utilization of the server, adjusting the request quota value using the harmonious growth multiplication, generating a random number based on the real-time quota value to allow or prohibit request access, and implementing adaptive current limit control.
It realizes smooth control of the number of requests on the server, avoids the one-size-fits-all current limiting problem in the existing technology, and improves the stability and user experience of the server.
Smart Images

Figure CN119071245A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of Internet technology, and in particular to a method and device for limiting CPU current at a server end. Background Art
[0002] When users access the server, they send requests to the server. When there are too many requests to the server, the server will be under too much pressure, and problems such as the failure to load the client page normally will occur. Current limiting is a technical solution that discards some requests when the service load or QPS (Queries-per-second) exceeds a certain load (level) to control the data or service access rate and protect the core system of the service path from being dragged down. It is an overload protection method for the server.
[0003] The existing current limiting method is to limit the requests of a single process or a single user within a certain period of time. It requires stress testing the system first, and it is limited to the situation where the online business and machine environment are basically the same before this current limiting method can be reused. However, for complex online environments, this rigid current limiting method is difficult to implement, has a narrow scope of application, and needs to be adjusted for each business. Furthermore, the existing current limiting method directly prohibits entry when the load exceeds a certain level, and releases it when the system load recovers, making it impossible to achieve a stable current limiting effect. Summary of the invention
[0004] In view of the above problems, embodiments of the present application are proposed to provide a method and device for limiting CPU current on a server side that overcomes the above problems or at least partially solves the above problems.
[0005] According to a first aspect of an embodiment of the present application, a server CPU current limiting method is provided, which includes:
[0006] Determine the initial credit value requested by the server, initialize the real-time credit value based on the initial credit value, and determine the value range of the requested random number based on the initial credit value;
[0007] Obtaining the CPU utilization of the server according to a preset time interval, comparing the CPU utilization with a preset utilization threshold, and obtaining a first comparison result;
[0008] According to the first comparison result, the real-time quota value is adjusted by using the sum growth multiplication reduction;
[0009] For any request to the server, a request random number corresponding to the request is generated based on the value range of the request random number, and the request to access the server is allowed or prohibited according to the second comparison result between the request random number and the real-time quota value.
[0010] Optionally, determining an initial credit value requested by the server, initializing a real-time credit value according to the initial credit value, and determining a value range of a requested random number according to the initial credit value further includes:
[0011] Obtaining the number of historical requests from the server, and calculating the initial credit value of the server request according to the number of historical requests according to a first preset ratio; and / or, setting the initial credit value of the server request according to a dynamic setting interface;
[0012] Assign the real-time quota value to the initial quota value;
[0013] The maximum value of the requested random number is set as the initial quota value, and the minimum value of the requested random number is set as the minimum preset threshold.
[0014] Optionally, according to the first comparison result, adjusting the real-time quota value by using the sum growth multiplication reduction further includes:
[0015] If the CPU utilization is greater than or equal to the preset utilization threshold, the real-time quota value is multiplied by the multiplication factor to reduce the real-time quota value; the multiplication factor is greater than 0 and less than 1;
[0016] If the CPU utilization is less than the preset utilization threshold, the utilization and efficiency factor is added to the real-time quota value to increase the real-time quota value; the utilization and efficiency factor is determined according to the initial quota value according to the second preset ratio.
[0017] Optionally, adding the sum factor to the real-time credit value to increase the real-time credit value further includes:
[0018] The real-time credit limit value is added with the sum factor to obtain the adjusted real-time credit limit value;
[0019] The adjusted real-time credit limit value is compared with the initial credit limit value. If it is greater than the initial credit limit value, the adjusted real-time credit limit value is updated to the initial credit limit value.
[0020] Optionally, for any request to the server, generating a request random number corresponding to the request based on a value range of the request random number further includes:
[0021] For any request to the server, a random algorithm is used to generate a request random number corresponding to the request within the value range of the request random number.
[0022] Optionally, according to the second comparison result between the request random number and the real-time quota value, allowing or prohibiting the request to access the server further includes:
[0023] If the requested random number is less than or equal to the real-time quota value, the request is allowed to access the server;
[0024] If the requested random number is greater than the real-time quota value, the request to access the server is prohibited.
[0025] Optionally, there are multiple servers;
[0026] If the request to access the server is prohibited, the method further includes:
[0027] Distribute the request to other servers, and let other servers determine whether to allow or prohibit the request to access other servers.
[0028] According to a second aspect of an embodiment of the present application, a server-side CPU current limiting device is provided, comprising:
[0029] An initialization module, adapted to determine an initial credit value requested by the server, initialize a real-time credit value according to the initial credit value, and determine a value range of a requested random number according to the initial credit value;
[0030] A first comparison module, adapted to obtain the CPU utilization of the server according to a preset time interval, compare the CPU utilization with a preset utilization threshold, and obtain a first comparison result;
[0031] An adjustment module adapted to adjust the real-time quota value by using a summation growth multiplication reduction according to the first comparison result;
[0032] The permission and prohibition module is suitable for generating a request random number corresponding to the request based on the value range of the request random number for any request to the server, and allowing or prohibiting the request to access the server according to the second comparison result between the request random number and the real-time quota value.
[0033] According to a third aspect of an embodiment of the present application, there is provided a computing device, comprising: a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus;
[0034] The memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute operations corresponding to the above-mentioned server-side CPU current limiting method.
[0035] According to a fourth aspect of an embodiment of the present application, a computer storage medium is provided, wherein at least one executable instruction is stored in the storage medium, and the executable instruction enables a processor to perform operations corresponding to the above-mentioned server-side CPU current limiting method.
[0036] According to a fifth aspect of an embodiment of the present application, a computer program product is provided, comprising at least one executable instruction, wherein the executable instruction enables a processor to perform operations corresponding to the above-mentioned server-side CPU current limiting method.
[0037] According to the server CPU current limiting method and device provided by the present application, by regularly monitoring the CPU utilization, the request amount can be adjusted in real time according to the CPU utilization. Based on the comparison between the CPU utilization and the preset utilization threshold, the real-time quota value of the server request is adaptively adjusted according to the sum growth multiplication reduction, and the request amount can be stably controlled according to the real-time quota value and the request random number generated by the request, solving the existing problem of unstable current limiting.
[0038] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present application. Also, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0040] Figure 1 A flow chart of a method for limiting CPU current at a server end according to an embodiment of the present application is shown;
[0041] Figure 2 A schematic diagram showing the mapping relationship between requests and CPU utilization upper limit;
[0042] Figure 3 A flow chart of a method for limiting CPU current on a server side according to another embodiment of the present application is shown;
[0043] Figure 4 A schematic diagram of the structure of a CPU current limiting device at a server end according to an embodiment of the present application is shown;
[0044] Figure 5 A schematic diagram of the structure of a computing device according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0045] The exemplary embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present application and to fully convey the scope of the present application to those skilled in the art.
[0046] First, the terms involved in one or more embodiments of the present application are explained.
[0047] CDN: Content Delivery Network is a technology that deploys nodes at the edge of the network to cache the static resources of the website on edge nodes closer to the users, thereby improving user access speed, reducing bandwidth consumption, and increasing concurrent capacity.
[0048] AIMD: additive-increase / multiplicative-decrease, a feedback control algorithm used to dynamically adjust a control variable in certain systems to achieve a balance between maintaining stability and avoiding excessive use of resources. Each time period or each iteration, the control variable increases by a fixed increment. When the system detects some kind of "congestion" or overload phenomenon (for example, resource utilization exceeds a certain threshold), the control variable is reduced at a fixed ratio.
[0049] Figure 1 A flow chart of a method for limiting CPU current at a server end according to an embodiment of the present application is shown. Figure 1 As shown, the method comprises the following steps:
[0050] Step S101, determining the initial credit value requested by the server, initializing the real-time credit value according to the initial credit value, and determining the value range of the requested random number according to the initial credit value.
[0051] Offline services based on CDN can undertake different services, such as live broadcast services, on-demand services and other different types of services. For the server, the server requests it receives are also different. For example, a request of 10,000 bytes and a request of 1,000 bytes consume different amounts of CPU on the server. For limiting the flow of server requests, if the server is limited to accepting xx requests within 1 second, this flow limiting method of fixed request values is too rigid for online business scenarios. Different requests consume different amounts of CPU. If the flow limiting method is used across the board, CPU resources cannot be fully utilized and more requests cannot be processed in a timely manner.
[0052] Considering the above problems, this embodiment uses an adaptive method to control requests according to CPU utilization, so as to fully utilize CPU resources, process more requests, and improve throughput. In this embodiment, the flow limit of server requests takes QPS as an example, such as limiting the query rate per second of QPS, but it is not limited to QPS, and can also be applied to the flow limit of various resources such as bandwidth.
[0053] Before monitoring CPU utilization, determine the initial quota value of the server request. If the initial quota value is too small, the number of prohibited requests will be too small when the number of requests is adjusted later, which will not alleviate the problem of high CPU utilization, or the number of allowed requests will be too small, which will not fully utilize CPU resources. The size of the initial quota value affects the size of the subsequent adjustment of the request amount.
[0054] For the setting of the initial credit value, it can be set according to the historical number of server requests. The historical number of server requests indicates the throughput size that the server can accept. According to the historical number of server requests, such as through the first preset ratio, the historical number is multiplied by the first preset ratio to obtain the initial credit value, which can realize the reasonable planning of server request flow restriction based on the historical number of server requests. The first preset ratio can be set according to the implementation situation, such as 10%, etc. Taking the historical number of QPS as 10000 as an example, the initial credit value = 10000 * 10% = 1000 is obtained. The above is an example, which is set according to the implementation situation and is not limited here. Alternatively, for the initial credit value, the initial credit value can also be dynamically set through a dynamic setting method to cope with business needs in different situations, such as when the business request volume is large, the initial credit value is increased. Further, the above two setting methods can also be combined to determine the initial credit value according to the historical number, and further adjust the initial credit value according to the business needs to obtain the final initial credit value, which is not limited here.
[0055] The real-time quota value is initialized according to the initial quota value, and the real-time quota value is initialized and assigned to the initial quota value. The real-time quota value is the number of requests used for flow control in real time, and can be adjusted in real time based on CPU utilization. Here, in the initial stage, when the server has not yet limited the request, the real-time quota value is assigned to the initial quota value, that is, all requests are allowed to access the server. Subsequently, the real-time quota value is adjusted in real time according to the CPU utilization to achieve flow control of the request.
[0056] The request random number is used to limit the flow of requests. The value range of the request random number is set according to the initial quota value. Initially, the maximum value in the value range of the request random number can be set as the initial quota value, and the minimum value is the minimum preset threshold, such as 0. Taking the initial quota value of 1000 as an example, the value range of the request random number is 0-1000. Determine the corresponding request random number within this value range so that flow can be limited according to the request random number and the real-time quota value.
[0057] Step S102, obtaining the CPU utilization of the server according to a preset time interval, comparing the CPU utilization with a preset utilization threshold, and obtaining a first comparison result.
[0058] When the CPU utilization rate of the server is high, it affects the response speed of the server to the request, causing problems such as slow page data return, slow refresh, or even no response, which in turn affects the user experience. In order to provide a good user experience and avoid problems such as server downtime due to high CPU utilization, this embodiment monitors the CPU utilization rate of the server. Since the resources required for requests of different services are different, it is not possible to directly determine how to limit the request based on a request. Therefore, this embodiment adopts a timed acquisition method to obtain the CPU utilization rate of the server at a preset time interval, such as every 5 seconds, so as to timely compare the CPU utilization rate with the preset utilization rate threshold, and make timely adjustments based on the first comparison result to meet business needs and improve user experience. The preset utilization rate threshold is set according to the implementation situation, taking into account the operation of the server and the business needs. For example, if it is set to 70%, if the CPU utilization rate is greater than 70%, it may affect the operation of the server, the request response efficiency, etc.
[0059] Based on the first comparison result of the obtained real-time CPU utilization and the preset utilization threshold, the request flow is limited or the response to the request is increased. This can achieve adaptive adjustment based on the current status of the server itself. Compared with the existing limitation that the server receives a fixed number of requests within 1s, this can better utilize the server's resources and will not cause excessive load on the server.
[0060] Step S103: According to the first comparison result, the real-time quota value is adjusted by using the summation growth multiplication reduction.
[0061] After obtaining the first comparison result, the real-time quota value can be adjusted in real time according to the first comparison result. When adjusting the real-time quota value, in order to avoid the real-time quota value adjustment value being too large, resulting in request jitter and the like, the real-time quota value can be adjusted by using AIMD and the multiplication reduction method of sexual growth. Specifically, according to the first comparison result, if it is determined that the CPU utilization rate is high, the multiplication reduction method can be used to limit the flow more quickly, but the number of requests will not be reduced by methods such as cutting in half. If it is determined that the CPU utilization rate is low, the number of requests allowed to access the server can be slowly increased by the sexual growth method, so that the adjustment of the real-time quota value is smooth, and the real-time quota value is relatively stable and set within a floating range. While ensuring that the server request can be responded to in a timely manner, the server's own resources can be fully utilized and will not cause excessive load on the server.
[0062] Specifically, when the real-time quota value is reduced by multiplication, such as the real-time quota value is multiplied by a factor less than 1, such as 0.9, from the initial 1000, the adjusted real-time quota value is 900. Compared with the initial 1000, the adjusted real-time quota value 900 reduces the quota value by 10%, restricting the access of some requests to the server, alleviating the problem of high CPU utilization, but not prohibiting a large number of requests from accessing the server in a one-size-fits-all manner. When the real-time quota value is increased by a summation growth, such as the real-time quota value is increased by 10 from 900, the adjusted real-time quota value is 910. Compared with before the adjustment, some (10) quota values are added, and the increase is relatively gentle. The change trend of the real-time quota value tends to be stable, and there will be no large changes in the number of prohibited or allowed requests, and the request instability. The real-time quota value can achieve a balance between maintaining stability and avoiding excessive use of resources.
[0063] Step S104, for any request to the server, a request random number corresponding to the request is generated based on the value range of the request random number, and according to the second comparison result between the request random number and the real-time quota value, the request to access the server is allowed or prohibited.
[0064] After adjusting the real-time quota value, the request can be allowed or prohibited according to the real-time quota value. Specifically, a request random number is generated for any request received by the server. Any random number generation algorithm can be used to generate a request random number corresponding to the request based on the value range of the request random number. If the value range of the request random number is 0-1000, the generated request random number can be any number between 0-1000, such as the request random number of request a is 909, the request random number of request b is 890, etc.
[0065] The generated request random number is compared with the real-time quota value, so as to allow or prohibit the request to access the server according to the comparison result. Specifically, if the real-time quota value is adjusted to 900, the real-time quota value 900 is compared with the request random number generated by each request. For example, if the request random number 909 of request a is compared with the real-time quota value 900, and the second comparison result is that the request random number is greater than the real-time quota value, then request a is prohibited from accessing the server; if the request random number 890 of request b is compared with the real-time quota value 900, and the second comparison result is that the request random number is less than the real-time quota value, then request b is allowed to access the server. Alternatively, the real-time credit value is adjusted to 910, and the real-time credit value 910 is compared with the request random number generated by each request. For example, if the request random number 909 of request a is compared with the real-time credit value 910, and the second comparison result is that the request random number is less than the real-time credit value, request a is allowed to access the server; if the request random number 890 of request b is compared with the real-time credit value 910, and the second comparison result is that the request random number is less than the real-time credit value, request b is allowed to access the server. The above is an example, which is set according to the implementation situation and is not limited here.
[0066] The server CPU current limiting effect is as follows Figure 2 As shown, the horizontal axis is the time axis and the vertical axis is the request volume. In this embodiment, the CPU utilization is obtained at each preset time interval, and compared with the CPU utilization upper limit, that is, the CPU preset utilization threshold. The flow is limited according to the CPU preset utilization threshold, the request volume is adjusted, and a mapping relationship between the request volume and the CPU utilization is constructed so that the overall request volume is in a relatively stable floating range, so that QPS can be stabilized based on CPU utilization. Figure 2 In the process, the changes in the request volume are relatively stable, and there will be no problems such as the one-size-fits-all or half-cut problems in the existing technology. It can provide users with stable service support, which is conducive to the stable operation of the server, timely response to requests, and maintenance of the stability of the operating environment.
[0067] According to the server CPU current limiting method provided by the present application, by regularly monitoring the CPU utilization, the request amount can be adjusted in real time according to the CPU utilization. Based on the comparison between the CPU utilization and the preset utilization threshold, the real-time quota value of the server request is adaptively adjusted according to the sum growth multiplication reduction, and the request amount can be smoothly controlled according to the real-time quota value and the request random number generated by the request, solving the existing problem of unstable current limiting.
[0068] Figure 3 A flow chart of a method for limiting CPU current at a server end according to an embodiment of the present application is shown. Figure 3 As shown, the method comprises the following steps:
[0069] Step S301, determining the initial credit value requested by the server, initializing the real-time credit value according to the initial credit value, and determining the value range of the requested random number according to the initial credit value.
[0070] When limiting the CPU flow of the server, it is necessary to first determine the initial quota value requested by the server, initialize the real-time quota value according to the initial quota value, and determine the value range of the request random number according to the initial quota value, and limit the maximum value of the request random number to the initial quota value. Initially, when requesting to access the server, the real-time quota value is the same as the maximum value of the request random number, that is, all requests are released and allowed to access the server, and then the real-time quota value is adjusted according to the CPU utilization of the server obtained at regular intervals. After reducing the real-time quota value, the real-time quota value is less than the initial quota value, that is, less than the maximum value of the request random number. Therefore, according to the generated request random number, some requests can be prohibited from accessing the server, and the initial quota value plays a role in limiting requests. The size of the initial quota value corresponds to the amount of request flow control. For example, if the initial quota value is 10000, when the real-time quota value is adjusted from 9000 to 9010, the allowed quota for requests will only increase by 0.1%. If the initial quota value is 1000, when the real-time quota value is adjusted from 900 to 910, the allowed quota for requests will increase by 1%. Different initial quota values will affect the number of requests allowed or prohibited after the real-time quota value is adjusted. When the adjusted number is too small, the flow control effect cannot be achieved. Furthermore, if the adjusted number is too large, the request cannot be stably limited.
[0071] When determining the initial credit value of the server request, it is also necessary to make reasonable settings in combination with the historical number of requests from the server. For example, the historical number of requests from the server is obtained, and the initial credit value of the server request is calculated according to the first preset ratio based on the historical number of requests. Initial credit value = historical number of requests * first preset ratio, which is convenient for reasonable planning based on the historical number of requests from the server and limiting the flow of requests. The first preset ratios of different servers can be set differently according to their respective performance, operating conditions, etc., and are set specifically according to the implementation situation, which is not limited here. Alternatively, a dynamic setting interface can be set for the initial credit value, and the initial credit value of the server request can be dynamically adjusted according to the business execution situation, different time periods, etc., such as setting the initial credit value accordingly according to the business execution situation at different time points, or, after obtaining the initial credit value based on the historical number of requests, it can also be dynamically adjusted, etc., which is not limited here.
[0072] The request random number is used to compare with the real-time quota value to allow or prohibit the request to access the server. The value range of the request random number is determined according to the initial quota value, and its maximum value is set to the initial quota value. The minimum value of the request random number is the minimum preset threshold, such as 0. That is, the value range of the request random number is between 0 and the initial quota value, and the request random number can be calculated according to any random algorithm, and the specific algorithm is not limited.
[0073] Step S302, obtaining the CPU utilization of the server according to a preset time interval, comparing the CPU utilization with a preset utilization threshold, and obtaining a first comparison result.
[0074] In order to facilitate real-time monitoring of requests and timely current limiting, this embodiment adopts a timed monitoring method, obtains the CPU utilization of the server at every preset time interval, such as 5 seconds, compares the CPU utilization of the server with the preset utilization threshold, and obtains a first comparison result. The first comparison result describes the current load of the server. If the CPU utilization is greater than or equal to the preset utilization threshold, the server may be overloaded and needs to be current limited in time. If the CPU utilization is less than the preset utilization threshold, the resources of the server are not fully utilized, and the number of requests can be appropriately increased.
[0075] According to the first comparison result, step S303 or S304 is executed accordingly.
[0076] Step S303: If the CPU utilization is greater than or equal to the preset utilization threshold, the real-time quota value is multiplied by a multiplication factor to reduce the real-time quota value.
[0077] If the CPU utilization is greater than or equal to the preset utilization threshold, the real-time quota value needs to be reduced to limit the access of requests to the server and reduce the load on the server. When adjusting and reducing the real-time quota value, a multiplication factor is used. The value range of the multiplication factor is greater than 0 and less than 1, such as 0.9. The real-time quota value can be adjusted in time to limit the number of requests to access the server, reduce the CPU utilization of the server, and avoid excessive load.
[0078] Step S304: If the CPU utilization is less than the preset utilization threshold, the utilization factor is added to the real-time quota value to increase the real-time quota value.
[0079] If the CPU utilization is less than the preset utilization threshold, and the server still has idle resources, the real-time quota value can be increased to increase the access requests to the server to avoid wasting idle resources. The harmony factor can be determined according to the initial quota value according to the second preset ratio, such as setting the harmony factor to the initial quota value * the second preset ratio. The second preset ratio can be set according to the implementation situation, with the number of requests adjusted smoothly as the setting basis. For example, if the initial quota value is 1000, the harmony factor = 1000 * 1% = 10, and the harmony factor is added to the real-time quota value to obtain the adjusted real-time quota value, so as to realize the sequential increase in the number of allowed requests, make more use of the idle resources of the server, and at the same time, avoid increasing too many requests at one time.
[0080] Furthermore, since different requests require different resources, if the resources required by each current request are small, if the real-time quota value is adjusted without an upper limit, the real-time quota value may be too high, such as adjusting the real-time quota value to 1200, etc. If it exceeds the initial quota value, the resources required for subsequent requests will increase. At this time, the real-time quota value is adjusted downward. It is possible that the adjusted real-time quota value 1200*0.9=1080 is still greater than the initial quota value, and the flow limiting effect cannot be achieved. Therefore, after using the harmony factor to adjust and increase the real-time quota value, for the adjusted real-time quota value, it is also necessary to compare the adjusted real-time quota value with the initial quota value. If it is greater than the initial quota value, the adjusted real-time quota value is updated to the initial quota value. If the adjusted real-time quota value is 1200 and the initial quota value is 1000, the adjusted real-time quota value 1200 needs to be updated to 1000 to avoid affecting the effect of the subsequent multiplication factor to reduce the real-time quota value.
[0081] Step S305, for any request to the server, a random algorithm is used to generate a request random number corresponding to the request within the value range of the request random number. If the request random number is less than or equal to the real-time quota value, the request is allowed to access the server; if the request random number is greater than the real-time quota value, the request is prohibited from accessing the server.
[0082] While adjusting the real-time quota value based on CPU utilization, for any request to the server, a random algorithm can be used to generate a request random number corresponding to the request. When generating, it is necessary to generate according to the value range of the request random number to avoid the generated request random number being too large or too small.
[0083] The real-time quota value controls the number of requests to access the server. The generated request random number is compared with the real-time quota value. If the request random number is less than or equal to the real-time quota value, the request is allowed to access the server; if the request random number is greater than the real-time quota value, the request is prohibited from accessing the server, thereby achieving current limiting of requests.
[0084] Step S306: If the request to access the server is prohibited, the request is distributed to other servers, and the other servers determine whether to allow or prohibit the request.
[0085] This embodiment runs in a CDN multi-node environment, and multiple different servers can provide services to users. When the CPU utilization of a server is greater than or equal to the preset utilization threshold, after adjusting the real-time quota value of the server, if the request random number generated by the request is greater than the real-time quota value of the server, the request is prohibited from accessing the server, and the request can be distributed to other servers through load balancing and other methods, and other servers judge whether to allow the request or prohibit access to other servers based on their own real-time quota values. Specifically, if request a accesses server 1, after comparing the request random number of request a with the real-time quota value of server 1, server 1 prohibits request a from accessing, distributes request a to server 2, and then compares the request random number of request a with the real-time quota value of server 2. If it is less than the real-time quota value of server 2, request a is allowed to access server 2. If it is greater than or equal to the real-time quota value of server 2, request a is distributed to server 3 or server 4... until a server allows request a to access.
[0086] According to the server CPU current limiting method provided by the present application, a mapping between the server CPU utilization and the number of requests is constructed based on the CPU utilization, and the real-time quota value of the request is adjusted by comparing the CPU utilization with the preset utilization threshold (i.e., the upper limit of CPU utilization), and the real-time quota value is increased or decreased by summing growth and multiplication, and then the request random number corresponding to the request is compared with the real-time quota value, thereby limiting the request, prohibiting it from accessing the server, and reducing the load on the server, or increasing the number of requests, allowing more requests to access the server, avoiding the waste of idle resources on the server, and realizing adaptive adjustment of the server's requests and smooth current limiting. Furthermore, for CDN multi-node environments, when a server limits the access of requests, the requests can be distributed to other servers to ensure that the requests are responded to in a timely manner.
[0087] Figure 4 The schematic diagram of the structure of the server CPU current limiting device provided by an embodiment of the present application is shown. Figure 4 As shown, the device comprises:
[0088] Initialization module 410, adapted to determine an initial credit value requested by the server, initialize a real-time credit value according to the initial credit value, and determine a value range of a requested random number according to the initial credit value;
[0089] A first comparison module 420 is adapted to obtain the CPU utilization of the server according to a preset time interval, compare the CPU utilization with a preset utilization threshold, and obtain a first comparison result;
[0090] An adjustment module 430 adapted to adjust the real-time quota value by using a summation growth multiplication reduction according to the first comparison result;
[0091] The permission and prohibition module 440 is suitable for generating a request random number corresponding to the request based on the value range of the request random number for any request to the server, and allowing or prohibiting the request to access the server according to the second comparison result between the request random number and the real-time quota value.
[0092] Optionally, the initialization module 410 is further adapted to:
[0093] Obtaining the number of historical requests from the server, and calculating the initial credit value of the server request according to the number of historical requests according to a first preset ratio; and / or, setting the initial credit value of the server request according to a dynamic setting interface;
[0094] Assign the real-time quota value to the initial quota value;
[0095] The maximum value of the requested random number is set as the initial quota value, and the minimum value of the requested random number is set as the minimum preset threshold.
[0096] Optionally, the adjustment module 430 is further adapted to:
[0097] If the CPU utilization is greater than or equal to the preset utilization threshold, the real-time quota value is multiplied by the multiplication factor to reduce the real-time quota value; the multiplication factor is greater than 0 and less than 1;
[0098] If the CPU utilization is less than the preset utilization threshold, the utilization and efficiency factor is added to the real-time quota value to increase the real-time quota value; the utilization and efficiency factor is determined according to the initial quota value according to the second preset ratio.
[0099] Optionally, the adjustment module 430 is further adapted to:
[0100] The real-time credit limit value is added with the sum factor to obtain the adjusted real-time credit limit value;
[0101] The adjusted real-time credit limit value is compared with the initial credit limit value. If it is greater than the initial credit limit value, the adjusted real-time credit limit value is updated to the initial credit limit value.
[0102] Optionally, the permission prohibition module 440 is further adapted to:
[0103] For any request to the server, a random algorithm is used to generate a request random number corresponding to the request within the value range of the request random number.
[0104] Optionally, the permission prohibition module 440 is further adapted to:
[0105] If the requested random number is less than or equal to the real-time quota value, the request is allowed to access the server;
[0106] If the requested random number is greater than the real-time quota value, the request to access the server is prohibited.
[0107] Optionally, there are multiple servers;
[0108] If the request to access the server is prohibited, the device further comprises: a distribution module 450 adapted to distribute the request to other servers, and the other servers determine whether to allow or prohibit the request to access other servers.
[0109] The description of each module above refers to the corresponding description in the method embodiment and will not be repeated here.
[0110] According to the server-side CPU current limiting device provided by the present application, the CPU utilization rate is monitored regularly, and the request amount can be adjusted in real time according to the CPU utilization rate. Based on the comparison between the CPU utilization rate and the preset utilization rate threshold, the real-time quota value of the server-side request is adaptively adjusted according to the sum growth multiplication reduction, and the request amount can be smoothly controlled according to the real-time quota value and the request random number generated by the request, solving the existing problem of unstable current limiting.
[0111] The present application also provides a non-volatile computer storage medium, which stores at least one executable instruction, and the executable instruction can execute the operation corresponding to the server CPU current limiting method in any of the above method embodiments.
[0112] The present application also provides a computer program product, which includes at least one executable instruction or computer program, and the executable instruction or computer program can enable a processor to perform operations corresponding to the server CPU current limiting method in any of the above method embodiments.
[0113] Figure 5 A schematic diagram of the structure of a computing device according to an embodiment of the present application is shown. The specific embodiment of the present application does not limit the specific implementation of the computing device.
[0114] like Figure 5 As shown, the computing device may include: a processor (processor) 502 , a communications interface (Communications Interface) 504 , a memory (memory) 506 , and a communication bus 508 .
[0115] in:
[0116] The processor 502 , the communication interface 504 , and the memory 506 communicate with each other via a communication bus 508 .
[0117] The communication interface 504 is used to communicate with other devices such as clients or other servers.
[0118] The processor 502 is used to execute the program 510, and specifically can execute the relevant steps in the above-mentioned server CPU current limiting method embodiment.
[0119] Specifically, the program 510 may include program codes, which include computer operation instructions.
[0120] The processor 502 may be a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the present application. The one or more processors included in the computing device may be processors of the same type, such as one or more CPUs; or processors of different types, such as one or more CPUs and one or more ASICs.
[0121] The memory 506 is used to store the program 510. The memory 506 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.
[0122] The program 510 can be specifically used to enable the processor 502 to execute the server CPU current limiting method in any of the above method embodiments. The specific implementation of each step in the program 510 can refer to the corresponding descriptions in the corresponding steps and units in the above server CPU current limiting embodiment, which will not be repeated here. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working process of the above-described devices and modules can refer to the corresponding process description in the above-mentioned method embodiment, which will not be repeated here.
[0123] The algorithm or display provided here is not inherently related to any specific computer, virtual system or other device. Various general systems can also be used together with the teaching based on this. According to the above description, it is obvious to construct the structure required for this type of system. In addition, the application is not directed to any specific programming language either. It should be understood that various programming languages can be utilized to realize the content of the application described here, and the above description of specific languages is to disclose the preferred embodiment of the application.
[0124] In the description provided herein, a large number of specific details are described. However, it is understood that the embodiments of the present application can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.
[0125] Similarly, it should be understood that in order to streamline the present application and help understand one or more of the various inventive aspects, in the above description of the exemplary embodiments of the present application, the various features of the present application are sometimes grouped together into a single embodiment, figure, or description thereof. However, the disclosed method should not be interpreted as reflecting the following intention: the claimed application requires more features than the features clearly stated in each claim. More specifically, as reflected in the claims below, the inventive aspects are less than all the features of the single embodiment disclosed above. Therefore, the claims following the specific embodiment are hereby expressly incorporated into the specific embodiment, wherein each claim itself serves as a separate embodiment of the present application.
[0126] Those skilled in the art will appreciate that the modules in the devices in the embodiments may be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments may be combined into one module or unit or component, and in addition they may be divided into a plurality of submodules or subunits or subcomponents. Except that at least some of such features and / or processes or units are mutually exclusive, all features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device disclosed in this manner may be combined in any combination. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstracts and drawings) may be replaced by an alternative feature providing the same, equivalent or similar purpose.
[0127] In addition, those skilled in the art will appreciate that, although some embodiments herein include certain features included in other embodiments but not other features, the combination of features of different embodiments is meant to be within the scope of the present application and form different embodiments. For example, in the claims below, any one of the claimed embodiments may be used in any combination.
[0128] The various component embodiments of the present application can be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. It should be understood by those skilled in the art that a microprocessor or digital signal processor (DSP) can be used in practice to implement some or all functions of some or all components of the present application. The present application can also be implemented as a device or apparatus program (e.g., computer program and computer program product) for executing a part or all of the methods described herein. Such a program implementing the present application can be stored on a computer-readable medium, or can have the form of one or more signals. Such a signal can be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.
[0129] It should be noted that the above embodiments illustrate the present application rather than limit the present application, and that those skilled in the art may design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference symbol between brackets shall not be constructed as a limitation on the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "one" or "an" preceding an element does not exclude the presence of multiple such elements. The present application may be implemented by means of hardware including several different elements and by means of a suitably programmed computer. In a unit claim that lists several devices, several of these devices may be embodied by the same hardware item. The use of the words first, second, and third, etc. does not indicate any order. These words may be interpreted as names. The steps in the above embodiments, unless otherwise specified, should not be understood as limitations on the order of execution.
Claims
1. A server CPU current limiting method, comprising: Determine the initial credit value requested by the server, initialize the real-time credit value according to the initial credit value, and determine the value range of the requested random number according to the initial credit value; Acquire the CPU utilization of the server according to a preset time interval, compare the CPU utilization with a preset utilization threshold, and obtain a first comparison result; According to the first comparison result, the real-time quota value is adjusted by using the sum growth multiplication reduction; For any request to the server, a request random number corresponding to the request is generated based on the value range of the request random number, and according to the second comparison result between the request random number and the real-time credit value, the request is allowed or prohibited from accessing the server.
2. The method according to claim 1, wherein: The determining of the initial credit value requested by the server, initializing the real-time credit value according to the initial credit value, and determining the value range of the requested random number according to the initial credit value further includes: Obtaining the number of historical requests from the server, and calculating the initial credit value requested by the server according to the number of historical requests and a first preset ratio; and / or, setting the initial credit value requested by the server according to a dynamic setting interface; Assigning the real-time credit limit value to the initial credit limit value; The maximum value of the requested random number is set as the initial credit value, and the minimum value of the requested random number is set as the minimum preset threshold.
3. The method according to claim 1, wherein: The adjusting the real-time quota value by using the summation growth multiplication reduction according to the first comparison result further includes: If the CPU utilization is greater than or equal to a preset utilization threshold, multiply the real-time quota value by a multiplication factor to reduce the real-time quota value; the multiplication factor is greater than 0 and less than 1; If the CPU utilization is less than a preset utilization threshold, a utilization and efficiency factor is added to the real-time quota value to increase the real-time quota value; the utilization and efficiency factor is determined according to the initial quota value in accordance with a second preset ratio.
4. The method according to claim 3, wherein: The utilization and performance factor is added to the real-time credit value to increase the real-time credit value further includes: Adding the sum factor to the real-time credit limit value to obtain an adjusted real-time credit limit value; The adjusted real-time credit limit value is compared with the initial credit limit value, and if the adjusted real-time credit limit value is greater than the initial credit limit value, the adjusted real-time credit limit value is updated to the initial credit limit value.
5. The method according to any one of claims 1 to 4, wherein: For any request to the server, generating a request random number corresponding to the request based on a value range of the request random number further includes: For any request to a server, a random algorithm is used to generate a request random number corresponding to the request within the value range of the request random number.
6. The method according to any one of claims 1 to 5, wherein: The allowing or prohibiting the request to access the server according to the second comparison result between the request random number and the real-time quota value further includes: If the request random number is less than or equal to the real-time quota value, the request is allowed to access the server; If the request random number is greater than the real-time quota value, the request is prohibited from accessing the server.
7. The method according to any one of claims 1 to 6, wherein: There are multiple servers; If the request is prohibited from accessing the server, the method further includes: The request is distributed to other servers, and the other servers determine whether to allow or prohibit the request from accessing other servers.
8. A server-side CPU current limiting device, comprising: An initialization module, adapted to determine an initial credit value requested by the server, initialize a real-time credit value according to the initial credit value, and determine a value range of a requested random number according to the initial credit value; A first comparison module, adapted to obtain a CPU utilization rate of the server according to a preset time interval, and compare the CPU utilization rate with a preset utilization rate threshold to obtain a first comparison result; An adjustment module, adapted to adjust the real-time credit limit value by using a summation growth multiplication reduction according to the first comparison result; The permission and prohibition module is suitable for generating a request random number corresponding to any request to the server based on the value range of the request random number, and allowing or prohibiting the request to access the server according to the second comparison result between the request random number and the real-time quota value.
9. A computing device comprising: A processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; The memory is used to store at least one executable instruction, and the executable instruction enables the processor to perform an operation corresponding to the server CPU current limiting method according to any one of claims 1-7.
10. A computer storage medium, wherein at least one executable instruction is stored in the storage medium, and the executable instruction enables a processor to perform operations corresponding to the server CPU current limiting method according to any one of claims 1 to 7.
11. A computer program product, comprising at least one executable instruction, wherein the executable instruction enables a processor to perform operations corresponding to the server CPU current limiting method according to any one of claims 1 to 7.
