A task scheduling method, device and equipment of a server cluster
Patent Information
- Application Number
- CN202411979670.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2026-09-22
- Estimated Expiration
- 2044-12-31
AI Technical Summary
[0003]但是由于任务数据量日益庞大,单台服务器已经无法满足我们的需求,必须使用多台服务器,也就是通过服务器集群去解决性能问题
[0036]本发明的上述方案,通过获取服务器集群中任意一个目标服务器的当前任务;通过装饰器函数对所述当前任务所对应的目标函数进行加载处理,得到所述当前任务的任务标识;在目标数据库中查询所述任务标识,得到查询结果;获取所述目标函数的属性;根据所述查询结果以及所述目标函数的属性,产生任务指令;将所述任务指令发送至所述目标服务器,使得所述目标服务器根据所述任务指令执行所述当前任务或者获取下一个目标任务。可以解决服务器集群的任务调度问题。
Smart Images

Figure CN119883635B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer information technology, and in particular to a task scheduling method, apparatus and equipment for server clusters. Background Technology
[0002] There are a large number of scheduled tasks in the background server that fetch data. Currently, Apschedular (a lightweight task scheduling framework) is commonly used to schedule these scheduled tasks. As a mainstream scheduled task scheduler, Apschedular is widely used in single-machine environments to schedule various scheduled tasks.
[0003] However, due to the ever-increasing volume of task data, a single server can no longer meet our needs, and we must use multiple servers, i.e., a server cluster, to solve the performance problem. However, the Apschedular framework itself does not provide task scheduling functionality for server clusters; it currently only supports task scheduling on a single server. Therefore, it is not possible to use Apschedular for reasonable task scheduling in a clustered environment. Summary of the Invention
[0004] The technical problem to be solved by the present invention is to provide a task scheduling method, apparatus and device for server clusters, which can solve the task scheduling problem of server clusters.
[0005] To solve the above-mentioned technical problems, the technical solution of the present invention is as follows:
[0006] A task scheduling method for a server cluster includes:
[0007] Get the current tasks of any target server in the server cluster;
[0008] The target function corresponding to the current task is loaded using a decorator function to obtain the task identifier of the current task;
[0009] The task identifier is queried in the target database to obtain the query results;
[0010] Obtain the properties of the objective function;
[0011] Based on the query results and the properties of the target function, generate task instructions;
[0012] The task instruction is sent to the target server, so that the target server executes the current task or obtains the next target task according to the task instruction.
[0013] Optionally, the target function corresponding to the current task is loaded through a decorator function to obtain the task identifier of the current task, including:
[0014] The objective function is input into the decorator function as a parameter to obtain the function signature returned by the decorator function; the function signature is used as the task identifier of the current task.
[0015] Optionally, the task identifier can be queried in the target database to obtain query results, including:
[0016] The task identifier is compressed to obtain the target string;
[0017] Using the target string as the target key, query the target database for the target key. If the target key is found, output the first query result; otherwise, output the second query result.
[0018] Optionally, the attributes of the objective function are obtained, including:
[0019] Obtain the configuration information of the objective function;
[0020] Obtain either the first attribute or the second attribute of the target function from the configuration information, wherein the first attribute is an interval execution function and the second attribute is a repeated execution function of the target function.
[0021] Optionally, based on the query results and the properties of the target function, task instructions are generated, including:
[0022] When the target function is an interval execution function and the query result is the first query result, obtain the value corresponding to the target key stored in the target database;
[0023] When the difference between the value and the current timestamp is greater than or equal to the interval of the objective function, a first task instruction is generated; the first task instruction is used to instruct the target server to execute the current task.
[0024] When the difference between the value and the current timestamp is less than the interval of the objective function, a second task instruction is generated, which is used to instruct the target server to obtain the next objective task.
[0025] Optionally, based on the query results and the properties of the target function, task instructions are generated, including:
[0026] When the target function is an interval execution function and the query result is the second query result, a third task instruction is generated, and the current timestamp is stored in the target database as the value of the target key. The third task instruction is used to instruct the target server to execute the current task.
[0027] Optionally, based on the query results and the properties of the target function, task instructions are generated, including:
[0028] When the target function is a repeatedly executed function and the query result is the first query result, a fourth task instruction is generated, which is used to instruct the target server to obtain the next target task.
[0029] When the target function is a repeatedly executed function and the query result is the second query result, a fifth task instruction is generated. The fifth task instruction is used to instruct the target server to execute the current task and store the target key in the target database.
[0030] The present invention also provides a task scheduling device for a server cluster, comprising:
[0031] The acquisition module is used to acquire the current tasks of any target server in the server cluster;
[0032] The processing module is used to load the target function corresponding to the current task through a decorator function to obtain the task identifier of the current task; query the task identifier in the target database to obtain the query result; obtain the attributes of the target function; generate a task instruction based on the query result and the attributes of the target function; and send the task instruction to the target server so that the target server executes the current task or obtains the next target task according to the task instruction.
[0033] The present invention also provides a computing device, comprising: a processor and a memory storing a computer program, wherein the computer program, when executed by the processor, performs the method described above.
[0034] The present invention also provides a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the method described above.
[0035] The above-described solution of the present invention has at least the following beneficial effects:
[0036] The above-described solution of the present invention solves the task scheduling problem of server clusters by: obtaining the current task of any target server in the server cluster; loading the target function corresponding to the current task through a decorator function to obtain the task identifier of the current task; querying the task identifier in the target database to obtain the query result; obtaining the attributes of the target function; generating a task instruction based on the query result and the attributes of the target function; and sending the task instruction to the target server, so that the target server executes the current task or obtains the next target task according to the task instruction. Attached Figure Description
[0037] Figure 1This is a first flowchart of a task scheduling method for a server cluster according to an embodiment of the present invention;
[0038] Figure 2 This is a second flowchart of the task scheduling method for a server cluster according to an embodiment of the present invention;
[0039] Figure 3 This is a schematic diagram of the task scheduling device for a server cluster according to an embodiment of the present invention. Detailed Implementation
[0040] Exemplary embodiments of the invention will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the invention are shown in the drawings, it should be understood that the invention may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this invention will be thorough and complete, and will fully convey the scope of the invention to those skilled in the art.
[0041] like Figure 1 As shown, an embodiment of the present invention proposes a task scheduling method for a server cluster, comprising:
[0042] Step 11: Obtain the current task of any target server in the server cluster;
[0043] Step 12: Load the target function corresponding to the current task through the decorator function to obtain the task identifier of the current task;
[0044] Step 13: Query the task identifier in the target database to obtain the query results;
[0045] Step 14: Obtain the properties of the objective function;
[0046] Step 15: Generate task instructions based on the query results and the attributes of the target function;
[0047] Step 16: Send the task instruction to the target server, so that the target server executes the current task or obtains the next target task according to the task instruction.
[0048] In this embodiment, the target task is a data retrieval task from the target server on the target data platform. The target task typically corresponds to a target function, through which data is retrieved from the target data platform. The target task can be an operation to synchronize target data from the target data platform, which can be a different advertising data platform or the data platform of the target application. Specifically, the target task can be as follows:
[0049] Task 1: Synchronize the target data platform account balance data.
[0050] scheduler.add_job(
[0051] id='gdt_account_fund_main',func=
[0052] gdt_account_fund_main,trigger='interval',hours=1,replace_existing=True,jobstore='default' )
[0054] Task 2: Synchronize target data platform account data
[0055] scheduler.add_job(
[0056] id='gdt_advertiser_info_main',func=
[0057] gdt_advertiser_info_main,trigger='interval',hours=1,replace_existing=True,jobstor e='default' )
[0059] Task 3: Obtain daily statement details of the funds account.
[0060] scheduler.add_job(
[0061] id='gdt_account_daily_balance_main',func=
[0062] gdt_account_daily_balance_main,trigger='cron',hours=9,replace_existing=True,jo bstore='cron' )
[0064] Task 4: Update target data platform materials
[0065] scheduler.add_job(
[0066] id='gdt_adgroup_daily_report_main', func=
[0067] gdt_adgroup_daily_report_main,trigger='
[0068] interval',minutes=3,replace_existing=True,jobstore='default'
[0069] Of the four target tasks listed above, the task that the target server is about to execute is the current task. In this embodiment, hundreds of target tasks are deployed on the target server. These target tasks are scheduled by Apschedular (a lightweight task scheduling framework) deployed on each target server. Each Apschedular on the target server refers to the same task scheduling configuration to know which functions need to be executed at this moment, that is, to determine the current task of the target server.
[0070] After determining the current task of the target server, such as Figure 2 As shown, the target function corresponding to the current task is decorated using a decorator function to obtain the signature of the target function, which is then used as the task identifier for the current task. The task identifier is queried in the target database to determine if it is already stored, yielding a query result. Based on the query result and the attributes of the target function corresponding to the current task, it is determined whether the target server will execute the current task. In this embodiment, preferably, the target database is a Redis database, a high-performance (key-value) distributed in-memory database with a key-value pair data model. In this embodiment, when all servers in the server cluster execute a target task, they store the target task's task identifier as the key and the current timestamp as the value in the target database. When the target task finishes execution, the corresponding key-value pair stored in the database is deleted or retained based on the attributes of the target function corresponding to the target task. When a server wants to execute a current task, it can determine whether other servers in the cluster are currently executing the current task and the past execution status of the target function corresponding to the current task by querying the task identifier in the database. The target database can determine whether the target server should execute the current task based on the execution status of other servers, thus enabling task scheduling for the server cluster.
[0071] In this embodiment, the target database acts as a central task scheduling center, using function signatures as unique identifiers for task execution. By querying function signatures, the past and current execution status of tasks is determined, enabling task scheduling for target servers within the server cluster. This solves the problem of task scheduling using the Apschedular (timed task) framework in a server cluster. Because a unified Redis manages all task states, and because Redis itself provides atomic access, concurrency issues are avoided. This means that the number of cluster servers can be dynamically added or removed at any time without affecting the overall execution performance.
[0072] In an optional embodiment of the present invention, step 12 may include:
[0073] Step 121: Input the target function as a parameter of the decorator function to obtain the function signature returned by the decorator function; use the function signature as the task identifier of the current task.
[0074] In this embodiment, each target function in the Apschedular configuration has been pre-processed using decorator logic to dynamically add function content and load function signatures. The decorator is a higher-order function that accepts the target function as a parameter. In this embodiment, an inner function is defined inside the decorator function. This inner function can access the decorator function's parameters and the external environment (including the decorated function). The inner function extends the functionality of the decorated function. Finally, the decorator function returns the inner function, effectively replacing the original function with the extended one.
[0075] In this embodiment, all target functions configured in the Apschedular framework are passed to the decorator count_func_execute_seconds, and the step to obtain the function signature is task_name = func.__name__.
[0076] Since functions are objects and have attributes, where `__name__` is the function name, this function signature serves as a unique identifier for task execution. Because the Python interpreter naturally checks for duplicate function names, no additional business logic code is needed to guarantee the uniqueness of function execution.
[0077] The wrapped function, which is all the scheduled task functions, is replaced with the inner function and returned. In the end, the task functions called by the Apschedular framework all have all the functionality written in the decorator code.
[0078] In an optional embodiment of the present invention, step 13 may include:
[0079] Step 131: Compress the task identifier to obtain the target string;
[0080] Step 132: Using the target string as the target key, query the target database for the target key. If the target key is found, output the first query result; otherwise, output the second query result.
[0081] In this embodiment, the decorator logic connects to the target database server. Since the target database contains a large number of keys, it is necessary to compress the key length to save storage space. The task identifier is compressed, and the compressed result is used as the key to query the target database. The compression method includes:
[0082] 1. Data block splitting: The function signature is divided into multiple data blocks (usually 256 bytes or less), and each data block can be compressed independently;
[0083] 2. Compress each data block. Compress the data by finding repeating byte sequences, creating a sliding window (typically 32KB) to find a match for the current byte. For each byte, output the offset and length of the match, or output the literal value directly.
[0084] 3. Statistically analyze the compression results of each data block, generate a Huffman tree and Huffman codes, and replace each symbol in the compression results of each data block with its corresponding Huffman code.
[0085] 4. The final output compressed data is Huffman encoded compressed data.
[0086] In an optional embodiment of the present invention, step 14 may include:
[0087] Step 141: Obtain the configuration information of the objective function;
[0088] Step 142: Obtain the first attribute or the second attribute of the target function from the configuration information, wherein the first attribute is an interval execution function and the second attribute is that the target function is a repetitive execution function.
[0089] In this embodiment, the configuration information configures the target function to be either cron mode (expression task scheduling) or interval mode (periodic task scheduling). When the target function is in interval mode, it is determined that the target function is an interval execution function, that is, the event is triggered after a fixed time interval. When the target function is in cron mode, since the cron expression set in this embodiment is for the target function to be executed continuously, it is determined that the target function is a recurring execution function.
[0090] In an optional embodiment of the present invention, step 15 may include:
[0091] Step 151: When the target function is an interval execution function and the query result is the first query result, obtain the value corresponding to the target key stored in the target database;
[0092] Step 152: When the difference between the value and the current timestamp is greater than or equal to the interval of the objective function, a first task instruction is generated; the first task instruction is used to instruct the target server to execute the current task.
[0093] Step 153: When the difference between the value and the current timestamp is less than the interval of the objective function, a second task instruction is generated. The second task instruction is used to instruct the target server to obtain the next objective task.
[0094] In this embodiment, when it is determined that the target function is an interval-executed function and the target database stores the key corresponding to the target function, the value corresponding to the key is queried. The value is the start time corresponding to the last execution of the target function on the server in the cluster. Based on the difference between the value and the current timestamp, the interval time since the last execution of the target function is determined. When the interval time is greater than or equal to the interval time set by the target function, it indicates that the target server needs to execute the target function. At this time, the database server sends a first task instruction to the target server, and the target server executes the current task according to the first task instruction. When the value shows that the interval time since the last execution is less than the interval time set by the target function, it indicates that the target server does not need to execute this current task. At this time, the database server sends a second task instruction to the target server, and the target server does not execute this current task according to the second task instruction, obtains the next target task, and repeats the determination of whether to execute the next target task.
[0095] In an optional embodiment of the present invention, step 15 may further include:
[0096] Step 154: When the target function is an interval execution function and the query result is the second query result, a third task instruction is generated, and the current timestamp is stored in the target database as the value of the target key. The third task instruction is used to instruct the target server to execute the current task.
[0097] In this embodiment, when the target function is an interval execution function and the task identifier of the current task is not found in the target database, it means that no server in the cluster has executed the target function. At this time, a third task instruction is generated, the target server executes the current task, and stores the compressed task identifier of the current task as the key and the current timestamp as the value in the target database.
[0098] When compressing the task identifier here, the following method can be used:
[0099] Duplicate data referencing is achieved by finding the longest prefix matching the current sequence of characters to be compressed (task identifier) within the current window (usually a fixed-size buffer). Specifically, assuming the current character sequence to be processed is S, and the window size is W, the position and length of the longest prefix matching the beginning of S within the window are determined as follows: Let the current matching position be match_pos, and the matching length be match_len. Initially, match_pos is negative infinity, and match_len is 0. Starting from the current character position, the search proceeds backward within the window to find the portion matching the beginning of the current character sequence, thus finding the position and length of the longest match.
[0100] Furthermore, the difference between the original data and the matching part, as well as some control information (such as flag bits), are encoded.
[0101] Suppose we have a set of symbols {s1,s2,s3,...,sn}, and their frequencies are {f1,f2,f3,...,fn}. Step 1: First, we construct a series of nodes for each symbol and its frequency. Each node can be regarded as a binary tree with only one node.
[0102] Step 2: Select the two nodes with the lowest frequencies from these nodes, create a new parent node with the frequency of the parent node being the sum of the frequencies of the two child nodes, remove the two child nodes from the node set, and add the newly created parent node to the node set.
[0103] Repeat step 2 until only one node remains in the node set; this node is the root node of the tree.
[0104] For each symbol, starting from the root node, it is encoded according to its path in the tree: moving left is encoded as 0, moving right is encoded as 1, and so on, resulting in the code for each symbol. This combination of searching, matching, and encoding achieves efficient data compression.
[0105] In an optional embodiment of the present invention, step 15 may further include:
[0106] Step 155: When the target function is a repeatedly executed function and the query result is the first query result, a fourth task instruction is generated. The fourth task instruction is used to instruct the target server to obtain the next target task.
[0107] Step 156: When the target function is a repeatedly executed function and the query result is the second query result, a fifth task instruction is generated. The fifth task instruction is used to instruct the target server to execute the current task and store the target key in the target database.
[0108] In this embodiment, when the target function is a repeatedly executed function and its signature is found in the target database, it indicates that another server in the cluster is currently executing the target function. To improve the efficiency of data retrieval from the server cluster, the target server does not need to repeatedly execute the target function. Instead, it can obtain the next target task and determine whether to execute it based on the same judgment logic.
[0109] If the target function is a recurring function and its signature is not found in the target database, it indicates that no server in the server cluster is currently executing the target function. Since the target function is set to be recurring, it needs to be executed continuously. Therefore, the target server executes the current task, calculates the key based on the target function corresponding to the current task, and stores the current timestamp as the value in the target database. When the target server finishes executing the current task, it deletes the corresponding key-value pair stored in the target database and continues to retrieve the next target task.
[0110] The method described in this invention uses decorators to execute business logic, including operations such as extracting function signatures. By leveraging Redis's single-threaded and atomic access capabilities to store task function signatures, it prevents erroneous access and duplicate execution on other machines in the cluster. Without modifying the Apschedular code itself, it enables task scheduling in a cluster environment using Apschedular, saving significant computing resources. This improves the performance of data retrieval tasks and enhances the timeliness and accuracy of data retrieval from various platforms.
[0111] The implementation process of the above method is further illustrated below with a specific embodiment:
[0112] Example 1: The target data platform is an advertising data platform.
[0113] 1. Start the Apschedular scheduling service on each cluster server;
[0114] 2. Each Apschedular references the same task scheduling configuration to determine which functions need to be executed at any given moment. Below are some example function code configurations.
[0115] Task 1: Synchronize advertising data platform account balance data
[0116] scheduler.add_job(
[0117] id='gdt_account_fund_main',func=
[0118] gdt_account_fund_main,trigger='interval',hours=1,replace_existing=True,jobstore='default' )
[0120] Task 2: Synchronize advertising data platform account data
[0121] scheduler.add_job(
[0122] id='gdt_advertiser_info_main',func=
[0123] gdt_advertiser_info_main,trigger='interval',hours=1,replace_existing=True,jobstor e='default' )
[0125] Task 3: Obtain daily statement details of the funds account.
[0126] scheduler.add_job(
[0127] id='gdt_account_daily_balance_main',func=
[0128] gdt_account_daily_balance_main,trigger='cron',hours=9,replace_existing=True,jo bstore='cron' )
[0130] Task 4: Update advertising data platform materials
[0131] scheduler.add_job(
[0132] id='gdt_adgroup_daily_report_main', func=
[0133] gdt_adgroup_daily_report_main,trigger='
[0134] interval',minutes=3,replace_existing=True,jobstore='default'
[0135] The above code is part of the data retrieval code from an advertising data platform, where:
[0136] The `gdt_account_fund_main` function is used to retrieve account balance data from the advertising data platform.
[0137] The `gdt_advertiser_info_main` function is used to retrieve account report data from the advertising data platform.
[0138] The `gdt_account_daily_balance_main` function is used to retrieve financial transaction data for advertising data platform accounts.
[0139] The `gdt_adgroup_daily_report_main` function is used to retrieve advertising creative data from the advertising data platform.
[0140] These four functions were called using cron and interval modes respectively. There are about four hundred similar function configurations. On average, it takes 10-20 minutes for a single function to execute. In other words, in a single-machine scenario, Apschedular cannot meet our requirements for function scheduling and execution efficiency.
[0141] 3. Each function to be executed in the configuration has been pre-loaded with its own content and its signature using decorator logic. Below is a partial code example:
[0142] Decoration configuration:
[0143] @count_func_execute_seconds
[0144] def gdt_account_daily_balance_main(record_date:str=None):
[0145] ""
[0146] Get daily statement details of your funds account (new, including daily closing balance data).
[0147] :param record_date:
[0148] :return:
[0149] ""
[0150] Decorator logic:
[0151]
[0152] In the code example, all the task functions configured in the Apschedular framework are passed to the decorator count_func_execute_seconds, and the step to get the function signature is task_name = func.__name__;
[0153] Since functions are objects and have attributes, where `__name__` is the function name, this function signature is used as a unique identifier for task execution. The advantage is that the Python interpreter naturally checks for functions with the same name, so there's no need to add extra business logic code to ensure the uniqueness of function execution.
[0154] The wrapped function, which is all our scheduled task functions, is replaced with the inner function and returned. In the end, the task functions called by the Apschedular framework all have all the functionality written in the decorator code.
[0155] 4. In the decorator logic, connect to the Redis server and calculate the key from the function signature for querying. Since a large number of keys reside in Redis, it is essential to compress the key length to save storage space.
[0156] 5. Check the Redis server to see if the Key from step 4 exists. Then, determine whether to continue execution based on the last execution time stored in the value. If the Key is not found at this time, write the Key into Redis and execute the process, writing the value back to the current time. At this point, the process ends.
[0157] like Figure 3 As shown, embodiments of the present invention also provide a task scheduling device 30 for a server cluster, comprising:
[0158] The acquisition module 31 is used to acquire the current task of any target server in the server cluster;
[0159] The processing module 32 is used to load the target function corresponding to the current task through a decorator function to obtain the task identifier of the current task; query the task identifier in the target database to obtain the query result; obtain the attributes of the target function; generate a task instruction based on the query result and the attributes of the target function; and send the task instruction to the target server so that the target server executes the current task or obtains the next target task according to the task instruction.
[0160] Optionally, the target function corresponding to the current task is loaded through a decorator function to obtain the task identifier of the current task, including:
[0161] The objective function is input into the decorator function as a parameter to obtain the function signature returned by the decorator function; the function signature is used as the task identifier of the current task.
[0162] Optionally, the task identifier can be queried in the target database to obtain query results, including:
[0163] The task identifier is compressed to obtain the target string;
[0164] Using the target string as the target key, query the target database for the target key. If the target key is found, output the first query result; otherwise, output the second query result.
[0165] Optionally, the attributes of the objective function are obtained, including:
[0166] Obtain the configuration information of the objective function;
[0167] Obtain either the first attribute or the second attribute of the target function from the configuration information, wherein the first attribute is an interval execution function and the second attribute is a repeated execution function of the target function.
[0168] Optionally, based on the query results and the properties of the target function, task instructions are generated, including:
[0169] When the target function is an interval execution function and the query result is the first query result, obtain the value corresponding to the target key stored in the target database;
[0170] When the difference between the value and the current timestamp is greater than or equal to the interval of the objective function, a first task instruction is generated; the first task instruction is used to instruct the target server to execute the current task.
[0171] When the difference between the value and the current timestamp is less than the interval of the objective function, a second task instruction is generated, which is used to instruct the target server to obtain the next objective task.
[0172] Optionally, based on the query results and the properties of the target function, task instructions are generated, including:
[0173] When the target function is an interval execution function and the query result is the second query result, a third task instruction is generated, and the current timestamp is stored in the target database as the value of the target key. The third task instruction is used to instruct the target server to execute the current task.
[0174] Optionally, based on the query results and the properties of the target function, task instructions are generated, including:
[0175] When the target function is a repeatedly executed function and the query result is the first query result, a fourth task instruction is generated, which is used to instruct the target server to obtain the next target task.
[0176] When the target function is a repeatedly executed function and the query result is the second query result, a fifth task instruction is generated. The fifth task instruction is used to instruct the target server to execute the current task and store the target key in the target database.
[0177] It should be noted that this device is the same as the method described above. All implementations in the above method embodiments are applicable to the embodiments of this device and can achieve the same technical effect.
[0178] Embodiments of the present invention also provide a computing device, including: a processor and a memory storing a computer program, wherein the computer program, when executed by the processor, performs the method as described above. All implementations in the above method embodiments are applicable to this embodiment and can achieve the same technical effects.
[0179] Embodiments of the present invention also provide a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the method as described above. All implementations in the above method embodiments are applicable to this embodiment and can achieve the same technical effects.
[0180] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0181] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0182] In the embodiments provided by this invention, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0183] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0184] In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0185] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, essentially, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, ROM, RAM, magnetic disks, or optical disks.
[0186] Furthermore, it should be noted that in the apparatus and method of the present invention, it is obvious that the components or steps can be decomposed and / or recombined. These decompositions and / or recombinations should be considered equivalent solutions of the present invention. Moreover, the steps performing the above-described series of processes can naturally be executed in the order described, but are not necessarily required to be executed in chronological order; some steps can be executed in parallel or independently of each other. Those skilled in the art will understand that all or any step or component of the method and apparatus of the present invention can be implemented in any computing device (including processors, storage media, etc.) or network of computing devices, in hardware, firmware, software, or a combination thereof. This is something that those skilled in the art can achieve by using their basic programming skills after reading the description of the present invention.
[0187] Therefore, the object of the present invention can also be achieved by running a program or a set of programs on any computing device. The computing device can be a known general-purpose device. Therefore, the object of the present invention can also be achieved simply by providing a program product containing program code implementing the method or apparatus. That is, such a program product also constitutes the present invention, and the storage medium storing such a program product also constitutes the present invention. Obviously, the storage medium can be any known storage medium or any storage medium developed in the future. It should also be noted that in the apparatus and method of the present invention, it is obvious that the components or steps can be decomposed and / or recombined. These decompositions and / or recombinations should be considered equivalent to the present invention. Furthermore, the steps performing the above series of processes can naturally be performed in the order described, but are not necessarily required to be performed in chronological order. Some steps can be performed in parallel or independently of each other.
[0188] The above description represents the preferred embodiments of the present invention. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principles of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A task scheduling method for a server cluster, characterized in that, include: Get the current tasks of any target server in the server cluster; The target function corresponding to the current task is loaded using a decorator function to obtain the task identifier of the current task; The task identifier is queried in the target database to obtain the query results; Obtain the properties of the objective function; Based on the query results and the properties of the target function, generate task instructions; The task instruction is sent to the target server, so that the target server executes the current task or obtains the next target task according to the task instruction; Specifically, querying the task identifier in the target database yields query results, including: The task identifier is compressed to obtain the target string; Using the target string as the target key, query the target database for the target key. If the target key is found, output the first query result; otherwise, output the second query result. The acquisition of the attributes of the objective function includes: Obtain the configuration information of the objective function; Obtain either a first attribute or a second attribute of the target function from the configuration information, wherein the first attribute indicates that the function is executed at intervals, and the second attribute indicates that the target function is executed repeatedly. The process of generating task instructions based on the query results and the properties of the target function includes: When the target function is an interval execution function and the query result is the first query result, obtain the value corresponding to the target key stored in the target database; When the difference between the value and the current timestamp is greater than or equal to the interval of the objective function, a first task instruction is generated; the first task instruction is used to instruct the target server to execute the current task. When the difference between the value and the current timestamp is less than the interval of the objective function, a second task instruction is generated, which is used to instruct the target server to obtain the next objective task.
2. The task scheduling method for a server cluster according to claim 1, characterized in that, The target function corresponding to the current task is loaded using a decorator function to obtain the task identifier of the current task, including: The objective function is input into the decorator function as a parameter to obtain the function signature returned by the decorator function; the function signature is used as the task identifier of the current task.
3. The task scheduling method for a server cluster according to claim 1, characterized in that, Based on the query results and the properties of the target function, task instructions are generated, including: When the target function is an interval execution function and the query result is the second query result, a third task instruction is generated, and the current timestamp is stored in the target database as the value of the target key. The third task instruction is used to instruct the target server to execute the current task.
4. The task scheduling method for a server cluster according to claim 1, characterized in that, Based on the query results and the properties of the target function, task instructions are generated, including: When the target function is a repeatedly executed function and the query result is the first query result, a fourth task instruction is generated, which is used to instruct the target server to obtain the next target task. When the target function is a repeatedly executed function and the query result is the second query result, a fifth task instruction is generated. The fifth task instruction is used to instruct the target server to execute the current task and store the target key in the target database.
5. A task scheduling device for a server cluster, characterized in that, include: The acquisition module is used to acquire the current tasks of any target server in the server cluster; The processing module is used to load the target function corresponding to the current task through a decorator function to obtain the task identifier of the current task; query the task identifier in the target database to obtain the query result; and obtain the attributes of the target function. Based on the query results and the properties of the target function, a task instruction is generated; the task instruction is sent to the target server, so that the target server executes the current task or obtains the next target task according to the task instruction; Specifically, querying the task identifier in the target database yields query results, including: The task identifier is compressed to obtain the target string; Using the target string as the target key, query the target database for the target key. If the target key is found, output the first query result; otherwise, output the second query result. The acquisition of the attributes of the objective function includes: Obtain the configuration information of the objective function; Obtain either a first attribute or a second attribute of the target function from the configuration information, wherein the first attribute indicates that the function is executed at intervals, and the second attribute indicates that the target function is executed repeatedly. The process of generating task instructions based on the query results and the properties of the target function includes: When the target function is an interval execution function and the query result is the first query result, obtain the value corresponding to the target key stored in the target database; When the difference between the value and the current timestamp is greater than or equal to the interval of the objective function, a first task instruction is generated; the first task instruction is used to instruct the target server to execute the current task. When the difference between the value and the current timestamp is less than the interval of the objective function, a second task instruction is generated, which is used to instruct the target server to obtain the next objective task.
6. A computing device, characterized in that, include: A processor, a memory storing a computer program, wherein the computer program, when executed by the processor, performs the method as described in any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that, A storage instruction that, when executed on a computer, causes the computer to perform the method as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Distributed timed task processing system, method and related device
CN113448699A
User big data multi-engine pressure measurement method
CN117609101A