CN118051346A - Method, device, electronic equipment and readable storage medium for requesting dynamic current limiting - Google Patents

Method, device, electronic equipment and readable storage medium for requesting dynamic current limiting Download PDF

Info

Publication number
CN118051346A
CN118051346A CN202410431337.1A CN202410431337A CN118051346A CN 118051346 A CN118051346 A CN 118051346A CN 202410431337 A CN202410431337 A CN 202410431337A CN 118051346 A CN118051346 A CN 118051346A
Authority
CN
China
Prior art keywords
thread
target application
threads
request
application
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202410431337.1A
Other languages
Chinese (zh)
Inventor
张震
丁亚军
李乔
刘莹皓
郑彬
刘志勇
沈起帆
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hundsun Technologies Inc
Original Assignee
Hundsun Technologies Inc
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hundsun Technologies Inc filed Critical Hundsun Technologies Inc
Priority to CN202410431337.1A priority Critical patent/CN118051346A/en
Publication of CN118051346A publication Critical patent/CN118051346A/en
Pending legal-status Critical Current

Links

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The invention relates to the technical field of Internet, and provides a method and a device for requesting dynamic current limiting, electronic equipment and a readable storage medium, wherein the method comprises the following steps: when a request corresponding to a target application is received, determining the type of a thread to be called corresponding to the request, wherein the target application is any application in a plurality of applications in the access electronic equipment; if the type of the thread to be called is the target application requiring thread, forwarding a request to the target application; if the type of the thread to be called is a non-target application requiring thread, determining whether a target application available thread exists in the electronic equipment according to a working thread upper limit threshold, wherein the working thread upper limit threshold is used for limiting the upper limit of the number of used threads of all applications in the electronic equipment; if the available threads of the target application exist, forwarding the request to the target application, otherwise, refusing to forward the request. The invention realizes the balance between resource utilization and thread isolation.

Description

Method, device, electronic equipment and readable storage medium for requesting dynamic current limiting
Technical Field
The present invention relates to the field of internet technologies, and in particular, to a method and apparatus for dynamic current limiting request, an electronic device, and a readable storage medium.
Background
For an electronic device accessing multiple downstream applications, in order to avoid that a certain downstream application responds slowly or fails to occupy excessive threads of a server, a thread isolation policy is generally adopted to affect normal responses of other downstream applications.
The existing thread isolation strategy comprises a thread pool isolation mode and a semaphore isolation mode, wherein the thread pool isolation mode uses one thread pool for each type of downstream application, so that the influence of different downstream applications is avoided. The semaphore schema creates a semaphore for each class of downstream applications that limits the number of concurrent accesses to the downstream applications. When a request of a downstream application arrives, whether the signal quantity exceeds the limit of the set signal quantity is judged first, and if so, a new request of the downstream application is discarded.
Although the two modes are configured by a preset mode, the request number of the downstream application is limited to a certain extent, so that cascade faults of the application and other downstream applications caused by slow response or faults of part of the downstream applications are avoided. However, in these two modes, if the number of threads configured for the downstream application is small, the thread resources cannot be fully utilized under the condition that the electronic device has many idle threads, and if the number of threads configured for the downstream application is large, when the downstream application is abnormal, the processing of other downstream applications will be affected, and the balance between the thread resource utilization and the thread isolation cannot be realized.
Disclosure of Invention
The invention aims to provide a method, a device, electronic equipment and a readable storage medium for dynamic current limiting of requests, which realize the balance between thread resource utilization and thread isolation.
Embodiments of the invention may be implemented as follows:
in a first aspect, the present invention provides a method for requesting dynamic current limiting, applied to an electronic device, the method comprising:
When a request corresponding to a target application is received, determining the type of a thread to be called corresponding to the request, wherein the target application is any application in a plurality of applications in the electronic equipment;
if the type of the thread to be called is the target application requiring thread, forwarding the request to the target application;
If the type of the thread to be called is not the target application requiring thread, determining whether the target application available thread exists in the electronic equipment according to a working thread upper limit threshold, wherein the working thread upper limit threshold is used for limiting the upper limit of the number of used threads of all the applications in the electronic equipment;
If the available threads of the target application exist, forwarding the request to the target application, otherwise, refusing to forward the request.
In an alternative embodiment, when a request corresponding to a target application is received, the step of determining the type of the thread to be invoked corresponding to the request includes:
acquiring the number of used threads and the number of required threads of the target application;
And if the number of the used threads is smaller than the number of the required threads, judging that the type of the thread to be called is the target application required thread, otherwise, judging that the type of the thread to be called is not the target application required thread.
In an alternative embodiment, the step of determining whether the electronic device has a target application available thread according to a worker thread upper limit threshold includes:
acquiring the total number of available threads of the electronic equipment;
Acquiring the number of reserved threads and the number of used threads at the current moment of each application;
determining an upper limit threshold of the working thread according to the total number of the available threads, the reserved thread numbers of all the applications and the preset upper limit percentage of the working thread;
and if the sum of the number of used threads of all the applications is greater than or equal to the upper limit threshold of the working thread, judging that the electronic equipment does not have the usable thread of the target application, otherwise, judging that the electronic equipment has the usable thread of the target application.
In an alternative embodiment, each application is preconfigured with a preset reserved thread number, and the step of obtaining the reserved thread number of each application at the current moment includes:
calculating the difference value between the required thread number of each application and the used thread number at the current moment;
if the difference value is smaller than or equal to 0, setting the corresponding reserved thread number to 0;
If the difference value is greater than 0, the corresponding preset reserved thread number is obtained, and the smaller value of the difference value and the corresponding preset reserved thread number is set as the reserved thread number at the corresponding current moment.
In an alternative embodiment, the step of forwarding the request includes:
Creating the thread to be called based on the request;
and forwarding the request by utilizing the thread to be called and increasing the number of used threads of the target application.
In an alternative embodiment, after the step of forwarding the request, the method further includes:
if a response message to the request is received, the thread forwarding the target application is released and its number of used threads is decremented.
In an alternative embodiment, before the step of receiving the request for the target application, the method further includes:
receiving an access request of the target application, wherein the access request comprises the required thread number and the preset reserved thread number of the target application;
Acquiring the total number of required threads of all applications; all the applications are applications accessed to the same electronic equipment;
if the sum of the total required threads and the required threads is smaller than or equal to the total available threads of the electronic equipment, and the ratio of the preset reserved threads to the required threads is smaller than or equal to a global reserved thread percentage threshold, accessing the target application to the electronic equipment; otherwise, refusing to access the target application to the electronic equipment.
In a second aspect, the present invention provides a dynamic current limiting device for electronic equipment, the device comprising:
The determining module is used for determining the type of a thread to be called corresponding to a request when the request corresponding to a target application is received, wherein the target application is any application in a plurality of applications in the electronic equipment;
the processing module is used for forwarding the request to the target application if the type of the thread to be called is the thread required by the target application;
The processing module is further configured to determine whether a target application available thread exists in the electronic device according to a working thread upper limit threshold if the type of the thread to be invoked is a thread that is not required by the target application, where the working thread upper limit threshold is used to limit an upper limit of a used thread number of all applications in the electronic device;
The processing module is further configured to forward the request to the target application if the target application available thread exists, and reject forwarding the request if the target application available thread exists.
In a third aspect, the present invention provides an electronic device, including a processor and a memory, where the memory is configured to store a program, and where the processor is configured to implement the method for dynamic current limiting according to any one of the foregoing embodiments when the program is executed.
In a fourth aspect, the present invention provides a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements a method of dynamic throttling of requests as in any of the previous embodiments.
Compared with the prior art, the embodiment of the invention provides a request dynamic current limiting method, a request dynamic current limiting device, electronic equipment and a readable storage medium, wherein for any target application in a plurality of applications in the electronic equipment, when a request corresponding to the target application is received, the type of a thread to be called corresponding to the request is determined, the request of the target application is forwarded according to the type of the thread to be called, if the type is the thread required by the target application, the request is forwarded to the target application, otherwise, whether the target application available thread exists in the electronic equipment is determined according to a working thread upper limit threshold, if the target application available thread exists, the request is forwarded to the target application, and otherwise, the request is refused to be forwarded. When the requests of the target application are not more, the requests can be normally forwarded because the target application requires threads, when the requests of the target application are more, the requests of other applications except the target application are not more, and when the requests of the target application are not more, the target application can use a part of other application requiring threads to fully utilize the line resources in the electronic device, when the requests of the other applications are gradually increased, the requesting threads of the other applications do not reach the line of the target application, the requests of the other applications can be normally forwarded, and as the requests of the other applications are increased, the number of used threads of all applications in the electronic device can be increased, and at the moment, the requests of the target application can stop to continue to use more than the other application requiring threads except the target application requiring threads due to the limitation of the line threshold of the working thread, so that the target application can avoid the influence on the other applications due to the occupation of excessive thread resources, and the balance between the utilization of the line resources and the line isolation is finally realized.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings that are needed in the embodiments will be briefly described below, it being understood that the following drawings only illustrate some embodiments of the present invention and therefore should not be considered as limiting the scope, and other related drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
Fig. 1 is an exemplary diagram of an application scenario provided in this embodiment.
Fig. 2 is a block diagram of an electronic device according to the present embodiment.
Fig. 3 is a flowchart illustrating a method for dynamic throttling of requests according to the present embodiment.
Fig. 4 is an exemplary diagram of a dynamic current limiting process according to the present embodiment.
Fig. 5 is an exemplary diagram of interactions among a client, an electronic device, and an application server according to the present embodiment.
Fig. 6 is a block diagram of a request dynamic current limiting device according to this embodiment.
Icon: 10-an electronic device; 11-a processor; 12-memory; 13-bus; 20-client; 30-an application server; 100-requesting a dynamic current limiting device; 110-a determination module; 120-a processing module; 130-access module.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are some embodiments of the present invention, but not all embodiments of the present invention. The components of the embodiments of the present invention generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations.
Thus, the following detailed description of the embodiments of the invention, as presented in the figures, is not intended to limit the scope of the invention, as claimed, but is merely representative of selected embodiments of the invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
It should be noted that: like reference numerals and letters denote like items in the following figures, and thus once an item is defined in one figure, no further definition or explanation thereof is necessary in the following figures.
In the description of the present invention, it should be noted that, if the terms "upper", "lower", "inner", "outer", and the like indicate an azimuth or a positional relationship based on the azimuth or the positional relationship shown in the drawings, or the azimuth or the positional relationship in which the inventive product is conventionally put in use, it is merely for convenience of describing the present invention and simplifying the description, and it is not indicated or implied that the apparatus or element referred to must have a specific azimuth, be configured and operated in a specific azimuth, and thus it should not be construed as limiting the present invention.
Furthermore, the terms "first," "second," and the like, if any, are used merely for distinguishing between descriptions and not for indicating or implying a relative importance.
It should be noted that the features of the embodiments of the present invention may be combined with each other without conflict.
In the prior art, although applications accessing to the electronic device can be preconfigured, in an actual application scenario, respective request situations of each application in a plurality of applications may be quite different, the same application may have quite different request numbers in different time periods, and a request emergency situation may also exist, so it is difficult to accurately evaluate the number of threads required by the application in advance, and it is difficult to match the configuration of the number of threads required by the application with the actual application scenario, and thread resources in the electronic device cannot be reasonably utilized.
In view of this, the present embodiment provides a method, an apparatus, an electronic device, and a readable storage medium for dynamic current limiting, where the core solution is as follows: when the number of threads required by the application is within the range of the required number of threads, normally forwarding the request of the application, when the number of threads required by the application exceeds the required number of threads, determining whether the threads exceeding the required number of threads of the application can be used or not by limiting the upper limit threshold of the working threads of the upper limit of the used number of threads of all the applications in the electronic equipment, if the threads exceeding the required number of threads can be used, normally forwarding the request of the application, otherwise, refusing to forward the request of the application, thereby enabling the target application to use more threads than required by the target application when the number of threads required by the target application is more and the number of threads used by the rest of the applications is less, and enabling the target application not to continue to use more threads than required by the target application when the number of threads used by the rest of the application is increased to a certain degree, so that the balance between the utilization of thread resources in the electronic equipment and the thread isolation is realized, and the thread resources in the electronic equipment are reasonably utilized. Which will be described in detail below.
Referring to fig. 1, fig. 1 is an exemplary diagram of an application scenario provided in this embodiment. In fig. 1, an electronic device 10 and a client 20 and an application server 30 are both communicatively connected. The user initiates an application request through the client 20, the electronic device 10 forwards the application request to the application server 30, the application server 30 returns a response to the application request to the electronic device 10, and the electronic device 10 returns the response to the client 20.
The client 20 is the originating end of the application request, and the client 20 includes, but is not limited to, a cell phone, a tablet computer, a notebook computer, a desktop computer, and the like.
The electronic device 10 is a device having a function of forwarding an application request, and is running a program including a forwarding module of a network, and the electronic device 10 may be an application gateway, which is an inter-network device that connects one network to another network to provide a specific application, and the application gateway must be able to implement a corresponding application protocol.
The application server 30 is a device that provides application services including, but not limited to, a WEB server that provides WEB browsing services, an FTP server that provides file transfer services, an HTTP server that provides hypertext transfer services, and the like.
It should be noted that, the application server 30 may be one or more, and one application server 30 may provide one type of application service, or may provide multiple types of application services. The electronic device 10 and the application server 30 may be a device, that is, a device has a functional module for forwarding a request and a functional module for providing an application service, where the functional module for forwarding the request forwards the received request to the functional module for the corresponding application service.
Based on the application scenario of fig. 1, the embodiment of the present invention further provides a block schematic diagram of the electronic device 10 in fig. 1, the electronic device 10 implements the dynamic current limiting method for request according to the foregoing embodiment, referring to fig. 2, fig. 2 shows a block schematic diagram of the electronic device 10 provided by the present invention, where the electronic device 10 includes a processor 11, a memory 12 and a bus 13, and the processor 11 and the memory 12 are connected through the bus 13.
The processor 11 may be an integrated circuit chip with signal processing capabilities. In implementation, the steps of the method for requesting dynamic current limiting of the above embodiment may be implemented by an integrated logic circuit of hardware in the processor 11 or an instruction in the form of software. The processor 11 may be a general-purpose processor including a central processing unit (Central Processing Unit, CPU), a network processor (Network Processor, NP), etc.; but may also be a digital signal Processor (DIGITAL SIGNAL Processor, DSP), application SPECIFIC INTEGRATED Circuit (ASIC), field programmable gate array (Field Programmable Logic GATE ARRAY, FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware components.
The memory 12 is used to store a program for implementing the request dynamic flow restriction method of the above embodiment, and the program may be a software function module stored in the memory 12 in the form of software or firmware (firmware) or solidified in an Operating System (OS) of the electronic device 10. After receiving the execution instruction, the processor 11 executes a program to implement the method for dynamic current limiting of requests disclosed in the above embodiment.
Based on fig. 1 and 2, the present embodiment provides a method for dynamically restricting a request applied to the electronic device 10 in fig. 1 and 2, please refer to fig. 3, fig. 3 is a flowchart illustrating the method for dynamically restricting a request provided in the present embodiment, the method includes the following steps:
Step S101, when a request corresponding to a target application is received, determining the type of a thread to be invoked corresponding to the request, wherein the target application is any application in a plurality of applications in the access electronic equipment.
In this embodiment, the same electronic device may access multiple applications, where each application may run on one application server, or multiple applications may run on the same application server at the same time, or multiple applications may run on the electronic device. The request corresponding to the target application may be a request from the client 20 to provide a service to the target application.
In this embodiment, the type of the thread to be called may be a target application request thread or a non-target application request thread, when the thread required by the target application is not used yet, the target application may use the thread required by the target application, and when the thread required by the target application is used, if there are other application requests but not used threads in the electronic device 10 at the present moment, the type of the thread to be called is the non-target application request thread.
Step S102, if the type of the thread to be called is the target application requiring thread, forwarding the request to the target application.
Step S103, if the type of the thread to be called is a non-target application requiring thread, determining whether the target application available thread exists in the electronic device according to a working thread upper limit threshold, wherein the working thread upper limit threshold is used for limiting the upper limit of the number of used threads of all applications in the electronic device.
Step S104, if the available thread of the target application exists, forwarding the request to the target application, otherwise, refusing to forward the request.
In this embodiment, if the type of the thread to be invoked is a non-target application requiring thread, in order to avoid that the target application uses more threads than the application requires to affect other applications without limitation, a working thread upper limit threshold is introduced in this embodiment, and the upper limit of the number of used threads of all applications in the electronic device is limited by using the working thread upper limit threshold.
It should be noted that, when the electronic device refuses to forward the request, the request busy fusing information may be fed back to the client, in order to give the client more humanized feedback, the degradation data may also be preset, and when the electronic device refuses to forward the request, the degradation data is fed back to the client.
According to the method provided by the embodiment, when the number of threads required by the target application is more and the number of threads used by other applications is less, the target application can use more threads than the number of threads required by the target application, and when the number of threads used by other applications is increased to a certain degree, the target application cannot continue to use more threads than the number of threads required by the target application, so that balance between thread resource utilization and thread isolation in the electronic equipment is realized, and the thread resource in the electronic equipment is reasonably utilized.
In this embodiment, in order to reasonably control the thread number used by an application requested by an access electronic device in advance, this embodiment provides an implementation manner of accessing the electronic device by the application, so that each application may be preconfigured with an estimated value that meets the application when accessing the electronic device, where the implementation manner is as follows:
Firstly, receiving an access request of a target application, wherein the access request comprises the required thread number and the preset reserved thread number of the target application;
In this embodiment, the required thread count of the target application may be the thread count required by the target application to satisfy the request under the normal condition, and the required thread count may be an empirical value predetermined according to the history request condition of the target application, for example, the maximum request concurrency count in the history request of the application a may be set to 100, or the average request concurrency count in the history request of the application a may be set to 80. The preset reserved thread number of the target application may be the number of threads that the target application needs to additionally reserve outside of the normally used threads. In order to make the preset reserved thread number of each application as reasonable as possible, the preset reserved thread number may be set to be not more than a preset percentage of the corresponding required thread number, for example, the required thread number is 100, and the preset percentage is 10%, and the preset reserved thread number is not more than 10.
Secondly, acquiring the total number of required threads of all applications; all applications are applications accessed to the same electronic equipment;
finally, if the sum of the total required threads and the required threads is smaller than or equal to the total available threads of the electronic equipment, and the ratio of the preset reserved threads to the required threads is smaller than or equal to the global reserved thread percentage threshold, accessing the target application into the electronic equipment; otherwise, refusing to access the target application to the electronic equipment.
In this embodiment, the electronic device is limited by its own software configuration and hardware configuration, and the maximum number of threads that can be supported by the electronic device and the total number of threads that are available to the electronic device are limited, for example, for a java application, a forwarding module in the electronic device that forwards a java application request is configured by a working thread number of a container deployed by the electronic device, for example, a maxThread configuration of a tomcat, that is, the number of threads running in the electronic device cannot exceed a maxThread configuration value, that is, the total number of threads that are available to the electronic device is a maxThread configuration value.
In this embodiment, the required threads of all applications accessing the electronic device cannot exceed the total number of available threads, and if so, the required threads exceed the affordable capability of the electronic device, and at this time, no new applications are allowed to access the electronic device.
It should be noted that, in order to avoid that the number of preset reserved threads set by each application is too large, as one implementation manner, a global reserved thread percentage threshold may be set for controlling the number of preset reserved threads of each application, and the ratio of the number of preset reserved threads of each application to the corresponding required number of threads cannot exceed the global reserved thread percentage threshold, as another implementation manner, a reserved thread percentage threshold may also be set for each application.
After the target application is allowed to access the electronic device 10, the client 20 may initiate a request for the target application to the electronic device 10, and in order to reasonably use idle threads in the required threads of the target application and the required threads of other applications except the target application, the embodiment provides an implementation manner for determining the type of the thread to be invoked corresponding to the request of the target application, which specifically includes: acquiring the number of used threads and the number of required threads of a target application; and secondly, if the number of the used threads is smaller than the number of the required threads, judging that the type of the thread to be called is the target application required thread, otherwise, judging that the type of the thread to be called is the non-target application required thread.
In this embodiment, if the number of used threads of the target application is smaller than the required number of threads, this means that the number of threads used by the target application does not exceed the required number of threads configured when the target application accesses the electronic device, and at this time, the electronic device may normally use the threads to forward the request for the request of the target application. If the number of used threads of the target application is greater than or equal to the required number of threads, the number of threads used by the target application is greater than or about to exceed the required number of threads configured by the target application, and the target application is idle in the required threads configured by the other threads.
When determining that the type of the thread to be invoked is not the target application requiring thread, in order to avoid that the target application uses the requiring threads of the rest applications without limitation, the embodiment further provides an implementation manner of determining whether the electronic device has a target application available thread according to the working thread upper limit threshold, which specifically includes:
firstly, obtaining the total number of available threads of the electronic equipment;
secondly, the number of reserved threads and the number of used threads of each application at the current moment are obtained;
in this embodiment, the number of reserved threads in each application at each time is dynamically changed, and is related to the number of used threads at the time and the preset reserved threads configured by the application, and one calculation method of the number of reserved threads is as follows:
(1) Calculating the difference value between the required thread number of each application and the used thread number at the current moment; (2) If the difference value is less than or equal to 0, the corresponding reserved thread number is set to 0; (3) If the difference value is greater than 0, the corresponding preset reserved thread number is obtained, and the smaller value of the difference value and the corresponding preset reserved thread number is set as the reserved thread number at the corresponding current moment. For example, if the number of used threads of application a at time t1 is 19, the required number of threads is 20, and the preset reserved number of threads is 2, the smaller value of the two values of (20-19) and 2, namely 1, of the reserved number of threads of application a at time t 1; if the number of used threads of application a is 22 at time t2, and exceeds the required number of threads, the number of reserved threads of application a is 0 at time t 2.
Thirdly, determining an upper limit threshold of the working thread according to the total number of the available threads, the reserved threads of all applications and the upper limit percentage of the preset working thread;
In this embodiment, the worker thread upper limit threshold= (total number of threads available-sum of number of threads reserved for all applications) ×preset worker thread upper limit percentage. For example, the electronic device has access to 3 applications: and the application A, B and the application C can reserve 10, 20 and 30 threads respectively, the total number of available threads is 1000, and the preset upper limit percentage of the working threads is 70%, so that the upper limit threshold of the working threads is= (1000- (10+20+30))x70% = 658.
And finally, if the sum of the used threads of all the applications is greater than or equal to the upper limit threshold of the working thread, judging that the electronic equipment does not have the available threads of the target application, otherwise, judging that the electronic equipment has the available threads of the target application.
It should be noted that, the purpose of setting the upper limit percentage of the preset worker thread is to: when a request for a newly accessed application or a request for a relatively idle application exists, a certain amount of idle threads are reserved in the electronic device, so that the threads of the electronic device are not occupied by all the requests for the busy application, and the requests for the newly accessed application or the requests for the relatively idle application cannot be forwarded normally.
It should be further noted that, the purpose of calculating the worker thread upper limit threshold value by adopting the calculation mode of the worker thread upper limit threshold value = (total number of available threads-sum of the number of retainable threads of all applications) ×preset worker thread upper limit percentage is that: reserving a certain number of threads for the application, wherein the more applications are accessed, the more threads need to be reserved; reserving a certain idle thread for the whole electronic equipment, and providing buffer time for releasing the thread for the application, so as to ensure the dynamic adjustment of the thread; when the number of threads which can be reserved is reduced due to the newly added threads (i.e. the threads which are needed to be newly created for forwarding the request), the upper limit threshold of the working thread is increased, so that the application of other overuse threads is not influenced as much as possible; when the newly added thread is not the retainable thread, the upper limit threshold of the working thread is unchanged, and the total number of used threads of all applications is increased, so that the number of threads of the application of the overuse thread can be limited.
Whether the type of the thread to be called is a target application requiring thread or the type of the thread to be called is a non-target application requiring thread and the electronic equipment has a target application available thread, the request of the target application can be forwarded normally, and the embodiment provides an implementation mode for forwarding the request:
creating a thread to be called based on the request; the request is forwarded by the thread to be invoked and the number of used threads of the target application is incremented.
In this embodiment, in order to timely release the number of threads occupied by the target application, after receiving the response message for the request, the electronic device 10 returns the response message to the client 20, and then the thread that processes the request may be released, which is implemented in the following manner:
If a response message to the request is received, the thread of the forwarding target application is released and the number of used threads is decremented.
In this embodiment, in order to more clearly illustrate the process of requesting dynamic current limiting, this embodiment further provides an exemplary diagram of dynamic current limiting, please refer to fig. 4, fig. 4 is an exemplary diagram of the process of dynamic current limiting provided in this embodiment, in fig. 4, the total number of available threads of the electronic device 10 is 300, and three applications are accessed: the number of required threads and the number of reserved threads of the preset reserved threads of the application A, B, C at the initial moment are 30, 3 and 3 respectively; 80. 8, 8; 150. 15, and by time t1, the number of used threads of application a, application B, and application C is 30, 10, 15, respectively, and at time t1+1, the electronic device receives a request for application a, where the number of used threads of application B and application C is 10, 15, respectively, the number of used threads of application a exceeds its required number of threads, and the current working thread upper threshold= (300- (0+8+15)) ×90% = 249, and the sum of the current used numbers of threads is: 10+15+30=55, the upper limit threshold of the working thread is not exceeded, so that application a can apply for a thread at time t1+1, therefore, at time t1+1, the number of used threads of application a is 31, from time t1+1 to time t2, the number of used threads of application a continues to increase, reaching 50, after which the number of used threads of application B and application C also gradually increase, respectively reaching 80, 150, at time t2+1, the electronic device receives a request for application a, the number of used threads of application a exceeds its required number of threads, and the current upper limit threshold of the working thread = (300- (0+0+0)) ×90% = 270, the sum of the current number of used threads of all applications is: 50+80+150=280, has exceeded the working thread upper threshold, so application a has not applied for a new thread at time t2+1, so application a has still a used thread count of 50 at time t2+1, starting from time t2+1 to time t3, application B and application C have used threads substantially maintained at their required thread count level, while application a has not applied for a new thread, while application a's used thread count is gradually released after the corresponding request has been processed, so application a's used thread count has dropped to its required thread count at time t3, i.e., application a used thread count of 30 at time t 3. As can be seen from the dynamic change of the number of used threads of each application at time t1 to time t3 in fig. 4, during time t1+1 to time t2, the number of requests of application a is relatively large at the beginning, the number of requests of application B and application C is relatively small, the number of threads used by application a exceeds the number of required threads, so that the full utilization of the threads of the electronic device 10 is realized, then, the number of requests of application B and application C is gradually increased, and the number of used threads of application a is gradually reduced from time t2+1 until the number of required threads is finally stabilized, so that the application a is prevented from occupying the threads exceeding the number of required threads without limitation to affect the normal forwarding of the requests of application B and application C.
In order to more clearly illustrate the interaction process between the client 20, the electronic device 10 and the application server 30, the present embodiment further provides an example diagram of the interaction process between the client, the electronic device and the application server, please refer to fig. 5, fig. 5 is an example diagram of the interaction process between the client, the electronic device and the application server, and in fig. 5, the three interaction steps are as follows:
s1: the electronic device 10 loads configuration information such as the total number of available threads, a global reserved thread percentage threshold value, a preset working thread upper limit percentage and the like;
s2: the application server A prepares registration information such as the required thread number, the preset reserved thread number and the like, and runs the application A;
s3: the application server A sends an access request carrying registration information to the electronic equipment 10;
s4: the electronic device 10 checks whether the access is allowed to the registration information of the application server a, and if the access is allowed to the registration information of the application server a, the access is allowed;
s5: the application server B prepares registration information such as the required thread number, the preset reserved thread number and the like;
S6: the application server B sends an access request carrying registration information to the electronic equipment 10;
s7: the electronic device 10 checks whether the access is allowed or not according to the registration information of the application server B, and refuses the access if the check is not passed;
S8: the client 20 initiates a request 1 to the electronic device 10 for the application server a;
S9: the electronic device 10 judges that the number of threads used by the application A does not exceed the required number of threads, and forwards the request 1 to the application server A;
s10: the client 20 initiates a request 2 to the electronic device 10 for the application server a;
s11: the electronic device 10 determines that the number of used threads of the application a exceeds the required number of threads, but the total number of used threads of all applications does not exceed the upper limit threshold of the working threads, and forwards the request 2 to the application server a;
S12: the client 20 initiates a request 3 to the electronic device 10 for the application server a;
S13: the electronic device 10 determines that the number of used threads of the application a exceeds the required number of threads, and that the total number of used threads of all applications exceeds the upper threshold of the worker thread, refuses to forward the request 3, and returns a prompt for refusing to forward to the client 20.
It should be noted that, in fig. 5, after the electronic device 10 forwards the request 1 and the request 2 to the application server a, response messages returned by the application server a for the request 1 and the request 2 are also received, and the respective response messages are returned to the client 20, where the response messages are not shown in fig. 5, but do not represent no response messages.
In order to perform the above-described embodiments and corresponding steps in each of the possible embodiments, an implementation of the request dynamic current limiting device 100 is given below. Referring to fig. 6, fig. 6 is a block diagram of a request dynamic current limiting device provided by the present invention, and it should be noted that, for brevity, the basic principle and the technical effects of the request dynamic current limiting device 100 provided by the present invention are the same as those of the corresponding embodiments described above, and the description of this embodiment is omitted.
The dynamic current limiting device 100 is applied to the electronic device 10 and comprises a determining module 110, a processing module 120 and an access module 130.
The determining module 110 determines the type of the thread to be invoked corresponding to the request when receiving the request corresponding to the target application, wherein the target application is any application in a plurality of applications in the access electronic device;
the processing module 120 is configured to forward a request to a target application if the type of the thread to be invoked is a target application requiring thread;
The processing module 120 is further configured to determine whether a target application available thread exists in the electronic device according to a working thread upper limit threshold if the type of the thread to be invoked is a non-target application requiring thread, where the working thread upper limit threshold is used to limit an upper limit of a used thread number of all applications in the electronic device;
The processing module 120 is further configured to forward the request to the target application if there is a thread available to the target application, and reject the forwarding request if not.
In an alternative embodiment, the determining module 110 is specifically configured to: acquiring the number of used threads and the number of required threads of a target application; if the number of the used threads is smaller than the number of the required threads, the type of the thread to be called is judged to be the target application required thread, otherwise, the type of the thread to be called is judged to be the non-target application required thread.
In an alternative embodiment, the determining module 110 is specifically configured to, when configured to determine whether the electronic device has a target application available thread according to the worker thread upper limit threshold: acquiring the total number of available threads of the electronic equipment; acquiring the number of retainable threads and the number of used threads at the current moment of each application; determining an upper limit threshold of the working thread according to the total number of the available threads, the reserved threads of all applications and the preset upper limit percentage of the working thread; if the sum of the used threads of all the applications is greater than or equal to the upper limit threshold of the working thread, the electronic equipment is judged to have no available thread of the target application, otherwise, the electronic equipment is judged to have available threads of the target application.
In an alternative embodiment, each application is preconfigured with a preset reserved thread number, and the determining module 110 is specifically configured to: calculating the difference value between the required thread number of each application and the used thread number at the current moment; if the difference value is less than or equal to 0, the corresponding reserved thread number is set to 0; if the difference value is greater than 0, the corresponding preset reserved thread number is obtained, and the smaller value of the difference value and the corresponding preset reserved thread number is set as the reserved thread number at the corresponding current moment.
In an alternative embodiment, the processing module 120 is specifically configured to: creating a thread to be called based on the request; the request is forwarded by the thread to be invoked and the number of used threads of the target application is incremented.
In an alternative embodiment, the processing module 120 is specifically further configured to: if a response message to the request is received, the thread of the forwarding target application is released and the number of used threads is decremented.
In an alternative embodiment, the access module 130 is configured to: receiving an access request of a target application, wherein the access request comprises the required thread number and the preset reserved thread number of the target application; acquiring the total number of required threads of all applications; all applications are applications accessed to the same electronic equipment; if the sum of the required thread count and the required thread count is smaller than or equal to the total number of available threads of the electronic device, and the ratio of the preset reserved thread count to the required thread count is smaller than or equal to the global reserved thread percentage threshold, accessing the target application into the electronic device; otherwise, refusing to access the target application to the electronic equipment.
An embodiment of the present invention provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements a method of dynamic throttling of requests as in any of the previous embodiments.
In summary, the embodiments of the present invention provide a method, an apparatus, an electronic device, and a readable storage medium for requesting dynamic current limiting, where the method is applied to the electronic device, and the method includes: when a request corresponding to a target application is received, determining the type of a thread to be called corresponding to the request, wherein the target application is any application in a plurality of applications in the access electronic equipment; if the type of the thread to be called is the target application requiring thread, forwarding a request to the target application; if the type of the thread to be called is a non-target application requiring thread, determining whether a target application available thread exists in the electronic equipment according to a working thread upper limit threshold, wherein the working thread upper limit threshold is used for limiting the upper limit of the number of used threads of all applications in the electronic equipment; if the available threads of the target application exist, forwarding the request to the target application, otherwise, refusing to forward the request. Compared with the prior art, the embodiment has at least the following advantages: (1) When the number of threads required by the target application is more and the number of threads used by other applications is less, the target application can use more threads than the number of threads required by the target application, and when the number of threads used by other applications is increased to a certain degree, the target application cannot continue to use more threads than the number of threads required by the target application, so that balance between thread resource utilization and thread isolation in the electronic equipment is realized, and the thread resources in the electronic equipment are reasonably utilized; (2) When an application accesses the electronic equipment, the reasonable control of the thread number of the application is realized in advance by setting the required thread number of the application and the preset reserved thread number; (3) According to the embodiment, a certain amount of idle threads are reserved in the electronic equipment through the preset upper limit percentage of the working threads, so that when a request for a newly accessed application exists or a request for a relatively idle application exists, the threads of the electronic equipment are not occupied by all the requests for busy applications, and the request for the newly accessed application or the request for the relatively idle application cannot be forwarded normally; (4) In the embodiment, by adopting a calculation mode of a working thread upper limit threshold value= (total number of available threads-sum of reserved threads of all applications) ×preset working thread upper limit percentage, on one hand, the thread is reserved for the applications; on the other hand, buffer time is provided for the application release thread, dynamic adjustment of the thread is guaranteed, and furthermore, when the reserved thread is reduced due to the newly added thread, the upper limit threshold of the working thread is increased, so that the application of other overuse threads is not influenced as much as possible; when the newly added thread is not the retainable thread, the upper limit threshold of the working thread is unchanged, and the total number of used threads of all applications is increased, so that the number of threads of the application of the overuse thread can be limited.
The foregoing is merely illustrative of the present invention, and the present invention is not limited thereto, and any changes or substitutions easily contemplated by those skilled in the art within the scope of the present invention should be included in the present invention. Therefore, the protection scope of the invention is subject to the protection scope of the claims.

Claims (10)

1. A method for dynamic current limiting of a request, applied to an electronic device, the method comprising:
When a request corresponding to a target application is received, determining the type of a thread to be called corresponding to the request, wherein the target application is any application in a plurality of applications in the electronic equipment;
if the type of the thread to be called is the target application requiring thread, forwarding the request to the target application;
If the type of the thread to be called is not the target application requiring thread, determining whether the target application available thread exists in the electronic equipment according to a working thread upper limit threshold, wherein the working thread upper limit threshold is used for limiting the upper limit of the number of used threads of all the applications in the electronic equipment;
If the available threads of the target application exist, forwarding the request to the target application, otherwise, refusing to forward the request.
2. The method of claim 1, wherein when a request corresponding to a target application is received, the step of determining a type of thread to be invoked corresponding to the request comprises:
acquiring the number of used threads and the number of required threads of the target application;
And if the number of the used threads is smaller than the number of the required threads, judging that the type of the thread to be called is the target application required thread, otherwise, judging that the type of the thread to be called is not the target application required thread.
3. The method of dynamic throttling a request of claim 1, wherein said step of determining whether said electronic device has a target application available thread based on a worker thread upper limit threshold comprises:
acquiring the total number of available threads of the electronic equipment;
Acquiring the number of reserved threads and the number of used threads at the current moment of each application;
determining an upper limit threshold of the working thread according to the total number of the available threads, the reserved thread numbers of all the applications and the preset upper limit percentage of the working thread;
and if the sum of the number of used threads of all the applications is greater than or equal to the upper limit threshold of the working thread, judging that the electronic equipment does not have the usable thread of the target application, otherwise, judging that the electronic equipment has the usable thread of the target application.
4. A method of dynamic current limiting for requests as recited in claim 3 wherein each of said applications is preconfigured with a preset number of reserved threads, and wherein said step of obtaining the number of reserved threads for each of said applications at the current time comprises:
calculating the difference value between the required thread number of each application and the used thread number at the current moment;
if the difference value is smaller than or equal to 0, setting the corresponding reserved thread number to 0;
If the difference value is greater than 0, the corresponding preset reserved thread number is obtained, and the smaller value of the difference value and the corresponding preset reserved thread number is set as the reserved thread number at the corresponding current moment.
5. The method of dynamic throttling a request of claim 1, wherein said step of forwarding said request comprises:
Creating the thread to be called based on the request;
and forwarding the request by utilizing the thread to be called and increasing the number of used threads of the target application.
6. The method of dynamic throttling of requests of claim 1, wherein after said step of forwarding said request, further comprising:
if a response message to the request is received, the thread forwarding the target application is released and its number of used threads is decremented.
7. The method of dynamic throttling of requests of claim 1, wherein prior to the step of receiving a request for a target application, further comprising:
receiving an access request of the target application, wherein the access request comprises the required thread number and the preset reserved thread number of the target application;
Acquiring the total number of required threads of all applications; all the applications are applications accessed to the same electronic equipment;
if the sum of the total required threads and the required threads is smaller than or equal to the total available threads of the electronic equipment, and the ratio of the preset reserved threads to the required threads is smaller than or equal to a global reserved thread percentage threshold, accessing the target application to the electronic equipment; otherwise, refusing to access the target application to the electronic equipment.
8. A dynamic current limiting apparatus for use with an electronic device, the apparatus comprising:
The determining module is used for determining the type of a thread to be called corresponding to a request when the request corresponding to a target application is received, wherein the target application is any application in a plurality of applications in the electronic equipment;
the processing module is used for forwarding the request to the target application if the type of the thread to be called is the thread required by the target application;
The processing module is further configured to determine whether a target application available thread exists in the electronic device according to a working thread upper limit threshold if the type of the thread to be invoked is a thread that is not required by the target application, where the working thread upper limit threshold is used to limit an upper limit of a used thread number of all applications in the electronic device;
The processing module is further configured to forward the request to the target application if the target application available thread exists, and reject forwarding the request if the target application available thread exists.
9. An electronic device comprising a processor and a memory, the memory for storing a program, the processor for implementing the dynamic current limiting method of request of any of claims 1-7 when the program is executed.
10. A computer readable storage medium, having stored thereon a computer program which, when executed by a processor, implements the requested dynamic throttling method of any of claims 1-7.
CN202410431337.1A 2024-04-11 2024-04-11 Method, device, electronic equipment and readable storage medium for requesting dynamic current limiting Pending CN118051346A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202410431337.1A CN118051346A (en) 2024-04-11 2024-04-11 Method, device, electronic equipment and readable storage medium for requesting dynamic current limiting

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202410431337.1A CN118051346A (en) 2024-04-11 2024-04-11 Method, device, electronic equipment and readable storage medium for requesting dynamic current limiting

Publications (1)

Publication Number Publication Date
CN118051346A true CN118051346A (en) 2024-05-17

Family

ID=91053870

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202410431337.1A Pending CN118051346A (en) 2024-04-11 2024-04-11 Method, device, electronic equipment and readable storage medium for requesting dynamic current limiting

Country Status (1)

Country Link
CN (1) CN118051346A (en)

Citations (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050262507A1 (en) * 2004-05-20 2005-11-24 Bea Systems, Inc. System and method for application server with self-tuned threading model
US20090183167A1 (en) * 2008-01-15 2009-07-16 Mark Gary Kupferschmidt Two-Tiered Dynamic Load Balancing Using Sets of Distributed Thread Pools
US20100153962A1 (en) * 2008-12-11 2010-06-17 Serban Tatu Method and system for controlling distribution of work items to threads in a server
US20110219377A1 (en) * 2010-03-05 2011-09-08 Rohith Thammana Gowda Dynamic thread pool management
CN108681481A (en) * 2018-03-13 2018-10-19 阿里巴巴集团控股有限公司 The processing method and processing device of service request
US20180357291A1 (en) * 2017-06-07 2018-12-13 Sap Se Dynamic admission control for database requests
US20180375784A1 (en) * 2017-06-27 2018-12-27 Microsoft Technology Licensing, Llc Throttling queue for a request scheduling and processing system
CN109710400A (en) * 2018-12-17 2019-05-03 平安普惠企业管理有限公司 The method and device of thread resources grouping
CN110032434A (en) * 2019-03-12 2019-07-19 平安普惠企业管理有限公司 A kind of method of adjustment and device of semaphore license
CN111857992A (en) * 2020-06-24 2020-10-30 厦门网宿有限公司 Thread resource allocation method and device in Radosgw module
CN113867954A (en) * 2021-09-27 2021-12-31 苏州九宫数字科技有限公司 Thread processing method, system and medium based on thread pool and object pool
CN113961338A (en) * 2021-09-17 2022-01-21 国网电力科学研究院有限公司 Management system and management method of dynamic thread pool and thread task processing method
CN117707716A (en) * 2023-05-26 2024-03-15 荣耀终端有限公司 Thread scheduling method, electronic device and computer readable storage medium

Patent Citations (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050262507A1 (en) * 2004-05-20 2005-11-24 Bea Systems, Inc. System and method for application server with self-tuned threading model
US20090183167A1 (en) * 2008-01-15 2009-07-16 Mark Gary Kupferschmidt Two-Tiered Dynamic Load Balancing Using Sets of Distributed Thread Pools
US20100153962A1 (en) * 2008-12-11 2010-06-17 Serban Tatu Method and system for controlling distribution of work items to threads in a server
US20110219377A1 (en) * 2010-03-05 2011-09-08 Rohith Thammana Gowda Dynamic thread pool management
US20180357291A1 (en) * 2017-06-07 2018-12-13 Sap Se Dynamic admission control for database requests
US20180375784A1 (en) * 2017-06-27 2018-12-27 Microsoft Technology Licensing, Llc Throttling queue for a request scheduling and processing system
CN108681481A (en) * 2018-03-13 2018-10-19 阿里巴巴集团控股有限公司 The processing method and processing device of service request
CN109710400A (en) * 2018-12-17 2019-05-03 平安普惠企业管理有限公司 The method and device of thread resources grouping
CN110032434A (en) * 2019-03-12 2019-07-19 平安普惠企业管理有限公司 A kind of method of adjustment and device of semaphore license
CN111857992A (en) * 2020-06-24 2020-10-30 厦门网宿有限公司 Thread resource allocation method and device in Radosgw module
CN113961338A (en) * 2021-09-17 2022-01-21 国网电力科学研究院有限公司 Management system and management method of dynamic thread pool and thread task processing method
CN113867954A (en) * 2021-09-27 2021-12-31 苏州九宫数字科技有限公司 Thread processing method, system and medium based on thread pool and object pool
CN117707716A (en) * 2023-05-26 2024-03-15 荣耀终端有限公司 Thread scheduling method, electronic device and computer readable storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
王俊峰;谢冬青;: "基于线程池技术集群接入点的应用研究", 微计算机信息, no. 24, 24 August 2009 (2009-08-24) *

Similar Documents

Publication Publication Date Title
US7694054B2 (en) Governing access to a computing resource
WO2021254331A1 (en) Resource management method and system, proxy server, and storage medium
EP0671035A1 (en) Software overload control method
CN111104227A (en) Resource control method and device of K8s platform and related components
CN110838987B (en) Queue current limiting method and storage medium
CN115190078B (en) Access flow control method, device, equipment and storage medium
JP2023092413A (en) Capacity reduction method and device based on cluster
CN114143327A (en) Cluster resource quota allocation method and device and electronic equipment
CN111104213B (en) Method and device for adjusting fusing
CN118051346A (en) Method, device, electronic equipment and readable storage medium for requesting dynamic current limiting
CN111338803B (en) Thread processing method and device
CN112671945A (en) Method, device, computer equipment and storage medium for managing IP proxy pool
CN115794396A (en) Resource allocation method, system and electronic equipment
US20220286499A1 (en) Apparatus and method for autoscaling service shared in cloud
CN111045819A (en) Resource request method, device, equipment and storage medium of distributed system
CN116489103A (en) Service flow limiting method, device and service processing system
CN114422530A (en) Flow control method and device, computer equipment and storage medium
CN110401708B (en) Session processing system and method based on server load state
CN115408106A (en) Method and system for sharing algorithm resources among virtual machines
CN112328387A (en) Multi-tenant-oriented micro-service resource scheduling method
CN109257201B (en) License sending method and device
CN115174479B (en) Flow control method and device
CN116708297B (en) Cross-platform server flow resource adjusting method, system and device
CN111258751A (en) Method, device and medium for controlling resource access
CN112118275A (en) Overload processing method, Internet of things platform and computer readable storage medium

Legal Events

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