Methods, devices, equipment, media, and products for determining task operation modes
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-14
- Publication Date
- 2026-08-14
AI Technical Summary
[0003]有鉴于此,本公开提供了一种任务运行模式的确定方法、装置、设备、介质及产品,以解决预配置任务运行模式与任务不匹配而导致任务执行效果不佳的问题
[0009]本公开提供的任务运行模式的确定方法、装置、设备、介质及产品,通过分析当前待调度的目标任务,确定目标任务的当前运行环境和历史任务运行数据。继而,以历史任务运行数据作为先验知识,预测目标任务在当前运行环境执行时的可用线程数;以当前运行环境作为实时知识,预测目标任务在当前运行环境执行时的任务运行时长。结合任务运行时长与可用线程数,确定目标任务最终的运行时长,以便根据运行时长进行运行模式的自适应匹配,从而能够在运行模式与目标任务不匹配时,对目标任务的运行模式进行准确切换,保证运行模式与目标任务的准确匹配,避免目标任务的执行出现性能瓶颈或响应迟缓,保证了目标任务的执行效果。
Smart Images

Figure CN122570084A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, specifically to methods, apparatus, equipment, media, and products for determining task operation modes. Background Technology
[0002] Currently, task execution modes typically employ synchronous or asynchronous modes. However, these modes are often pre-configured, and the pre-configured modes may not be suitable for the current task. This can lead to performance bottlenecks and slow response times, affecting the overall execution performance. Summary of the Invention
[0003] In view of this, the present disclosure provides a method, apparatus, device, medium and product for determining a task operation mode, so as to solve the problem of poor task execution effect caused by mismatch between the pre-configured task operation mode and the task.
[0004] In a first aspect, this disclosure provides a method for determining a task execution mode, including: obtaining a target task currently to be scheduled; analyzing the target task to determine its current execution environment and historical task execution data; determining the task runtime of the target task based on the environment attributes of the current execution environment; predicting the number of available threads for the target task according to the historical task execution data; determining the runtime of the target task based on the fusion result of the task runtime and the number of available threads; and matching the execution mode of the target task according to the runtime.
[0005] Secondly, this disclosure provides a device for determining a task execution mode, comprising: an acquisition module for acquiring a target task currently to be scheduled; a data analysis module for analyzing the target task and determining the current execution environment and historical task execution data of the target task; a duration determination module for determining the task execution duration of the target task based on the environmental attributes of the current execution environment; a thread prediction module for predicting the number of available threads for the target task according to historical task execution data; and an execution mode determination module for determining the execution duration of the target task based on the fusion result of the task execution duration and the number of available threads, and matching the execution mode of the target task according to the execution duration.
[0006] Thirdly, this disclosure provides a computer device, including: a memory and a processor, which are communicatively connected to each other. The memory stores computer instructions, and the processor executes the computer instructions to perform the method for determining the task operation mode described in the first aspect or any corresponding embodiment.
[0007] Fourthly, this disclosure provides a computer-readable storage medium storing computer instructions for causing a computer to execute the method for determining a task operation mode described in the first aspect or any corresponding embodiment.
[0008] Fifthly, this disclosure provides a computer program product, including computer instructions, which are used to cause a computer to perform a method for determining a task execution mode of the first aspect or any corresponding embodiment described above.
[0009] The method, apparatus, equipment, medium, and product disclosed herein for determining the task execution mode determine the current execution environment and historical task execution data of the target task by analyzing the target task to be scheduled. Then, using the historical task execution data as prior knowledge, the number of available threads for the target task in the current execution environment is predicted; using the current execution environment as real-time knowledge, the task runtime for the target task in the current execution environment is predicted. Combining the task runtime and the number of available threads, the final runtime of the target task is determined, enabling adaptive matching of the execution mode based on the runtime. This allows for accurate switching of the target task's execution mode when the execution mode does not match the target task, ensuring accurate matching between the execution mode and the target task, avoiding performance bottlenecks or slow response times, and guaranteeing the execution effect of the target task. Attached Figure Description
[0010] To more clearly illustrate the technical solutions in the specific embodiments or related technologies of this disclosure, the accompanying drawings used in the description of the specific embodiments or related technologies will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of this disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0011] Figure 1 This is a flowchart illustrating a method for determining a task operation mode according to an embodiment of this disclosure;
[0012] Figure 2 This is a flowchart illustrating a method for determining another task operation mode according to an embodiment of the present disclosure;
[0013] Figure 3 This is a flowchart illustrating another method for determining a task operation mode according to an embodiment of the present disclosure;
[0014] Figure 4 This is a system block diagram for determining the task operation mode according to an embodiment of the present disclosure;
[0015] Figure 5This is a structural block diagram of a task operation mode determination device according to an embodiment of the present disclosure;
[0016] Figure 6 This is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present disclosure. Detailed Implementation
[0017] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this disclosure, and not all embodiments. Based on the embodiments of this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure.
[0018] It is understood that before using the technical solutions disclosed in the various embodiments of this disclosure, users should be informed of the types, scope of use, and usage scenarios of the personal information involved in this disclosure in an appropriate manner in accordance with relevant laws and regulations, and user authorization should be obtained.
[0019] For example, upon receiving a user's active request, a prompt message is sent to the user to explicitly inform them that the requested operation will require the acquisition and use of the user's personal information. This allows the user to independently choose whether to provide personal information to the software or hardware, such as the electronic device, application, server, or storage medium performing the operations of this disclosed technical solution, based on the prompt message.
[0020] As an optional but non-limiting implementation, in response to a user's active request, sending a prompt message to the user can be done via a pop-up window, where the prompt message can be presented in text format. Furthermore, the pop-up window can also include a selection control allowing the user to choose "agree" or "disagree" to provide personal information to the electronic device.
[0021] It is understood that the above notification and user authorization process are merely illustrative and do not constitute a limitation on the implementation of this disclosure. Other methods that comply with relevant laws and regulations may also be applied to the implementation of this disclosure.
[0022] It is understood that the data involved in this technical solution (including but not limited to the data itself, the acquisition or use of the data) shall comply with the requirements of relevant laws, regulations and related provisions.
[0023] Task execution modes typically employ either synchronous or asynchronous modes. Synchronous execution is suitable for scenarios with short execution times and high sequential requirements, but it can easily lead to performance bottlenecks and slow response times when handling long-running tasks or processing multiple tasks simultaneously. While asynchronous execution allows for multiple asynchronous threads to be matched to the target task, these threads may simultaneously access and modify shared resources, such as global variables and shared data structures. For short-running tasks, the additional mutual exclusion mechanisms added for thread safety can also impact performance.
[0024] However, most task execution modes are pre-configured, and the pre-configured task execution modes may not be suitable for the execution of the current task. Therefore, how to achieve adaptive matching between tasks and task execution modes is an urgent problem to be solved.
[0025] Based on this, the technical solution disclosed herein combines the prior historical running data and real-time running status of the target task to predict the running time of the target task, thereby adaptively matching the running mode according to the running time, ensuring the execution effect of the target task.
[0026] According to an embodiment of this disclosure, a method for determining a task execution mode is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0027] This embodiment provides a method for determining a task execution mode, which can be used in computer devices such as computers and servers. Figure 1 This is a flowchart of a method for determining a task operation mode according to an embodiment of this disclosure, such as... Figure 1 As shown, the process includes the following steps:
[0028] Step S101: Obtain the target task to be scheduled.
[0029] The target task is the task that needs to be scheduled for execution. Specifically, each task is stored in a task queue, which has a corresponding scheduling order. The computer device can retrieve the target task from the task queue in the order of scheduling.
[0030] In a specific example, you use operating system calls or management tools to obtain the target task currently awaiting scheduling. For instance, on Linux, you can use the `ps` command or the `sched_get_next_task()` system call to obtain the target task; or you can use management tools such as `ps`, `top`, or `htop` to view the current thread status and obtain the target task based on the current thread status.
[0031] In another concrete example, threads or task schedulers in a programming language can also be used to obtain the target task currently awaiting scheduling. For instance, in Python, a task queue from an asynchronous programming library can be used to obtain the task to be scheduled; in Java, the target task in the current task queue can be obtained by viewing the task lifecycle or using a thread pool manager.
[0032] Of course, other methods can also be used to obtain the target task to be scheduled. Those skilled in the art can determine the appropriate method based on actual needs, and no specific limitations are made here.
[0033] Step S102: Analyze the target task and determine the current operating environment and historical task operation data of the target task.
[0034] The current runtime environment is used to characterize the execution environment of the target task; historical task runtime data refers to the runtime data generated by the target task within a historical period, specifically including online runtime data generated within a historical period and test data in the local environment.
[0035] Data generated during the execution of the target task is saved to the corresponding task database. When the target task is scheduled for execution, the historical task execution data corresponding to the target task is retrieved from the task database. At the same time, the execution environment of the target task is detected to determine the current running environment of the target task.
[0036] Step S103: Determine the task runtime of the target task based on the environment attributes of the current operating environment.
[0037] Environment attributes are used to characterize the features of the current operating environment, which may include the scenario in which the target task is located, the machine type, memory, CPU utilization, etc.; task runtime is the time required to execute the target task in the current operating environment.
[0038] By analyzing the environmental attributes of the current operating environment, the execution environment of the target task is analyzed, and the task runtime required for the target task to run in the current operating environment is predicted. Specifically, features are extracted from the current operating environment, and the running status of the target task is estimated based on the extracted features to determine the execution time of the target task.
[0039] Step S104: Predict the number of available threads for the target task based on historical task execution data.
[0040] The number of available threads is an estimate, based on historical task execution data, of the number of threads available to execute the target task in the current runtime environment. By analyzing historical task execution data, the thread resources used for the target task during historical execution can be determined, thereby allowing the estimation of the number of available threads for executing the target task currently.
[0041] Step S105: Based on the fusion result of task runtime and available thread count, determine the runtime of the target task, and match the running mode of the target task according to the runtime.
[0042] As described above, the task runtime is determined based on the current runtime environment, while the number of available threads is predicted based on historical task runtime data. By fusing the number of available threads with the task runtime, a relationship curve between the two can be fitted. This curve can then be used to assist in determining the runtime of the target task.
[0043] The execution mode refers to the method by which the target task is executed. This includes synchronous and asynchronous execution modes. In asynchronous mode, the execution of the target task does not block the current thread but runs independently in a background thread or thread pool. In this mode, the main thread can continue executing other tasks without waiting for the target task to complete. When the target task completes, it can return the result to the main thread or other interested parts through callback functions, event notifications, or other means for subsequent processing. Asynchronous execution mode allows multiple tasks to execute concurrently in the background, fully utilizing system resources and improving the overall throughput of the program.
[0044] In synchronous execution mode, a thread will block and wait while executing a target task until that task is completed before continuing with the next scheduled target task. For example, when a thread calls a function to read a file, it will wait until the file is read completely and cannot perform other operations in the meantime. If multiple synchronous target tasks need to be executed sequentially, the total execution time is the sum of the execution times of each target task.
[0045] In a specific example, the corresponding runtime threshold range is different for different running modes. If the runtime of the target task falls within the runtime threshold range, the corresponding running mode can be matched.
[0046] In another specific example, clustering algorithms (such as K-means, hierarchical clustering, etc.) can be used to cluster runtime data to find the runtime patterns most similar to the runtime.
[0047] In another specific example, pattern recognition (such as time series analysis, machine learning algorithms, etc.) can also be used to match the operating mode corresponding to the target task. Of course, other methods can also be used to match the operating mode of the target task, and no specific limitations are made here.
[0048] The method for determining the task execution mode provided in this embodiment analyzes the target task to be scheduled to determine the current execution environment and historical task execution data of the target task. Then, using the historical task execution data as prior knowledge, it predicts the number of available threads when the target task is executed in the current execution environment; using the current execution environment as real-time knowledge, it predicts the task runtime when the target task is executed in the current execution environment. Combining the task runtime and the number of available threads, it determines the final runtime of the target task, enabling adaptive matching of the execution mode based on the runtime. This allows for accurate switching of the target task's execution mode when the execution mode does not match the target task, ensuring accurate matching between the execution mode and the target task, avoiding performance bottlenecks or slow response times, and guaranteeing the execution effect of the target task.
[0049] This embodiment provides a method for determining a task execution mode, which can be used in computer devices such as computers and servers. Figure 2 This is a flowchart of a method for determining a task operation mode according to an embodiment of this disclosure, such as... Figure 2 As shown, the process includes the following steps:
[0050] Step S201: Obtain the target task currently to be scheduled. For details, please refer to the relevant descriptions of the corresponding steps in the above embodiments, which will not be repeated here.
[0051] Step S202: Analyze the target task to determine its current operating environment and historical task execution data. For details, please refer to the relevant descriptions of the steps in the above embodiments; they will not be repeated here.
[0052] Step S203: Determine the task runtime of the target task based on the environment attributes of the current operating environment.
[0053] Specifically, step S203 includes:
[0054] Step S2031: Based on the environmental attributes of the current operating environment, determine the static and dynamic operating characteristics of the target task in the current operating environment.
[0055] Static operating characteristics are the static features of the current operating environment, such as the scenario in which the target task is located (e.g., live streaming scenario, video-on-demand scenario, system startup, etc.) and the type of machine on which the target task is running (e.g., high-end machine, mid-range machine, low-end machine, etc.).
[0056] Dynamic runtime characteristics are the real-time characteristics of the current runtime environment, such as the memory usage of the computer device executing the target task (e.g., the frequency of garbage collection (GC) of virtual machine memory, GC settings, physical memory usage, etc.), the CPU utilization of the computer device executing the target task, the battery level when not charging, network status, frame rate, etc.
[0057] Specifically, by analyzing the environmental attributes of the current operating environment of the target task, it can be determined whether these environmental attributes will change. If the environmental attributes remain constant, the static operating characteristics of the target task can be extracted by combining these constant environmental attributes; if the environmental attributes change in real time, the dynamic operating characteristics of the target task can be determined by combining the changes in the environmental attributes.
[0058] Step S2032: The running status of the target task is scored according to the static running characteristics and dynamic running characteristics to obtain the running score of the target task.
[0059] For static and dynamic runtime characteristics, corresponding feature weights are assigned. The static runtime characteristics and their corresponding feature weights, as well as the dynamic runtime characteristics and their corresponding feature weights, are then weighted and summed to obtain the runtime score of the target task in its running state. Specifically:
[0060] runtimeScore = Score 动态运行特征 *q1+Score 静态运行特征 *q2;
[0061] Among them, Score 动态运行特征 The determination method is as follows:
[0062] Score 动态运行特征 =Score 启动 *z1+Score 帧率 *z2+...+Score 设备状态 *z n ;
[0063] Among them, Score 静态态运行特征 The determination method is as follows:
[0064] Score 静态态运行特征 =Score 场景 *w1+...+Score 机型 *w n ;
[0065] Where q1 is the feature weight of the dynamic operating feature; q2 is the feature weight of the static operating feature; the sum of q1 and q2 is 1; z1 to zn The sum of w1 to w is 1; n The sum is 1.
[0066] Step S2033: Match the task runtime of the target task according to the running score.
[0067] Different running scores correspond to different runtimes. By combining the running score with the range it falls within, the corresponding task runtime can be determined. For example, when the running score is above 85, the average runtime for executing a target task of type A is 100ms. Therefore, it can be assumed that the runtime for the next execution of a target task of type A will also be 100ms.
[0068] Step S204: Predict the number of available threads for the target task based on historical task execution data.
[0069] Specifically, step S204 includes:
[0070] Step S2041: Extract the historical available thread count, historical created thread count, and historical running thread count corresponding to the target task from the historical task execution data.
[0071] The historical available thread count is the number of available threads that could be provided for the execution of the target task during the historical execution process; the historical created thread count is the number of threads created for the execution of the target task; and the historical running thread count is the number of threads that ran the target task.
[0072] By analyzing the number of threads used to execute the target task in the historical task execution data, statistics are collected on the historical available threads, historical created threads, and historical running threads to obtain the corresponding historical available threads, historical created threads, and historical running threads.
[0073] Step S2042: Compare the historical available thread count with the historical created thread count to determine the first thread count difference between the historical available thread count and the historical created thread count.
[0074] By comparing the historical number of available threads with the historical number of created threads, the difference in thread count between the two is determined, i.e., the first thread count difference. Specifically, by comparing the historical number of available threads with the historical number of created threads, the growth or decline trend of the available thread count can be determined. If the historical number of created threads is steadily increasing, and the historical number of available threads is also increasing, this means that system resources (such as the number of CPU cores) are sufficient to support more concurrent threads. In this case, asynchronous execution mode can be considered to process the target task. If the total number of historically created threads is increasing, but the historical number of available threads is decreasing, it indicates that system resources are limited, and the thread pool may be close to full capacity. In this case, synchronous execution mode is more appropriate to process the target task.
[0075] Step S2043: Compare the historical number of available threads with the historical number of running threads to determine the second thread difference between the number of available threads and the number of running threads.
[0076] By comparing the historical number of available threads with the historical number of running threads, the difference in thread count between the two is determined, i.e., the second thread count difference. Specifically, by comparing the historical number of available threads with the historical number of running threads, the growth or decline trend of the historical number of available threads can be determined. If the historical number of running threads gradually increases, while the historical number of available threads remains unchanged or grows slowly, it indicates that the computer's operating system is constantly receiving tasks that need to be executed, but the thread pool cannot keep up with the growth rate of tasks. In this case, more threads are needed to process tasks, and a synchronous running mode (such as increasing the thread pool size) can be adopted. If the historical number of running threads and the historical number of available threads increase synchronously, and both are close to the maximum capacity of the thread pool, it indicates that the computer's operating system is under high load, and the thread pool is close to saturation. In this case, synchronous processing may cause tasks to block and wait for available threads, and an asynchronous running mode can be considered to reduce the waiting time of the target task.
[0077] Step S2044: Determine the number of available threads for the target task based on the difference between the first and second thread counts.
[0078] Based on the above analysis of the differences in the first and second thread counts, the growth or decrease trend of the number of available threads during the execution of the target task can be determined. If the historical running thread count continues to increase while the number of available threads decreases, it indicates that the thread pool is approaching its capacity limit. If the historical running thread count increases steadily with the support of the available thread count, but the available thread count remains unchanged, it indicates that the thread pool capacity is insufficient. If the historical created thread count continues to increase while the historical available thread count does not increase accordingly, it indicates that the thread pool capacity is not set large enough, or the system load is increasing. If both the historical created thread count and the historical available thread count are increasing, but the growth rate of the historical available thread count is lower than the growth rate of the historical created thread count, it indicates that the thread pool is rapidly being exhausted.
[0079] Specifically, the thread pool type in the current runtime environment is determined. If the operating system load is increasing, but the number of threads is not increasing or is increasing slowly, the number of available threads may decrease. Conversely, if the operating system load is decreasing, but the number of threads is not decreasing or is decreasing slowly, the number of available threads may increase. Based on historical task execution data, statistical models (such as linear regression and time series analysis) are established to predict the number of available threads when executing the target task in the future. Simultaneously, external factors that may affect thread pool performance are considered, such as system resource limitations (CPU, memory), network latency, and database response time. If the predicted number of available threads will decrease, consider increasing the thread pool capacity or using asynchronous processing to reduce thread contention. If the predicted number of available threads will increase, consider reducing the thread pool capacity to optimize resource utilization.
[0080] The types of thread pools include fixed-size thread pools (the number of threads does not increase automatically, so the number of threads needs to be predefined according to the system load and task characteristics), cached thread pools (the number of threads increases dynamically as needed, but there is a maximum thread limit), and scalable thread pools (the number of threads can be dynamically scaled, but there are usually minimum and maximum thread limits).
[0081] In a specific example, suppose the historical number of available threads gradually decreases from 100 to 20, the historical number of running threads gradually increases from 20 to 60, and the historical number of created threads gradually increases from 20 to 60. Based on this thread data, the number of available threads can be predicted. If the historical number of created threads and the historical number of running threads grow at the same rate, and the number of available threads continues to decrease, then at some point in the future, without increasing the thread pool capacity, the number of available threads may drop to 0, causing new target tasks to be unable to execute immediately.
[0082] Therefore, the number of available threads when executing the target task can be predicted based on the trend of thread count changes in historical task execution data, so as to adjust the size of the thread pool and ensure that there are enough available threads to handle the target task.
[0083] Step S205: Based on the fusion result of the task runtime and the number of available threads, determine the runtime of the target task, and match the running mode of the target task according to the runtime. For details, please refer to the relevant descriptions of the corresponding steps in the above embodiments, which will not be repeated here.
[0084] The task execution mode determination method provided in this embodiment combines the environmental attributes of the target task's current execution environment to extract the static and dynamic execution characteristics of the target task in the current environment. Then, it scores the execution based on these static and dynamic characteristics, thereby achieving real-time prediction of task runtime and improving the accuracy of execution mode prediction. Furthermore, it performs a difference analysis on the historical available thread count, historical created thread count, and historical running thread count corresponding to the target task. Based on the trend of thread count changes in historical task execution data, it predicts the available thread count when executing the target task to determine whether the available thread count meets the execution requirements of the target task. This improves the accuracy of available thread count prediction and facilitates accurate estimation and switching of the target task's execution mode based on the available thread count.
[0085] This embodiment provides a method for determining a task execution mode, which can be used in computer devices such as computers and servers. Figure 3 This is a flowchart of a method for determining a task operation mode according to an embodiment of this disclosure, such as... Figure 3 As shown, the process includes the following steps:
[0086] Step S301: Obtain the task to be executed, encapsulate the task to be executed, and generate the target task.
[0087] The task to be executed is the task that is about to be executed. The target task encapsulates all the execution operation information of the task to be executed. For the task to be executed, the task execution logic is determined based on its execution operation information. The task to be executed is then encapsulated according to the task execution logic, and task attributes (such as task identifier (ID), priority, start time, end time, etc.) are assigned to the encapsulated task to generate the corresponding target task. Figure 4 As shown, the task to be executed is transformed into a structured target task through encapsulation, thereby enabling the target task to be managed and executed efficiently while maintaining its independence, allowing for easy addition, removal, and monitoring of the target task.
[0088] Step S302: Store the target task in the task queue through the task interface.
[0089] The task interface serves as a general communication interface between the target task and the task queue; the task queue is a data structure for storing target tasks, used to store the task objects corresponding to the target tasks. This task queue can be a linked list, array, stack, queue, etc., and supports adding and removing target tasks. Figure 4As shown, the encapsulated target task object is added to the task queue through the task interface. If the task queue supports priority, the target task can be inserted into the correct position in the queue according to its priority; if the task queue is a first-in-first-out queue, the target task is directly added to the end of the task queue.
[0090] Step S303: Schedule the target task according to the task queue.
[0091] A pre-defined scheduling mechanism is established for the target tasks in the task queue, and this mechanism is used to schedule and process the target tasks in the task queue. This scheduling mechanism can be a timed task, event-triggered, or other mechanism; no specific limitation is made here.
[0092] like Figure 4 As shown, the task scheduler continuously monitors the task queue and retrieves target tasks from the queue for execution according to the scheduling mechanism. The task management module can match the appropriate running mode based on the runtime of the target task to determine whether to use a synchronous or asynchronous module to run the target task. During the execution of the target task, its status can be updated, such as being marked as "in execution," "completed," or "failed." When the target task is completed, the task scheduler removes the target task from the task queue and records the execution result or status, thereby achieving automated processing and management of target tasks.
[0093] Step S304: Obtain the target task currently to be scheduled. For details, please refer to the relevant descriptions of the corresponding steps in the above embodiments, which will not be repeated here.
[0094] Step S305: Analyze the target task to determine its current operating environment and historical task execution data. For details, please refer to the relevant descriptions of the steps in the above embodiments; they will not be repeated here.
[0095] Step S306: Determine the task runtime of the target task based on the environment attributes of the current operating environment. For details, please refer to the relevant descriptions of the corresponding steps in the above embodiments, which will not be repeated here.
[0096] Step S307: Predict the number of available threads for the target task based on historical task execution data. For details, please refer to the relevant descriptions of the corresponding steps in the above embodiments; they will not be repeated here.
[0097] Step S308: Based on the fusion result of task runtime and available thread count, determine the runtime of the target task, and match the running mode of the target task according to the runtime.
[0098] Specifically, step S308 includes:
[0099] Step S3081: Determine the correspondence between task runtime and available thread count based on a preset algorithm.
[0100] The preset algorithm is a pre-defined algorithm used to construct the relationship curve between the number of available threads and the task runtime, such as the moving average method, exponential smoothing method, spline interpolation method, etc.
[0101] Taking the moving average method as an example, the moving average method is based on the historical task execution data of the target task to average the results and smooth out fluctuations in execution time. For example, to calculate the moving average of the most recent 5 times, the execution time of the target task in the past 5 times is added together and then divided by 5. As time goes by, new data is continuously added to the calculation, and old data is successively removed, thus forming a continuous moving average. Specifically, the expression for the moving average method is as follows:
[0102]
[0103] Among them, M AN P represents an N-times moving average. i This represents the runtime of the target task in the i-th iteration.
[0104] If the previous target task runtime was above the moving average and the moving average was trending upwards, it's predicted that the next runtime will continue to increase; conversely, if the previous target task runtime was below the moving average and the moving average was trending downwards, the next runtime may be trending downwards. Therefore, the range of the next target task runtime can be estimated based on the slope of the moving average. Specifically, by fitting the moving average to a linear function, we can obtain the following expression:
[0105] MAPredictTime = k*x + b, x∈N
[0106] Where k is the slope of the fitted function, b is the intercept, and x is the number of times the target task is run.
[0107] Step 3082: Determine the runtime of the target task according to the corresponding relationship.
[0108] By combining prior historical task execution data and the current execution environment, the expected additional overhead of adding a new thread, given the current number of threads, is obtained. Combined with the prediction results of the moving average method, the final runtime of the target task is obtained. Then, an activation function (such as Sigmoid or ReLU) is applied to determine whether to use synchronous or asynchronous execution mode. The specific expression is as follows:
[0109] HybridPredictTime=MAPredictTime*Ratio1+threadnum*Ratio2;
[0110] PredictResult=Relu(HybridPredictTime);
[0111] Among them, Ratio1 is the weight of the predicted value obtained by the moving average method in the current running environment, and Ratio2 is the weight of the negative impact of the current number of threads in the current environment; PredictResult is the prediction result for the running mode; Ratio1 and Ratio2 are obtained based on the tree model in the current running environment.
[0112] In some alternative implementations, a weighted average-based exponential smoothing algorithm can also be used. Specifically, the exponential smoothing algorithm assigns different weights to the runtime of the target task over a historical period, giving higher weights to the most recent runtime, with the weights decaying exponentially over time. This is expressed as follows:
[0113] S t =a*y t +(1-α)*S t-1
[0114] Among them, S t S is the runtime of executing the target task at the current time point; t-1 The runtime of the target task at the previous time point; y t α is the runtime of the most recent execution of the target task; α is a smoothing constant, and adjusting the smoothing constant α increases the weight of recent data.
[0115] In some alternative implementations, spline interpolation can also be used to calculate the runtime. Specifically, spline interpolation approximates a given data point by constructing a piecewise polynomial function, such that within each segment interval, the polynomial function smoothly connects adjacent data points, thereby predicting the runtime of executing the target task.
[0116] It should be noted that the value of Ratio1 will change accordingly under different algorithms.
[0117] Step S3083: Determine whether the runtime is greater than the preset runtime.
[0118] The preset duration is the minimum allowed duration for task execution in asynchronous mode. The runtime is compared with the preset duration to determine their relationship. If the runtime is greater than the preset duration, step S3062 is executed; otherwise, step S3063 is executed.
[0119] Step S3084: If the runtime is longer than the preset duration, then the target task's running mode is determined to be asynchronous running mode.
[0120] If the runtime exceeds the preset duration, it indicates that the target task takes a long time to process. Using synchronous running mode can easily lead to performance bottlenecks and slow response. In this case, asynchronous running mode can be used to process the target task to improve the response speed of the target task in the current running environment.
[0121] Step S3085: If the running time is less than the preset time, then the running mode of the target task is determined to be synchronous running mode.
[0122] If the runtime is less than the preset duration, it means that the target task takes a short time to process. Using asynchronous running mode may result in simultaneous access to and modification of shared resources, which can easily lead to thread mutual exclusion and performance bottlenecks. In this case, synchronous running mode can be used to process the target task to avoid thread mutual exclusion and improve the response speed of the target task in the current running environment.
[0123] In some optional implementations, the above method further includes:
[0124] Step d1: Obtain the mode configuration information for the target task.
[0125] Step d2: Determine the running mode of the target task according to the mode configuration information.
[0126] The mode configuration information is pre-configured for the target task, including synchronous and asynchronous running modes. Specifically, target tasks with special requirements need to run in a specified fixed mode. This allows the target task to specify a fixed mode when calling an interface, such as a target task that always runs as a daemon thread. For target tasks in specific program execution scenarios, or for specific target tasks, corresponding synchronous or asynchronous running modes can be pre-configured. Therefore, technical personnel can pre-configure the appropriate mode configuration information for the target task based on its task attributes.
[0127] When a target task is scheduled, it is checked whether the target task has the corresponding mode configuration information. If the target task has the corresponding mode configuration information, the mode configuration information is parsed to execute the target task according to the running mode carried in the mode configuration information. If the target task does not have the corresponding mode configuration information, the corresponding running mode is matched for it based on the running data corresponding to the target task, as described in the above embodiments, and will not be repeated here.
[0128] In the above embodiments, by pre-configuring the mode configuration information of the target task, the mode configuration information is used to match the running mode of the target task, ensuring that the running mode of the target task can adapt to specific scenarios and improving the adaptability between the running mode and the target task.
[0129] The task execution mode determination method provided in this embodiment, upon acquiring a task to be executed, encapsulates it into a target task according to its task execution logic and stores it in a task queue. This facilitates task scheduling according to the task queue, ensuring that target tasks are scheduled sequentially and executed in order, thus preventing chaotic execution of target tasks and impacting system performance. A preset algorithm is used to fit the correspondence between task runtime and the number of available threads, enabling auxiliary decision-making on the target task's runtime based on this correspondence, ensuring that the determined runtime is suitable for the current operating environment. By comparing the runtime with a preset duration, an asynchronous or synchronous execution mode is matched for the target task, ensuring that the target task achieves better performance under the matched asynchronous or synchronous execution mode, thereby improving the target task's response speed and execution performance.
[0130] This embodiment also provides a task operation mode determination device, which is used to implement the above embodiments and preferred embodiments, and will not be repeated as already described. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0131] This embodiment provides a device for determining a task operation mode, such as... Figure 5 As shown, it includes:
[0132] The acquisition module 401 is used to acquire the target task currently to be scheduled.
[0133] The data analysis module 402 is used to analyze the target task and determine the current operating environment and historical task operation data of the target task.
[0134] The duration determination module 403 is used to determine the task runtime of the target task based on the environment attributes of the current running environment.
[0135] The thread prediction module 404 is used to predict the number of available threads for a target task based on historical task execution data.
[0136] The running mode determination module 405 is used to determine the runtime of the target task based on the fusion result of the task runtime and the number of available threads, and to match the running mode of the target task according to the runtime.
[0137] In some optional implementations, the duration determination module 403 includes:
[0138] The feature extraction unit is used to determine the static and dynamic operating characteristics of the target task in the current operating environment based on the environmental attributes of the current operating environment.
[0139] The scoring unit is used to score the running status of the target task according to static and dynamic running characteristics, and obtain the running score of the target task.
[0140] The duration matching unit is used to match the task runtime of the target task based on the runtime score.
[0141] In some alternative implementations, the thread prediction module 404 includes:
[0142] The thread extraction unit is used to extract the historical available thread count, historical created thread count, and historical running thread count corresponding to the target task from historical task execution data.
[0143] The first thread comparison unit is used to compare the historical number of available threads with the historical number of created threads to determine the first thread difference between the historical number of available threads and the historical number of created threads.
[0144] The second thread comparison unit is used to compare the historical number of available threads with the historical number of running threads to determine the second thread difference between the number of available threads and the number of running threads.
[0145] The available thread determination unit is used to determine the number of available threads for the target task based on the difference between the first thread count and the difference between the second thread count.
[0146] In some alternative implementations, the operating mode determination module 405 includes:
[0147] The correspondence determination unit is used to determine the correspondence between task runtime and the number of available threads based on a preset algorithm.
[0148] The runtime determination unit is used to determine the runtime of the target task according to the correspondence.
[0149] The judgment unit is used to determine whether the running time is greater than the preset time.
[0150] The first mode determination unit is used to determine that the target task's running mode is asynchronous if the runtime is longer than a preset duration.
[0151] The second mode determination unit is used to determine the target task's running mode as synchronous running mode if the running time is less than the preset time.
[0152] In some alternative embodiments, the above-described apparatus further includes:
[0153] The encapsulation module is used to obtain the task to be executed, encapsulate the task to be executed, and generate the target task.
[0154] The storage module is used to store target tasks into the task queue through the task interface.
[0155] The scheduling module is used to schedule target tasks according to the task queue.
[0156] In some alternative embodiments, the above-described apparatus further includes:
[0157] The configuration information acquisition module is used to obtain the mode configuration information of the target task.
[0158] The run mode matching module is used to determine the run mode of the target task according to the mode configuration information.
[0159] Further functional descriptions of the above modules and units are the same as those in the corresponding embodiments described above, and will not be repeated here.
[0160] In this embodiment, the device for determining the task operation mode is presented in the form of a functional unit. Here, a unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that execute one or more software or fixed programs, and / or other devices that can provide the above functions.
[0161] The task execution mode determination apparatus provided in this disclosure analyzes the target task to be scheduled to determine the current execution environment and historical task execution data of the target task. Then, using the historical task execution data as prior knowledge, it predicts the number of available threads when the target task is executed in the current execution environment; using the current execution environment as real-time knowledge, it predicts the task runtime when the target task is executed in the current execution environment. Combining the task runtime and the number of available threads, it determines the final runtime of the target task, enabling adaptive matching of the execution mode based on the runtime. This allows for accurate switching of the target task's execution mode when the execution mode does not match the target task, ensuring accurate matching between the execution mode and the target task, avoiding performance bottlenecks or slow response times in the target task's execution, and guaranteeing the execution effect of the target task.
[0162] This disclosure also provides a computer device having the above-described features. Figure 5 The device for determining the task operation mode shown.
[0163] Please see Figure 6 , Figure 6 This is a schematic diagram of the structure of a computer device provided in an optional embodiment of this disclosure, such as... Figure 6 As shown, the computer device includes one or more processors 10, memory 20, and interfaces for connecting the components, including high-speed interfaces and low-speed interfaces. The components communicate with each other via different buses and can be mounted on a common motherboard or otherwise installed as needed. The processors can process instructions executed within the computer device, including instructions stored in or on memory to display graphical information of a GUI on external input / output devices (such as display devices coupled to the interfaces). In some alternative implementations, multiple processors and / or multiple buses can be used with multiple memories and multiple memory modules, if desired. Similarly, multiple computer devices can be connected, each providing some of the necessary operations (e.g., as a server array, a group of blade servers, or a multiprocessor system). Figure 6 Take a processor 10 as an example.
[0164] Processor 10 may be a central processing unit, a network processor, or a combination thereof. Processor 10 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The programmable logic device may be a complex programmable logic device (CAMP), a field-programmable gate array (FPGA), a general-purpose array logic (GDA), or any combination thereof.
[0165] The memory 20 stores instructions executable by at least one processor 10 to cause the at least one processor 10 to perform the method shown in the above embodiments.
[0166] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store the operating system and application programs required for at least one function; and the data storage area may store data created based on the use of the computer device.
[0167] Furthermore, memory 20 may include high-speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some alternative embodiments, memory 20 may optionally include memory remotely located relative to processor 10, which can be connected to the computer device via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0168] The memory 20 may include volatile memory, such as random access memory; the memory may also include non-volatile memory, such as flash memory, hard disk or solid-state drive; the memory 20 may also include a combination of the above types of memory.
[0169] The computer device also includes a communication interface 30 for communicating with other devices or communication networks.
[0170] This disclosure also provides a computer-readable storage medium in which the methods described in this disclosure can be implemented in hardware or firmware, or implemented as recordable on a storage medium, or implemented as computer code originally stored on a remote storage medium or a non-transitory machine-readable storage medium and subsequently stored on a local storage medium after being downloaded over a network. Thus, the methods described herein can be processed by software stored on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. The storage medium may be a magnetic disk, optical disk, read-only memory, random access memory, flash memory, hard disk, or solid-state drive, etc.; further, the storage medium may also include combinations of the above types of memory. It is understood that computers, processors, microprocessor controllers, or programmable hardware include storage components capable of storing or receiving software or computer code that, when accessed and executed by the computer, processor, or hardware, implements the methods shown in the above embodiments.
[0171] A portion of this disclosure can be applied to computer program products, such as computer program instructions, which, when executed by a computer, can invoke or provide methods and / or technical solutions according to this disclosure through the operation of the computer. Those skilled in the art will understand that the forms in which computer program instructions exist in a computer-readable medium include, but are not limited to, source files, executable files, and installation package files. Accordingly, the ways in which computer program instructions are executed by a computer include, but are not limited to: the computer directly executing the instructions; the computer compiling the instructions and then executing the corresponding compiled program; the computer reading and executing the instructions; or the computer reading and installing the instructions and then executing the corresponding installed program. Here, the computer-readable medium can be any available computer-readable storage medium or communication medium accessible to a computer.
[0172] Although embodiments of the present disclosure have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the present disclosure, and such modifications and variations all fall within the scope defined by the appended claims.
Claims
1. A method for determining a task execution mode, characterized in that, The method includes: Get the target task currently awaiting scheduling; Analyze the target task to determine its current operating environment and historical task operation data; Based on the environmental attributes of the current operating environment, determine the task runtime of the target task; Predict the number of available threads for the target task based on the historical task execution data; Based on the fusion result of the task runtime and the number of available threads, the runtime of the target task is determined, and the running mode of the target task is matched according to the runtime.
2. The method according to claim 1, characterized in that, Determining the task runtime of the target task based on the environment attributes of the current operating environment includes: Based on the environmental attributes, determine the static and dynamic operating characteristics of the target task in the current operating environment; The running status of the target task is scored according to the static running characteristics and the dynamic running characteristics to obtain the running score of the target task; The task runtime of the target task is matched based on the running score.
3. The method according to claim 1, characterized in that, The step of predicting the number of available threads for the target task based on the historical task execution data includes: Extract the historical available thread count, historical created thread count, and historical running thread count corresponding to the target task from the historical task execution data; By comparing the historical available thread count with the historical created thread count, a first thread count difference between the historical available thread count and the historical created thread count is determined; By comparing the historical number of available threads with the historical number of running threads, a second thread difference between the number of available threads and the number of running threads is determined; Based on the first thread count difference and the second thread count difference, the number of available threads for the target task is determined.
4. The method according to any one of claims 1-3, characterized in that, Determining the runtime of the target task based on the fusion result of the task runtime and the number of available threads includes: The correspondence between the task runtime and the number of available threads is determined based on a preset algorithm; The runtime of the target task is determined according to the aforementioned correspondence.
5. The method according to claim 4, characterized in that, The step of matching the running mode of the target task according to the running duration includes: Determine whether the runtime is greater than a preset duration; If the runtime is longer than the preset runtime, then the target task is determined to run in an asynchronous mode. If the runtime is less than the preset runtime, then the target task is determined to be in synchronous running mode.
6. The method according to claim 1, characterized in that, Also includes: Obtain the mode configuration information of the target task; The operating mode of the target task is determined according to the mode configuration information.
7. The method according to claim 1, characterized in that, Before obtaining the currently scheduled target task, the method further includes: Obtain the task to be executed, encapsulate the task to be executed, and generate the target task; The target task is stored in the task queue through the task interface; The target task is scheduled according to the task queue.
8. A device for determining a task operation mode, characterized in that, The device includes: The acquisition module is used to acquire the target tasks currently awaiting scheduling; The data analysis module is used to analyze the target task and determine the current operating environment and historical task operation data of the target task. The duration determination module is used to determine the task runtime of the target task based on the environment attributes of the current operating environment; The thread prediction module is used to predict the number of available threads for the target task based on the historical task execution data. The running mode determination module is used to determine the running time of the target task based on the fusion result of the task running time and the number of available threads, and to match the running mode of the target task according to the running time.
9. A computer device, characterized in that, include: A memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the computer instructions to perform the method for determining the task running mode according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for causing the computer to execute the method for determining the task running mode according to any one of claims 1 to 7.