Thread scheduling method and apparatus, storage medium, and electronic device

CN117149374BActive Publication Date: 2026-10-27BEIJING QIYI CENTURY SCI & TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310929794.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-07-26
Publication Date
2026-10-27
Estimated Expiration
2043-07-26

AI Technical Summary

Technical Problem

[0002]当上游服务调用下游服务的接口,下游服务的接口流量较大时,会导致上游服务的线程被流量较大的下游服务的接口占用,而被占用的线程无法被及时释放,导致其它下游服务接口没有可用线程,使得上游服务的线程的利用率较低

Benefits of technology

[0037]本申请实施例提供的技术方案,通过获取目标上游服务代理的下游服务接口,确定所述下游服务接口的每秒请求数占目标上游服务的每秒请求数的第一占比,确定所述下游服务接口的每秒请求数中接口响应时间大于预设响应时间阈值的请求数占所述下游服务接口的每秒请求数的第二占比,确定所述下游服务接口的线程数量占所述目标上游服务的总线程数量的第三占比,根据所述下游服务接口对应的所述第一占比、所述第二占比以及所述第三占比,判断所述下游服务接口是否为预设的目标下游服务接口,若所述下游服务接口为预设的目标下游服务接口,将所述预设的目标下游服务接口的线程数量调小。本申请中通过确定的第一占比、第二占比以及第三占比调整目标上游服务代理的下游服务接口的线程数量,可以使得下游服务占用的线程数量被及时释放,从而提高上游服务线程的利用率。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117149374B_ABST
    Figure CN117149374B_ABST
Patent Text Reader

Abstract

The application discloses a thread scheduling method and device, a storage medium and an electronic device. The method comprises the following steps: acquiring a downstream service interface of a target upstream service agent, determining a first proportion of the number of requests per second of the downstream service interface in the number of requests per second of the target upstream service, determining a second proportion of the number of requests per second of the downstream service interface, of which the interface response time is greater than a preset response time threshold, in the number of requests per second of the downstream service interface, determining a third proportion of the number of threads of the downstream service interface in the total number of threads of the target upstream service, determining whether the downstream service interface is a preset target downstream service interface according to the first proportion, the second proportion and the third proportion of the downstream service interface, and reducing the number of threads of the preset target downstream service interface if the downstream service interface is the preset target downstream service interface. The application can release the number of threads occupied by the downstream service in time, thereby improving the utilization rate of the upstream service thread.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, specifically to a thread scheduling method, apparatus, storage medium, and electronic device. Background Technology

[0002] When an upstream service calls the interface of a downstream service, and the interface traffic of the downstream service is high, the threads of the upstream service will be occupied by the interface of the downstream service with high traffic. The occupied threads cannot be released in time, resulting in no available threads for other downstream service interfaces, and thus the utilization rate of the threads of the upstream service is low. Summary of the Invention

[0003] This application provides a thread scheduling method, apparatus, storage medium, and electronic device that can improve the utilization rate of upstream service threads.

[0004] In a first aspect, embodiments of this application provide a thread scheduling method, including:

[0005] Obtain the downstream service interface of the target upstream service proxy;

[0006] Determine the first percentage of the number of requests per second of the downstream service interface relative to the number of requests per second of the target upstream service;

[0007] Determine the second proportion of the number of requests per second of the downstream service interface whose interface response time is greater than a preset response time threshold.

[0008] Determine the third percentage of the number of threads in the downstream service interface relative to the total number of threads in the target upstream service;

[0009] Based on the first proportion, the second proportion, and the third proportion corresponding to the downstream service interface, it is determined whether the downstream service interface is a preset target downstream service interface;

[0010] If the downstream service interface is a preset target downstream service interface, reduce the number of threads of the preset target downstream service interface.

[0011] In some embodiments, determining whether a downstream service interface is a preset target downstream service interface based on the first proportion, the second proportion, and the third proportion corresponding to the downstream service interface includes:

[0012] Determine whether the first proportion is greater than a preset first threshold, whether the second proportion is greater than a preset second threshold, and whether the third proportion is greater than a preset third threshold;

[0013] If the first proportion is greater than a preset first threshold, the second proportion is greater than a preset second threshold, and the third proportion is greater than a preset third threshold, then the downstream service interface is determined to be the preset target downstream service interface.

[0014] In some embodiments, determining whether the first proportion is greater than a preset first threshold, whether the second proportion is greater than a preset second threshold, and whether the third proportion is greater than a preset third threshold includes:

[0015] Determine whether, within a continuous preset first time period, the first proportion of the downstream service interface is greater than a preset first threshold, the second proportion is greater than a preset second threshold, and the third proportion is greater than a preset third threshold.

[0016] In some embodiments, determining whether the downstream service interface is a preset target downstream service interface includes:

[0017] If, within a consecutive preset first time period, the first proportion of the downstream service interface is greater than a preset first threshold, the second proportion is greater than a preset second threshold, and the third proportion is greater than a preset third threshold, then the downstream service interface is determined to be the preset target downstream service interface.

[0018] In some embodiments, reducing the number of threads in the preset target downstream service interface includes:

[0019] Obtain the total number of threads in the target upstream service and the total number of downstream service interfaces proxied by the target upstream service;

[0020] The target thread count is obtained by dividing the total number of threads in the target upstream service by the total number of threads.

[0021] Adjust the preset number of threads for the target downstream service interface to the target number of threads.

[0022] In some embodiments, after adjusting the preset number of threads for the target downstream service interface to the target number of threads, the method further includes:

[0023] Detect whether the second percentage of the preset target downstream service interface is less than a preset fourth threshold within a consecutive preset second time period;

[0024] If the second percentage of the preset target downstream service interface is less than the preset fourth threshold for a consecutive preset second time period, then the number of threads corresponding to the preset target downstream service interface will be adjusted back to the number of threads before the last adjustment.

[0025] In some embodiments, after adjusting the number of threads corresponding to the preset target downstream service interface back to the number of threads before the last adjustment, the method further includes:

[0026] If the second proportion of the preset target downstream service interface is not less than the preset fourth threshold in a continuous preset second time period, then it is detected whether the second proportion of the preset target downstream service interface is greater than the preset second threshold in a continuous preset third time period.

[0027] If the second percentage of the preset target downstream service interface is greater than the preset second threshold for a consecutive preset third time period, then the number of threads of the preset target downstream service interface is adjusted to a preset percentage of the currently adjusted number of threads, and the process proceeds to the step of detecting whether the second percentage of the preset target downstream service interface is less than a preset fourth threshold for a consecutive preset second time period, wherein the preset percentage is greater than 0 and less than 1.

[0028] Secondly, embodiments of this application also provide a thread scheduling device, comprising:

[0029] The acquisition unit is used to acquire the downstream service interface of the target upstream service proxy;

[0030] The first determining unit is used to determine the first percentage of the number of requests per second of the downstream service interface to the number of requests per second of the target upstream service;

[0031] The second determining unit is used to determine the second proportion of the number of requests with an interface response time greater than a preset response time threshold in the number of requests per second of the downstream service interface.

[0032] The third determining unit is used to determine the third percentage of the number of threads of the downstream service interface relative to the total number of threads of the target upstream service;

[0033] The judgment unit is used to determine whether the downstream service interface is a preset target downstream service interface based on the first proportion, the second proportion and the third proportion corresponding to the downstream service interface.

[0034] The scheduling unit is used to reduce the number of threads of the preset target downstream service interface if the downstream service interface is a preset target downstream service interface.

[0035] Thirdly, embodiments of this application also provide a computer-readable storage medium having a computer program stored thereon, which, when run on a computer, causes the computer to execute the thread scheduling method provided in any embodiment of this application.

[0036] Fourthly, embodiments of this application also provide an electronic device, including a processor and a memory, wherein the memory has a computer program, and the processor executes a thread scheduling method as provided in any embodiment of this application by calling the computer program.

[0037] The technical solution provided in this application obtains the downstream service interface of the target upstream service proxy, determines the first percentage of the number of requests per second of the downstream service interface relative to the total number of requests per second of the target upstream service, determines the second percentage of the number of requests per second of the downstream service interface whose interface response time is greater than a preset response time threshold relative to the total number of requests per second of the downstream service interface, and determines the third percentage of the number of threads of the downstream service interface relative to the total number of threads of the target upstream service. Based on the first, second, and third percentages corresponding to the downstream service interface, it is determined whether the downstream service interface is a preset target downstream service interface. If the downstream service interface is a preset target downstream service interface, the number of threads of the preset target downstream service interface is reduced. By adjusting the number of threads of the downstream service interface of the target upstream service proxy through the determined first, second, and third percentages in this application, the number of threads occupied by the downstream service can be released in a timely manner, thereby improving the utilization rate of the upstream service threads. Attached Figure Description

[0038] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0039] Figure 1 This is a flowchart illustrating a thread scheduling method provided in an embodiment of this application.

[0040] Figure 2 This is a flowchart illustrating the thread scheduling method provided in this application embodiment in a real-world application scenario.

[0041] Figure 3 This is a schematic diagram of the structure of the thread scheduling device provided in the embodiments of this application.

[0042] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0043] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the protection scope of this application.

[0044] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.

[0045] This application provides a thread scheduling method. The execution entity of this thread scheduling method can be the thread scheduling device provided in this application, or an electronic device integrating the thread scheduling device. The thread scheduling device can be implemented in hardware or software. The electronic device can be a smartphone, tablet computer, PDA, laptop computer, or desktop computer, etc.

[0046] Please see Figure 1 , Figure 1 This is a flowchart illustrating a thread scheduling method provided in an embodiment of this application. The thread scheduling method provided in this embodiment may include steps S110 to S160, as follows:

[0047] S110. Obtain the downstream service interface of the target upstream service proxy.

[0048] In this embodiment, the upstream service may proxy one or more downstream service interfaces. For example, service A may proxy the interfaces of multiple services such as B, C, and D in different scenarios. Service A is the upstream service, and B, C, and D are the downstream services. The interfaces that the upstream service proxies for the downstream services are the downstream service interfaces. For example, service A is a gateway system, service B is an order list, service C is a coupon, and service D is a voucher. The page request enters from the gateway and then requests the downstream system interfaces B, C, and D.

[0049] For ease of description, this application uses one of the downstream service interfaces of the target upstream service proxy as an example to illustrate the thread scheduling method provided in this application. It is understood that all downstream service interfaces of the target upstream service proxy can be adjusted using the thread scheduling method provided in this application.

[0050] S120. Determine the first percentage of the number of requests per second of the downstream service interface relative to the number of requests per second of the target upstream service.

[0051] Queries Per Second (QPS) is the number of queries a server can respond to per second. It is a measure of the amount of traffic a specific query server can process within a specified time, i.e., the number of response requests per second.

[0052] In this embodiment, the number of requests per second of the downstream service interface and the number of requests per second of the target upstream service can be obtained, and then the first proportion can be determined based on the obtained number of requests per second of the downstream service interface and the obtained number of requests per second of the target upstream service.

[0053] Specifically, the formula for calculating the first percentage is: number of requests per second of the downstream service interface / number of requests per second of the target upstream service.

[0054] For ease of description, percentages are used in this application.

[0055] S130. Determine the second proportion of the number of requests per second of the downstream service interface whose interface response time is greater than a preset response time threshold.

[0056] The preset response time threshold can be set by those skilled in the art according to the actual scenario.

[0057] In this embodiment, the number of requests with a response time greater than a preset response time threshold among the requests per second of the downstream service interface can be obtained, and the number of requests per second of the downstream service interface can be obtained. Then, the second proportion can be determined based on the number of requests with a response time greater than the preset response time threshold among the requests per second of the downstream service interface and the number of requests per second of the downstream service interface.

[0058] Specifically, the formula for calculating the second percentage is: the number of requests per second of the downstream service interface with an interface response time greater than a preset response time threshold / the number of requests per second of the downstream service interface.

[0059] S140. Determine the third percentage of the number of threads of the downstream service interface relative to the total number of threads of the target upstream service.

[0060] In this embodiment, the number of threads of the downstream service interface and the total number of threads of the target upstream service can be obtained, and then the third proportion can be determined based on the obtained number of threads of the downstream service interface and the obtained total number of threads of the target upstream service.

[0061] Specifically, the formula for calculating the third percentage is: number of threads in the downstream service interface / total number of threads in the target upstream service.

[0062] It is understood that the percentages determined in this application are the first percentage, the second percentage, and the third percentage corresponding to a certain downstream server.

[0063] S150. Based on the first proportion, the second proportion, and the third proportion corresponding to the downstream service interface, determine whether the downstream service interface is a preset target downstream service interface.

[0064] Specifically, the first, second, and third percentages corresponding to the preset target downstream service interfaces each meet certain percentage thresholds. The specific percentage thresholds can be set by those skilled in the art based on actual circumstances. For example, the preset first percentage of the target downstream service interfaces can be set to be greater than 50%, the second percentage greater than 90%, and the third percentage greater than 60%.

[0065] It should be noted that the target downstream service interface preset in this application corresponds to the downstream service interface with high traffic. The thread scheduling method provided in this application is to ensure that the number of threads occupied by these downstream service interfaces with high traffic can be released in a timely manner, so as to ensure that the calls of other downstream services will not be squeezed out, and at the same time avoid the downtime caused by the upstream service's thread count being full.

[0066] In this embodiment, the downstream service interface can be determined to be the preset target downstream service interface by judging whether it meets the preset target downstream service interface's percentage threshold by using the first percentage, second percentage and third percentage corresponding to the downstream service interface.

[0067] S160. If the downstream service interface is a preset target downstream service interface, reduce the number of threads of the preset target downstream service interface.

[0068] In this embodiment, if the downstream service interface is a preset target downstream service interface, the number of threads of the preset target downstream service interface is reduced.

[0069] For example, if the first percentage of a downstream service interface is greater than 50%, the second percentage is greater than 90%, and the third percentage is greater than 60%, then the number of threads for that downstream service interface will be reduced.

[0070] In practice, this application is not limited by the execution order of the described steps. Without causing conflicts, some steps may be performed in other orders or simultaneously.

[0071] As can be seen from the above, by obtaining the downstream service interface of the target upstream service proxy, the first percentage of the number of requests per second of the downstream service interface relative to the number of requests per second of the target upstream service is determined; the second percentage of the number of requests per second of the downstream service interface whose interface response time is greater than a preset response time threshold is determined; and the third percentage of the number of threads of the downstream service interface relative to the total number of threads of the target upstream service is determined. Based on the first, second, and third percentages corresponding to the downstream service interface, it is determined whether the downstream service interface is a preset target downstream service interface. If the downstream service interface is a preset target downstream service interface, the number of threads of the preset target downstream service interface is reduced. In this application, adjusting the number of threads of the downstream service interface of the target upstream service proxy by determining the first, second, and third percentages can ensure that the number of threads occupied by the downstream service is released in a timely manner, thereby improving the utilization rate of the upstream service threads.

[0072] In some embodiments, step S150, "determining whether the downstream service interface is a preset target downstream service interface based on the first proportion, the second proportion, and the third proportion corresponding to the downstream service interface," may include the following steps:

[0073] S1510. Determine whether the first proportion is greater than a preset first threshold, whether the second proportion is greater than a preset second threshold, and whether the third proportion is greater than a preset third threshold.

[0074] The preset first threshold, preset second threshold, preset third threshold, and preset first duration are set by those skilled in the art according to the actual scenario.

[0075] For example, the first threshold is set to 50%, the second threshold is set to 90%, and the third threshold is set to 60%, which corresponds to the first proportion of the target downstream service interface being greater than 50%, the second proportion being greater than 90%, and the third proportion being greater than 60%.

[0076] It is understandable that there may be one or more of the preset target downstream service interfaces.

[0077] S1520. If the first proportion is greater than a preset first threshold, the second proportion is greater than a preset second threshold, and the third proportion is greater than a preset third threshold, then the downstream service interface is determined to be the preset target downstream service interface.

[0078] In this embodiment, a first proportion of the target downstream service interface is set to be greater than a first preset threshold, a second proportion is set to be greater than a second preset threshold, and a third proportion is set to be greater than a third preset threshold. It can be understood that when a downstream service interface meets the proportion threshold corresponding to the target service interface, then the downstream service interface is the target downstream service interface.

[0079] In some embodiments, step S150, "determining whether the downstream service interface is a preset target downstream service interface based on the first proportion, the second proportion, and the third proportion corresponding to the downstream service interface," may include the following steps:

[0080] S1530. Determine whether, within a continuous preset first time period, the first proportion of the downstream service interface is greater than a preset first threshold, the second proportion is greater than a preset second threshold, and the third proportion is greater than a preset third threshold.

[0081] The preset first duration is set by those skilled in the art based on the actual scenario.

[0082] In this embodiment, a first percentage of the target downstream service interface can be set to be greater than a first threshold for a continuous first time period, a second percentage to be greater than a second threshold for a continuous first time period, and a third percentage to be greater than a third threshold for a continuous first time period.

[0083] For example, the first preset threshold can be set to 50%, the second preset threshold to 90%, the third preset threshold to 60%, and the first preset duration to 1 minute. That is, the preset target downstream service satisfies that the first percentage is greater than 50%, the second percentage is greater than 90%, and the third percentage is greater than 60% within a consecutive 1 minute.

[0084] S1540. If, within a consecutive preset first time period, the first proportion of the downstream service interface is greater than a preset first threshold, the second proportion is greater than a preset second threshold, and the third proportion is greater than a preset third threshold, then the downstream service interface is determined to be the preset target downstream service interface.

[0085] It is understandable that when a downstream service interface meets the preset percentage threshold corresponding to the target service interface, then that downstream service interface is the preset target downstream service interface.

[0086] In some embodiments, step S160, "If the downstream service interface is a preset target downstream service interface, reduce the number of threads of the preset target downstream service interface," may include the following steps:

[0087] S1610. Obtain the total number of threads of the target upstream service and the total number of downstream service interfaces proxied by the target upstream service;

[0088] S1620. The target thread count is obtained by dividing the total number of threads in the target upstream service by the total number of threads.

[0089] In this embodiment, the formula for calculating the target thread count is: total number of threads in the target upstream service / total number of downstream service interfaces proxied by the target upstream service.

[0090] S1630. Adjust the preset number of threads of the target downstream service interface to the target number of threads.

[0091] In this embodiment, the number of threads of the preset target downstream service interface is adjusted to the target number of threads calculated above, so as to reduce the number of threads of the preset target downstream service interface.

[0092] In some embodiments, after step S1630 "adjusting the number of threads of the preset target downstream service interface to the target number of threads", the following steps may also be included:

[0093] S1640. Detect whether the second proportion of the preset target downstream service interface is less than the preset fourth threshold within a continuous preset second time period.

[0094] The preset fourth threshold and the preset second duration are set by those skilled in the art according to the actual scenario.

[0095] For example, the preset fourth threshold is set to 50%, and the preset second duration is set to 1 minute, which means detecting whether the second percentage of the preset target downstream service interface is less than 50% within a consecutive 1 minute.

[0096] S1650. If the second percentage of the preset target downstream service interface is less than the preset fourth threshold for a consecutive preset second time period, then the number of threads corresponding to the preset target downstream service interface is adjusted back to the number of threads before the last adjustment.

[0097] For example, if the second percentage of the preset target downstream service interface is less than 50% for a continuous 1 minute, then the number of threads corresponding to the preset target downstream service interface will be adjusted back to the number of threads before the last adjustment.

[0098] The previous adjustment in this step corresponds to step S1630, where the thread count before step S1630 was the initial thread count. This initial thread count refers to the thread count before the preset target downstream service interface thread count was adjusted. This step adjusts the thread count back to the level before the previous adjustment, that is, adjusts the thread count corresponding to the preset target downstream service interface to this initial thread count.

[0099] In some embodiments, after step S1650 "if the second proportion of the preset target downstream service interface is less than the preset fourth threshold for a consecutive preset second time period, then the number of threads corresponding to the target downstream service interface is adjusted back to the number of threads before the last adjustment", the following steps may also be included:

[0100] S1660. If the second proportion of the preset target downstream service interface is not less than the preset fourth threshold in a continuous preset second time period, then detect whether the second proportion of the preset target downstream service interface is greater than the preset second threshold in a continuous preset third time period.

[0101] The preset third duration can be set by those skilled in the art based on the actual scenario.

[0102] For example, if the preset third duration is 1 minute, and the preset target downstream service interface has a second proportion that is not less than 50% for a continuous 1 minute, then the detection will check whether the preset target downstream service interface has a second proportion that is greater than 90% for a continuous 1 minute.

[0103] S1670. If the second percentage of the preset target downstream service interface is greater than the preset second threshold for a continuous preset third time period, then the number of threads of the preset target downstream service interface is adjusted to a preset percentage of the currently adjusted number of threads, and the process proceeds to the step of detecting whether the second percentage of the preset target downstream service interface is less than a preset fourth threshold for a continuous preset second time period, wherein the preset percentage is greater than 0 and less than 1.

[0104] The preset ratio can be set to 0.5, which means adjusting the preset number of threads for the target downstream service interface to 0.5 times the currently adjusted number of threads. This preset ratio can be set by those skilled in the art according to the actual scenario. The currently adjusted number of threads is also the currently preset number of threads for the target downstream server interface.

[0105] In this embodiment, for example, if the second percentage of the preset target downstream service interface is greater than 90% for a continuous 1 minute, the number of threads of the preset target downstream service interface is adjusted to the preset ratio of the currently adjusted number of threads, and the process proceeds to step S1640.

[0106] In this embodiment, the number of threads for upstream services to call downstream services can be automatically adjusted. If one of the downstream services has a problem, the number of allocated threads is reduced according to the thread scheduling method provided in this application, ensuring that calls to other downstream services will not be squeezed out, and that the number of threads for upstream services will not be filled by calls to problematic downstream services, thus preventing downtime. After the downstream service is detected to have recovered, the number of threads is automatically restored to the number before the last adjustment.

[0107] To better illustrate the thread scheduling method in this application, we will take the target upstream service A and the downstream service interface J of the downstream service B proxied by the target upstream service A as an example to explain the thread scheduling method in this application. Please refer to [link / reference]. Figure 2 , Figure 2 A flowchart illustrating the thread scheduling method provided in this application embodiment in a real-world application scenario includes the following steps:

[0108] S1. Obtain the first percentage, second percentage, and third percentage corresponding to the downstream service interface J proxied by the upstream service A.

[0109] S2. Determine whether, within a continuous preset first time period, the first proportion of downstream service interface J is greater than the preset first threshold, the second proportion is greater than the preset second threshold, and the third proportion is greater than the preset third threshold. If yes, proceed to step S4; otherwise, proceed to step S3.

[0110] S3. Keep the number of threads in the downstream service interface J at the initial number of threads.

[0111] S4. Adjust the number of threads in the downstream service interface J to the target number of threads.

[0112] S5. Detect whether the second proportion of the downstream service interface J is less than the preset fourth threshold within a continuous preset second time period. If yes, proceed to step S3; otherwise, proceed to step S6.

[0113] In step S3, the number of threads in the downstream service interface J is adjusted back to the number of threads before the last adjustment, which means adjusting the number of threads in the downstream service interface J back to the initial number of threads in the downstream service interface J.

[0114] S6. Detect whether the second proportion of the downstream service interface J is greater than the preset second threshold within a continuous preset third time period. If yes, proceed to step S7; otherwise, proceed to step S5.

[0115] S7. Adjust the number of threads in the downstream service interface J to the preset ratio of the currently adjusted number of threads.

[0116] In one embodiment, a thread scheduling device is also provided. See also... Figure 3 , Figure 3 This is a schematic diagram of the structure of a thread scheduling device 300 provided in an embodiment of this application. The thread scheduling device 300 is applied to an electronic device and includes an acquisition unit 301, a first determination unit 302, a second determination unit 303, a third determination unit 304, a judgment unit 305, and a scheduling unit 306, as follows:

[0117] Acquisition unit 301 is used to acquire the downstream service interface of the target upstream service proxy;

[0118] The first determining unit 302 is used to determine the first percentage of the number of requests per second of the downstream service interface to the number of requests per second of the target upstream service;

[0119] The second determining unit 303 is used to determine the second proportion of the number of requests with an interface response time greater than a preset response time threshold in the number of requests per second of the downstream service interface.

[0120] The third determining unit 304 is used to determine the third percentage of the number of threads of the downstream service interface relative to the total number of threads of the target upstream service;

[0121] The judgment unit 305 is used to determine whether the downstream service interface is a preset target downstream service interface based on the first proportion, the second proportion and the third proportion corresponding to the downstream service interface.

[0122] The scheduling unit 306 is used to reduce the number of threads of the preset target downstream service interface if the downstream service interface is a preset target downstream service interface.

[0123] In some embodiments, the determining unit 305 may be used to:

[0124] Determine whether the first proportion is greater than a preset first threshold, whether the second proportion is greater than a preset second threshold, and whether the third proportion is greater than a preset third threshold;

[0125] If the first proportion is greater than a preset first threshold, the second proportion is greater than a preset second threshold, and the third proportion is greater than a preset third threshold, then the downstream service interface is determined to be the preset target downstream service interface.

[0126] In some embodiments, the determining unit 305 may be used to:

[0127] Determine whether, within a consecutive preset first time period, the first proportion of the downstream service interface is greater than a preset first threshold, the second proportion is greater than a preset second threshold, and the third proportion is greater than a preset third threshold.

[0128] If, within a consecutive preset first time period, the first proportion of the downstream service interface is greater than a preset first threshold, the second proportion is greater than a preset second threshold, and the third proportion is greater than a preset third threshold, then the downstream service interface is determined to be the preset target downstream service interface.

[0129] In some embodiments, the scheduling unit 306 can be used for:

[0130] Obtain the total number of threads in the target upstream service and the total number of downstream service interfaces proxied by the target upstream service;

[0131] The target thread count is obtained by dividing the total number of threads in the target upstream service by the total number of threads.

[0132] Adjust the preset number of threads for the target downstream service interface to the target number of threads.

[0133] In some embodiments, the scheduling unit 306 can also be used for:

[0134] Detect whether the second percentage of the preset target downstream service interface is less than a preset fourth threshold within a consecutive preset second time period;

[0135] If the second percentage of the preset target downstream service interface is less than the preset fourth threshold for a consecutive preset second time period, then the number of threads corresponding to the preset target downstream service interface will be adjusted back to the number of threads before the last adjustment.

[0136] In some embodiments, the scheduling unit 306 can also be used for:

[0137] If the second proportion of the preset target downstream service interface is not less than the preset fourth threshold in a continuous preset second time period, then it is detected whether the second proportion of the preset target downstream service interface is greater than the preset second threshold in a continuous preset third time period.

[0138] If the second percentage of the preset target downstream service interface is greater than the preset second threshold for a consecutive preset third time period, then the number of threads of the preset target downstream service interface is adjusted to a preset percentage of the currently adjusted number of threads, and the process proceeds to the step of detecting whether the second percentage of the preset target downstream service interface is less than a preset fourth threshold for a consecutive preset second time period, wherein the preset percentage is greater than 0 and less than 1.

[0139] It should be noted that the thread scheduling device provided in this application embodiment belongs to the same concept as the thread scheduling method in the above embodiment. Any of the methods provided in the thread scheduling method embodiment can be implemented through this thread scheduling device. For details of its implementation process, please refer to the thread scheduling method embodiment, which will not be repeated here.

[0140] Furthermore, to better implement the thread scheduling method in the embodiments of this application, this application also provides an electronic device based on the thread scheduling method. Please refer to... Figure 4 , Figure 4 A schematic diagram of one structure of the electronic device 400 provided in this application is shown, such as... Figure 4 As shown, the electronic device 400 provided in this application includes a processor 401 and a memory 402. When the processor 401 executes the computer program stored in the memory 402, it implements the steps of the thread scheduling method as described in the above embodiments of this application, such as:

[0141] Obtain the downstream service interface of the target upstream service proxy;

[0142] Determine the first percentage of the number of requests per second of the downstream service interface relative to the number of requests per second of the target upstream service;

[0143] Determine the second proportion of the number of requests per second of the downstream service interface whose interface response time is greater than a preset response time threshold.

[0144] Determine the third percentage of the number of threads in the downstream service interface relative to the total number of threads in the target upstream service;

[0145] Based on the first proportion, the second proportion, and the third proportion corresponding to the downstream service interface, it is determined whether the downstream service interface is a preset target downstream service interface;

[0146] If the downstream service interface is a preset target downstream service interface, reduce the number of threads of the preset target downstream service interface.

[0147] For example, a computer program may be divided into one or more modules / units, one or more of which are stored in memory 402 and executed by processor 401 to complete the embodiments of this application. One or more modules / units may be a series of computer program instruction segments capable of performing a specific function, which describe the execution process of the computer program in a computer device.

[0148] Electronic device 400 may include, but is not limited to, processor 401 and memory 402. Those skilled in the art will understand that the illustrations are merely examples of electronic device 400 and do not constitute a limitation on electronic device 400. It may include more or fewer components than illustrated, or combine certain components, or different components. For example, electronic device 400 may also include input / output devices, network access devices, buses, etc., with processor 401, memory 402, input / output devices, and network access devices connected via a bus.

[0149] Processor 401 can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor. The processor is the control center of electronic device 400, connecting various parts of the electronic device 400 through various interfaces and lines.

[0150] The memory 402 can be used to store computer programs and / or modules. The processor 401 implements various functions of the computer device by running or executing the computer programs and / or modules stored in the memory 402 and by calling the data stored in the memory 402. The memory 402 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, application programs required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device 400 (such as audio data, video data, etc.). In addition, the memory may include high-speed random access memory, and may also include non-volatile memory, such as hard disk, RAM, plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, at least one disk storage device, flash memory device, or other volatile solid-state storage device.

[0151] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the thread scheduling device, electronic device 400 and its corresponding units described above can be referred to the description of the thread scheduling method in the above embodiments of this application, and will not be repeated here.

[0152] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.

[0153] Therefore, embodiments of this application provide a computer-readable storage medium storing multiple instructions that can be loaded by a processor to execute steps in the thread scheduling method described above, such as:

[0154] Obtain the downstream service interface of the target upstream service proxy;

[0155] Determine the first percentage of the number of requests per second of the downstream service interface relative to the number of requests per second of the target upstream service;

[0156] Determine the second proportion of the number of requests per second of the downstream service interface whose interface response time is greater than a preset response time threshold.

[0157] Determine the third percentage of the number of threads in the downstream service interface relative to the total number of threads in the target upstream service;

[0158] Based on the first proportion, the second proportion, and the third proportion corresponding to the downstream service interface, it is determined whether the downstream service interface is a preset target downstream service interface;

[0159] If the downstream service interface is a preset target downstream service interface, reduce the number of threads of the preset target downstream service interface.

[0160] For specific instructions, please refer to the description of the thread scheduling method in the above embodiments of this application, which will not be repeated here.

[0161] The computer-readable storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.

[0162] Since the instructions stored in the computer-readable storage medium can execute the steps of the thread scheduling method in the above embodiments of this application, the beneficial effects that the thread scheduling method in the above embodiments of this application can achieve can be realized, as detailed in the preceding description, and will not be repeated here.

[0163] Furthermore, the terms "first," "second," and "third," etc., used in this application are used to distinguish different objects, not to describe a specific order. Additionally, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or modules is not limited to the listed steps or modules, but some embodiments may also include steps or modules not listed, or some embodiments may include other steps or modules inherent to these processes, methods, products, or devices.

[0164] The thread scheduling method, apparatus, electronic device, and storage medium provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The description of the above embodiments is only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A thread scheduling method, characterized in that, include: Obtain the downstream service interface of the target upstream service proxy; Determine the first percentage of the number of requests per second of the downstream service interface relative to the number of requests per second of the target upstream service; Determine the second proportion of the number of requests per second of the downstream service interface whose interface response time is greater than a preset response time threshold. Determine the third percentage of the number of threads in the downstream service interface relative to the total number of threads in the target upstream service; Based on the first percentage, the second percentage, and the third percentage corresponding to the downstream service interface, determine whether the downstream service interface is a preset target downstream service interface, including: determining whether the first percentage is greater than a preset first threshold, whether the second percentage is greater than a preset second threshold, and whether the third percentage is greater than a preset third threshold; if the first percentage is greater than the preset first threshold, the second percentage is greater than the preset second threshold, and the third percentage is greater than the preset third threshold, then determine that the downstream service interface is the preset target downstream service interface; If the downstream service interface is a preset target downstream service interface, reduce the number of threads of the preset target downstream service interface.

2. The thread scheduling method as described in claim 1, characterized in that, The step of determining whether the first proportion is greater than a preset first threshold, whether the second proportion is greater than a preset second threshold, and whether the third proportion is greater than a preset third threshold includes: Determine whether, within a consecutive preset first time period, the first proportion of the downstream service interface is greater than the preset first threshold, the second proportion is greater than the preset second threshold, and the third proportion is greater than the preset third threshold.

3. The thread scheduling method as described in claim 2, characterized in that, The step of determining whether the downstream service interface is a preset target downstream service interface includes: If, within a consecutive preset first time period, the first proportion of the downstream service interface is greater than the preset first threshold, the second proportion is greater than the preset second threshold, and the third proportion is greater than the preset third threshold, then the downstream service interface is determined to be the preset target downstream service interface.

4. The thread scheduling method as described in claim 1, characterized in that, The step of reducing the number of threads in the preset target downstream service interface includes: Obtain the total number of threads in the target upstream service and the total number of downstream service interfaces proxied by the target upstream service; The target thread count is obtained by dividing the total number of threads in the target upstream service by the total number of threads. Adjust the preset number of threads for the target downstream service interface to the target number of threads.

5. The thread scheduling method as described in claim 4, characterized in that, After adjusting the preset number of threads for the target downstream service interface to the target number of threads, the method further includes: Detect whether the second percentage of the preset target downstream service interface is less than a preset fourth threshold within a consecutive preset second time period; If the second percentage of the preset target downstream service interface is less than the preset fourth threshold for a consecutive preset second time period, then the number of threads corresponding to the preset target downstream service interface will be adjusted back to the number of threads before the last adjustment.

6. The thread scheduling method as described in claim 5, characterized in that, After adjusting the number of threads corresponding to the preset target downstream service interface back to the number of threads before the last adjustment, the method further includes: If the second proportion of the preset target downstream service interface is not less than the preset fourth threshold in a continuous preset second time period, then it is detected whether the second proportion of the preset target downstream service interface is greater than the preset second threshold in a continuous preset third time period. If the second percentage of the preset target downstream service interface is greater than the preset second threshold for a consecutive preset third time period, then the number of threads of the preset target downstream service interface is adjusted to a preset percentage of the currently adjusted number of threads, and the process proceeds to the step of detecting whether the second percentage of the preset target downstream service interface is less than a preset fourth threshold for a consecutive preset second time period, wherein the preset percentage is greater than 0 and less than 1.

7. A thread scheduling device, characterized in that, Includes a unit for performing the thread scheduling method as described in any one of claims 1 to 6.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is run on a computer, it causes the computer to perform the thread scheduling method as described in any one of claims 1 to 6.

9. An electronic device comprising a processor and a memory, the memory storing a computer program, characterized in that, The processor executes the thread scheduling method as described in any one of claims 1 to 6 by invoking the computer program.

Citation Information

Patent Citations

  • Message traffic control method and device and related system

    CN106921587A

  • Asynchronous resource processing method and system based on enterprise service bus

    CN112433837A