CN115480897A - Task processing method, device, equipment, storage medium and program product - Google Patents

Task processing method, device, equipment, storage medium and program product Download PDF

Info

Publication number
CN115480897A
CN115480897A CN202211147627.0A CN202211147627A CN115480897A CN 115480897 A CN115480897 A CN 115480897A CN 202211147627 A CN202211147627 A CN 202211147627A CN 115480897 A CN115480897 A CN 115480897A
Authority
CN
China
Prior art keywords
task
target
attribute
executed
thread
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211147627.0A
Other languages
Chinese (zh)
Inventor
冯波
殷源
柏杨
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Construction Bank Corp
Original Assignee
China Construction Bank Corp
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Construction Bank Corp filed Critical China Construction Bank Corp
Priority to CN202211147627.0A priority Critical patent/CN115480897A/en
Publication of CN115480897A publication Critical patent/CN115480897A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/4881Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues

Abstract

The invention relates to the technical field of data processing, in particular to a task processing method, a device, equipment, a storage medium and a program product, wherein the method comprises the following steps: receiving a task to be executed submitted to a target thread pool; acquiring attribute information of at least one target attribute corresponding to the task to be executed, wherein the target attribute is a self-defined task attribute; determining a target thread for executing the task to be executed from the target thread pool based on the attribute information of the at least one target attribute; and distributing the task to be executed to the target thread so that the target thread executes the task to be executed. According to the method, at least one target attribute is defined by user, the processing thread is allocated to the task to be executed according to the attribute information of the at least one target attribute corresponding to the task to be executed, the sequential execution of the multi-thread task can be realized, and the requirement of sequential operation of the multi-thread task is met.

Description

Task processing method, device, equipment, storage medium and program product
Technical Field
The present invention relates to the field of data processing technologies, and in particular, to a method, an apparatus, a device, a storage medium, and a program product for processing a task.
Background
With the rapid development of computer application technologies, most computer devices adopt a thread pool to perform task processing. The thread pool is a pooling technology, can fully exert the performance of a multi-core Central Processing Unit (CPU), and fully utilizes computer equipment resources by means of multi-thread parallel Processing in the thread pool to improve task Processing efficiency, thread manageability and the like. The method is often used in service scenes where quick response to user requests or quick processing of batch tasks and the like are needed.
Currently, for the execution of a single-threaded task, the execution order can be guaranteed to be in accordance with the writing order of the task. However, when a plurality of tasks are executed by multithreading, since the CPU can execute only one task at each time and the execution time allocated to each thread by the operating system may not be uniform, it is not possible to ensure that the order of finally executing the tasks is uniform with the order of writing the tasks.
For example, assuming a thread pool of 4 threads is created, the operating system constantly randomly assigns tasks to the 4 threads. When a plurality of tasks have a certain execution sequence, because the operating system may randomly allocate the plurality of tasks to 4 threads in the thread pool, and the execution time allocated to each thread by the operating system may be inconsistent, the execution sequence of the plurality of tasks may not be guaranteed when the tasks are finally executed, and thus a case may occur in which a task written later (to be executed later) is executed before a task written earlier (to be executed earlier), which may cause a task execution failure or a different operation result, and may not meet the requirement of sequential operation of the multi-threaded tasks.
Disclosure of Invention
In view of the foregoing problems in the prior art, it is an object of the present invention to provide a task processing method, device, apparatus, storage medium, and program product, which can implement ordered execution of multi-threaded tasks.
In order to solve the above problem, the present invention provides a task processing method, including:
receiving a task to be executed submitted to a target thread pool;
acquiring attribute information of at least one target attribute corresponding to the task to be executed, wherein the target attribute is a self-defined task attribute;
determining a target thread for executing the task to be executed from the target thread pool based on the attribute information of the at least one target attribute;
distributing the task to be executed to the target thread so that the target thread executes the task to be executed.
Further, the method further comprises:
determining a current task configuration strategy, wherein the task configuration strategy is a self-defined task configuration strategy;
and analyzing the task configuration strategy, and determining at least one task attribute corresponding to the task configuration strategy as a target attribute.
Further, the method further comprises:
respectively judging whether the attribute information of each target attribute in the at least one target attribute meets the corresponding preset attribute condition;
and when the attribute information of all the target attributes in the at least one target attribute meets the corresponding preset attribute condition, executing a step of determining a target thread for executing the task to be executed from the target thread pool based on the attribute information of the at least one target attribute.
Further, the method further comprises:
when the attribute information of any one of the at least one target attribute does not meet the corresponding preset attribute condition, allocating a thread from the target thread pool as a target thread by using a preset thread allocation strategy;
and distributing the task to be executed to the target thread so that the target thread executes the task to be executed.
Further, the determining, from the target thread pool, a target thread for executing the task to be executed based on the attribute information of the at least one target attribute includes:
performing hash operation on the attribute information of the at least one target attribute to obtain a corresponding hash value;
determining the number of threads in the target thread pool;
performing modulus operation on the hash value by taking the thread number as a modulus to obtain a modulus value;
and determining a thread corresponding to the modulus value from the target thread pool as a target thread for executing the task to be executed.
Further, the target attribute includes a device identifier, a device type, a website identifier, a website type, a task identifier, or a task type.
Another aspect of the present invention provides a task processing apparatus, including:
the task receiving module is used for receiving the tasks to be executed submitted to the target thread pool;
the attribute acquisition module is used for acquiring attribute information of at least one target attribute corresponding to the task to be executed, wherein the target attribute is a self-defined task attribute;
a thread determining module, configured to determine, based on the attribute information of the at least one target attribute, a target thread for executing the task to be executed from the target thread pool;
and the task distribution module is used for distributing the task to be executed to the target thread so as to enable the target thread to execute the task to be executed.
Another aspect of the present invention provides an electronic device, including a processor and a memory, where at least one instruction or at least one program is stored in the memory, and the at least one instruction or the at least one program is loaded by the processor and executed to implement the task processing method as described above.
Another aspect of the present invention provides a computer-readable storage medium, in which at least one instruction or at least one program is stored, and the at least one instruction or the at least one program is loaded and executed by a processor to implement the task processing method as described above.
Another aspect of the invention provides a computer program product comprising computer programs/instructions which, when executed by a processor, implement the steps of the task processing method as described above.
Due to the technical scheme, the invention has the following beneficial effects:
according to the task processing method provided by the embodiment of the invention, at least one target attribute is defined by user, and the target thread for executing the task to be executed is determined according to the attribute information of the at least one target attribute corresponding to the task to be executed, so that the purpose that the task with the same attribute ensures the execution of the same thread is achieved, the sequential execution of the multi-thread tasks with the same attribute in the thread pool can be realized, the requirement of sequential operation of the multi-thread tasks is met, and the normal execution of the tasks is ensured. And the target attribute can be adjusted in real time according to actual service requirements so as to better adapt to the actual requirements of users.
Drawings
In order to more clearly illustrate the technical solution of the present invention, the drawings used in the embodiment or the description of the prior art will be briefly described below. It is obvious that the drawings in the following description are only some embodiments of the invention, and that for a person skilled in the art, other drawings can be derived from them without inventive effort.
FIG. 1 is a schematic diagram of an implementation environment provided by an embodiment of the invention;
FIG. 2 is a flow diagram of a method for task processing provided by one embodiment of the invention;
FIG. 3 is a flowchart of a task processing method provided by another embodiment of the invention;
FIG. 4 is a thread allocation diagram provided by one embodiment of the invention;
FIG. 5 is a schematic structural diagram of a task processing device according to an embodiment of the present invention;
fig. 6 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
In order to make the technical solutions of the present invention better understood, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be obtained by a person skilled in the art without any inventive step based on the embodiments of the present invention, are within the scope of the present invention.
It should be noted that the terms "first," "second," and the like in the description and claims of the present invention and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the invention described herein are capable of operation in other sequences than those illustrated or described herein. Moreover, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, apparatus, article, or device that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or device.
In order to make the objects, technical solutions and advantages disclosed in the embodiments of the present invention more clearly apparent, the embodiments of the present invention are described in further detail below with reference to the accompanying drawings and the embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the embodiments of the invention and are not intended to limit the embodiments of the invention. In the technical scheme of the embodiment of the invention, the data acquisition, storage, use, processing and the like all conform to relevant regulations of national laws and regulations.
First, the embodiments of the present invention explain the following concepts:
hash (Hash) operation: refers to the conversion of an input of arbitrary length (also called pre-map) into an output of fixed length by a hashing algorithm, where the output is a hash value.
A thread pool: is a thread usage pattern. Too many threads can bring scheduling overhead, which in turn affects cache locality and overall performance. While the thread pool maintains multiple threads waiting for the supervisory administrator to assign concurrently executable tasks. This avoids the cost of creating and destroying threads while processing short-time tasks. The thread pool not only can ensure the full utilization of the kernel, but also can prevent over-scheduling. The number of available threads in the thread pool depends on the number of available concurrent processors, processor cores, memory, network sockets, and the like. For example, the number of threads is typically equal to the number of processors plus 2, and an excessive number of threads may result in additional thread switching overhead.
Modulus operation: the modulus operation is characterized in that: the modulo value must be within the range of the modulo. The element routing algorithm can be made not to exceed the boundary and be placed regularly by referring to this property. The modulo operation process may first determine a module (range), and then modulo the element to make the element regularly fall into the container in the range of the module, such as HashMap, database sub-table, distributed node routing algorithm, etc. For example, in 5mod 3=2, modulo is 3,2 is a modulo value. Wherein "mode" refers to the counting range of a metering system; if the clock is used, and 12 integral points are the calculation range, the module is 12; the computer is also a metrology machine, modulo 32 bits or 64 bits.
Referring to the specification and fig. 1, a schematic diagram of an implementation environment of a task processing method according to an embodiment of the invention is shown. It should be noted that fig. 1 is only an example of an implementation environment in which the embodiment of the present invention may be applied to help those skilled in the art understand the technical content of the present invention, and does not mean that the embodiment of the present invention may not be applied to other devices, systems, environments or scenarios. As shown in FIG. 1, the implementation environment may include at least a task processing platform 110 and at least one application party 120. The task processing platform 110 and each application party 120 may be directly or indirectly connected through a wired or wireless communication manner, which is not limited in this embodiment of the present invention.
The task processing platform 110 and the at least one application party 120 may include a smart phone, a tablet computer, a notebook computer, a desktop computer, a digital assistant, a smart speaker, a smart wearable device, a vehicle-mounted terminal, a server, and other types of physical devices, and may also include software running in the physical devices, such as an application program, but not limited thereto. The operating systems running on the task processing platform 110 and the at least one application side 120 may include, but are not limited to, an android system, an iOS system, a linux system, a windows system, and the like.
In this embodiment of the present invention, the at least one application party 120 may send a task to be executed to the task processing platform 110 through an interface and submit the task to the target thread pool, and the task processing platform 110 may allocate a target thread to the task to be executed by using the task processing method provided in this embodiment of the present invention, so that the target thread executes the task to be executed, thereby ensuring the ordered execution of the task with specific requirements.
In practical applications, the application party 120 may be each website of a financial institution such as a bank, the task processing platform 110 may be a corresponding website management platform, and the task to be processed may be a task of data processing, data cleaning, data analysis, and the like of each website.
In practical applications, the application party 120 may also be an internet of things device, the task processing platform 110 may be an internet of things device management platform, and the to-be-processed task may be a task such as device activation, device check-in, pre-check-in, and the like of each internet of things device.
It should be noted that fig. 1 is only an example. Those skilled in the art will appreciate that although only 2 application parties 120 are shown in fig. 1, the embodiment of the present invention is not limited thereto, and there may be any number of application parties 120 according to actual needs.
Referring to the specification, fig. 2 illustrates a flow of a task processing method according to an embodiment of the present invention, which may be applied to the task processing platform in fig. 1, and specifically as shown in fig. 2, the method may include the following steps:
s210: and receiving the task to be executed submitted to the target thread pool.
In the embodiment of the present invention, the task processing platform may create a target thread pool in advance, and determine the number of threads in the target thread pool. The method for creating the thread pool may refer to the prior art, which is not described herein again in the embodiments of the present invention, and the number of threads of the created target thread pool may be set according to actual needs, which is also not limited in the embodiments of the present invention.
In the embodiment of the present invention, each application side may submit a task to be executed to the target thread pool through an interface, and the task processing platform may receive the task to be executed and allocate a target thread for executing the task to be executed.
S220: and acquiring attribute information of at least one target attribute corresponding to the task to be executed, wherein the target attribute is a self-defined task attribute.
In the embodiment of the invention, a user can pre-configure one or more task attributes as target attributes according to actual needs, and can allocate tasks with the attribute information of the same target attributes to the same thread for execution by taking the attribute information of the target attributes as the standard for allocating the thread, thereby ensuring the ordered execution of the tasks with a certain operation sequence.
Specifically, the target attribute may include, but is not limited to, a device identifier, a device type, a website identifier, a website type, a task identifier, a task type, or other task attributes.
In a possible embodiment, before performing step S220, the method may further include:
determining a current task configuration strategy, wherein the task configuration strategy is a self-defined task configuration strategy;
and analyzing the task configuration strategy, and determining at least one task attribute corresponding to the task configuration strategy as a target attribute.
Specifically, the user may set a corresponding task configuration policy according to actual needs, where the task configuration policy may include one or more task attributes (i.e., target attributes) as allocation criteria. The task processing platform can analyze the current task configuration strategy to obtain one or more corresponding task attributes as target attributes.
For example, a user may set a policy for task configuration according to a device, a network point, or a task type, that is, a task of the same device, a task of the same network point, or a task of the same type guarantees that the same thread executes (or executes sequentially). After analyzing the task configuration policy set by the user, the task processing platform may take the device identifier, the website identifier, or the task type as the target attribute. The device identifier and the website identifier both have the characteristic of a platform-wide unique identifier, that is, different devices have different device identifiers, and different websites have different website identifiers.
For example, the user may set a policy for task configuration according to the network points and task types, that is, the same type of tasks of the same network point ensure the same thread to execute (or execute sequentially), and different types of tasks of the same network point or the same type of tasks of different network points do not need the same thread to execute (or execute sequentially). After the task processing platform analyzes the task configuration strategy set by the user, the network point identification and the task type can be used as target attributes.
It should be noted that the task configuration policy that adopts one or two task attributes as target attributes is only an example and does not limit the embodiment of the present invention, and the task configuration policy may include any number of task attributes according to actual needs. In addition, the strategy for task configuration in the embodiment of the invention can be adjusted in real time according to the actual service requirement, so as to better adapt to the actual requirement of the user.
It can be understood that, in the embodiment of the present invention, by customizing the target attribute by the user, the purpose of specifying the thread for executing the task according to a certain attribute specified by the user can be achieved, and the purpose of ensuring the execution of the same thread by the same attribute can be achieved.
In this embodiment of the present invention, when acquiring the attribute information of at least one target attribute corresponding to the task to be executed, step S230 may be executed to determine a target thread for executing the task to be executed; when the attribute information of at least one target attribute corresponding to the task to be executed is not acquired, the thread for executing the task to be executed may be allocated by a policy of the target thread pool itself.
The policy of the target thread pool may be set according to actual needs, for example, the policy may be set to randomly allocate a thread of the target thread pool to the task to be executed, or a thread of the target thread pool may be allocated to the task to be executed by using a load balancing principle, and the like, which is not limited in the embodiment of the present invention.
In one possible embodiment, the method may further include:
respectively judging whether the attribute information of each target attribute in the at least one target attribute meets the corresponding preset attribute condition;
and when the attribute information of all the target attributes in the at least one target attribute meets the corresponding preset attribute condition, executing a step of determining a target thread for executing the task to be executed from the target thread pool based on the attribute information of the at least one target attribute.
In practical applications, due to the user-defined strategy of configuring tasks, the tasks of the whole platform or only part of the tasks of the platform can be involved. Therefore, after the attribute information of at least one target attribute of the task to be executed is acquired, whether the task to be executed relates to the task specified by the user can be judged. When the task to be executed relates to the task specified by the user, the method provided by the embodiment of the invention can be adopted, and the thread is distributed to the task to be executed based on the attribute information of the at least one target attribute; when it is determined that the task to be executed does not involve a task specified by the user, a thread for executing the task may be assigned by a policy of the target thread pool itself.
Specifically, when the user sets a corresponding task configuration policy according to actual needs, the user may further specify, in the task configuration policy, a target attribute value set corresponding to the one or more task attributes (i.e., target attributes) serving as the assignment criteria, where the target attribute value set may be used to define the task specified by the user. After the task processing platform analyzes the task configuration strategy set by the user, one or more target attributes can be obtained, and a target attribute value set corresponding to each target attribute can also be obtained.
Specifically, after acquiring the attribute information of at least one target attribute corresponding to the task to be executed, the task processing platform may respectively determine whether the attribute information of each target attribute belongs to a corresponding target attribute value set, and if so, determine that the attribute information of the target attribute satisfies a corresponding preset attribute condition; otherwise, judging that the attribute information of the target attribute does not meet the corresponding preset attribute condition.
For example, the user may set a policy for task configuration of tasks of z-type and w-type devices, that is, the tasks of the z-type and w-type devices are guaranteed to be executed (or executed sequentially) by the same thread, and the tasks of other types of devices are not required to be executed (or executed sequentially) by the same thread. After the task processing platform analyzes the task configuration policy set by the user, the device type can be used as a target attribute, and the target attribute value set corresponding to the device type is { device type z, device type w }.
Correspondingly, after acquiring the device type information corresponding to the task to be executed, the task processing platform may determine whether the device type information is a device type z or a device type w. If the device type information is the device type z or the device type w, it is determined that the device type information satisfies the corresponding preset attribute condition, and the method provided by the embodiment of the present invention may be adopted, so as to allocate a thread to the task to be executed based on the attribute information of the at least one target attribute.
For example, the user may set a policy for task configuration of device a of mesh point x, that is, the tasks of device a of mesh point x are guaranteed to be executed (or sequentially executed) by the same thread, and the tasks of other mesh points or other devices of mesh point x are not required to be executed (or sequentially executed) by the same thread. After the task processing platform analyzes the task configuration policy set by the user, the node identifiers and the device identifiers can be used as target attributes, the set of target attribute values corresponding to the node identifiers is { the identification information of the node x }, and the set of target attribute values corresponding to the device identifiers is { the identification information of the device a }.
Correspondingly, after acquiring the first identification information of the website identification and the second identification information of the device identification corresponding to the task to be executed, the task processing platform may determine whether the first identification information is the same as the identification information of the website x, and determine whether the second identification information is the same as the identification information of the device a. If the first identification information and the second identification information are the same, it is determined that both the first identification information and the second identification information meet corresponding preset attribute conditions, and the method provided by the embodiment of the invention may be adopted to allocate a thread to the task to be executed based on the attribute information of the at least one target attribute.
It should be noted that, when a user does not specify a target attribute value set corresponding to a certain target attribute, it may be directly determined that the attribute information of the target attribute satisfies a corresponding preset attribute condition. The task configuration policy that adopts one or two task attributes as target attributes is only an example and does not constitute a limitation to the embodiments of the present invention, and the task configuration policy may include any number of task attributes according to actual needs. In addition, the strategy for task configuration in the embodiment of the invention can be adjusted in real time according to actual service requirements, so as to better adapt to the requirements of users.
It can be understood that, in the embodiment of the present invention, after the attribute information of the target attribute corresponding to the task to be executed is obtained by user-defining the target attribute and the target attribute value set corresponding to the target attribute, based on the target attribute value set, it is determined whether the attribute information meets the corresponding preset attribute condition, and in the case of determining that the condition is met, the thread for processing the task is determined based on the attribute information, so that the task (which may be a part of or all of tasks) having a specific requirement in the multi-thread task can be executed in order according to the actual service requirement.
In one possible embodiment, the method may further include:
when the attribute information of any one of the at least one target attribute does not meet the corresponding preset attribute condition, allocating a thread from the target thread pool as a target thread by using a preset thread allocation strategy;
and distributing the task to be executed to the target thread so that the target thread executes the task to be executed.
Specifically, when the task processing platform determines that the attribute information of one or more target attributes does not satisfy the corresponding preset attribute condition, it is determined that the task to be processed does not relate to a task specified by a user, that is, a thread for executing the task may be allocated by a policy of the target thread pool itself.
It can be understood that, in the embodiment of the present invention, only the task with a specific requirement in the multi-thread tasks is assigned with the thread for executing the task to ensure the execution order thereof, and for other tasks, the thread for executing the task is allocated by the policy of the target thread pool itself, and the execution order thereof does not need to be concerned, which can retain the advantages of the thread pool itself to a certain extent, thereby ensuring the efficiency of the thread pool in processing the task.
S230: and determining a target thread for executing the task to be executed from the target thread pool based on the attribute information of the at least one target attribute.
In the embodiment of the present invention, a target thread may be allocated to the task to be executed from the target thread pool according to the attribute information of the at least one target attribute, and the tasks with the same attribute information may be allocated to the same thread for execution, so as to ensure the ordered execution of the tasks with a certain operation order. Tasks with different attribute information can be distributed to the same thread for execution, and can also be distributed to different threads for execution.
In a possible embodiment, referring to fig. 3 in combination with the description, the determining, based on the attribute information of the at least one target attribute, a target thread to execute the task from the target thread pool may include:
s231: and carrying out hash operation on the attribute information of the at least one target attribute to obtain a corresponding hash value.
Specifically, when the attribute information of one target attribute is acquired, the hash operation can be directly performed on the attribute information to obtain a corresponding hash value; when the attribute information of a plurality of target attributes is obtained, hash budgeting can be performed on the plurality of attribute information to obtain corresponding hash values. The specific content of the hash operation may refer to the prior art, and is not described herein again in the embodiments of the present invention.
S232: and determining the number of threads in the target thread pool.
Specifically, when the target thread pool is created, the number of threads in the target thread pool may be recorded.
S233: and performing modulus operation on the hash value by taking the thread number as a modulus to obtain a modulus value.
Specifically, the hash value is modulo-operated by taking the number of threads as a modulus, so that a fixed integer value in a modulus range can be obtained. Exemplarily, assuming that the number of threads is n, taking a modulus of the hash value with n as a modulus may result in a value between 1-n.
S234: and determining a thread corresponding to the modulus value from the target thread pool as a target thread for executing the task to be executed.
Specifically, a corresponding relationship between each thread in the target thread pool and each modulus value may be pre-established, and when the modulus value is determined, a thread corresponding to the modulus value may be determined according to the corresponding relationship. In this way, tasks with the same hash/modulo value may be allocated to the same thread in the target thread pool.
Illustratively, as shown in FIG. 4, the threads in the target thread pool may be sorted in advance to obtain thread 1, thread 2, \ 8230, and thread n (where n is the number of threads in the target thread pool). After the module-taking operation is performed to obtain the module-taking value, the thread with the same sequence number as the module-taking value can be used as a target thread for executing the task to be executed. If the modulus value is 1, determining the thread 1 as a target thread; and if the modulus value is n-1, determining the thread n-1 as a target thread.
In practical applications, the step S230 may be performed by a "thread scheduler". Because the operation result values of Hash operation performed on the tasks with the same attribute information are the same, and the processing threads corresponding to the execution of the tasks in the distributed thread pools are also the same, the tasks with the same attribute information can be realized, and the tasks can be executed according to the submission sequence of the tasks.
It can be understood that, in the embodiment of the present invention, by introducing the attribute information of at least one target attribute to perform Hash operation and then perform modulo operation, and then allocating the task to the thread corresponding to the modulo value, it is realized that the task of a specific type can specify the thread to be executed correspondingly, it is ensured that the tasks having specific requirements can all be executed in order in the thread pool, and meanwhile, the integrity of data is ensured.
S240: and distributing the task to be executed to the target thread so that the target thread executes the task to be executed.
In the embodiment of the invention, the target thread can sequentially execute the distributed tasks to be executed, namely, the distributed tasks are executed firstly and then the distributed tasks are executed, so that the normal execution of each task is ensured, and the execution result data is obtained.
The following describes an exemplary task processing flow with reference to a specific application example.
Firstly, an internet of things device management platform is taken as an example for explanation, a device registration process of the internet of things device management platform may include activation, check-in, pre-check-in and the like, and it can be seen that a device activation task, a device check-in task and a device pre-check-in task need to be executed in order. The user may preset a policy for performing task configuration according to the device identifier, that is, the customized target attribute may be the device identifier.
When the management platform of the equipment in the internet of things receives tasks to be executed (including equipment activation tasks, equipment sign-in tasks, equipment pre-sign-in tasks and the like) sent by each equipment in the internet of things, corresponding equipment identification information can be obtained, hash operation is carried out on the equipment identification information through a thread scheduler, modulus operation is carried out on the obtained Hash value by taking the number of threads in a target thread pool as modulus, and a corresponding execution thread is determined according to the obtained modulus value.
Assuming that the task to be executed with the corresponding device identification information a is processed by the thread 1 after hash operation and modular operation, the device activation task, the device sign-in task, the device pre-sign-in task and the like sent by the equipment a of the internet of things are all appointed to be processed by the thread 1. Since the equipment a of the internet of things sequentially sends the equipment activation task, the equipment sign-in task and the equipment pre-sign-in task to the management platform of the equipment of the internet of things, the thread 1 can orderly execute each task of the equipment a of the internet of things according to the writing sequence of the tasks. Therefore, for the equipment of the Internet of things marked as a, the equipment activation task is executed firstly, then the equipment sign-in task, the equipment pre-sign-in task and the like are executed, and the execution sequence of the tasks is ensured.
In the following, a website management platform is taken as an example for description, and the website management platform can manage data of each website. Each network node is assumed to include multiple devices, and each device may send a task to be executed to the network node management platform.
Assuming that tasks sent by partial devices in partial mesh points need to be executed in order currently, a user may set a policy for task configuration of the partial devices (for example, devices of which the device types are z in mesh points x and y) in partial mesh points (for example, mesh point x and mesh point y), that is, the customized target attribute may be a mesh point identifier and a device type.
When the network management platform receives a task to be executed sent by each device in each network, the network management platform can acquire corresponding network identification information and device type information, judge whether the network identification information is x or y, and judge whether the device type information is z, when the network identification information corresponding to the task to be executed is x or y and the device type information is z, hash operation is performed on the network identification information and the device type information through a thread scheduler, modulo operation is performed on an obtained hash value by taking the number of threads in a target thread pool as a modulus, and a corresponding execution thread is determined according to the obtained modulo value.
Assuming that tasks to be executed with corresponding network point identification information x and device type information z are both processed by the thread 2 after hash operation and modulo operation, each task sent by a device of z type in the network point x is designated to be processed by the thread 2. The thread 2 executes each task of the type of equipment in order according to the writing sequence of the tasks, so that the sequential execution sequence of each task of the type z equipment in the mesh point x is realized.
When the mesh point identification information corresponding to the task to be executed is neither x nor y, or the device type information is not z, the task may be ignored/discarded by a "thread scheduler", and a thread for executing the task is allocated by a policy of the target thread pool itself.
In summary, according to the task processing method in the embodiment of the present invention, by customizing at least one target attribute, and according to the attribute information of the at least one target attribute corresponding to the task to be executed, the target thread for executing the task to be executed is determined, so as to achieve the purpose that the tasks with the same attribute ensure that the same thread is executed, and enable the multi-thread tasks with the same attribute to be executed in order in the thread pool, thereby meeting the requirement of sequential operation of the multiple tasks and ensuring normal execution of the tasks.
In addition, because the tasks with the same attribute are all distributed to the same thread for execution, the information such as the execution records, logs and the like of the tasks can be inquired in the corresponding thread instead of screening in multiple threads, and the positioning efficiency of production events/problems is improved.
Referring to the specification, fig. 5 shows a structure of a task processing device 500 according to an embodiment of the present invention. As shown in fig. 5, the apparatus 500 may include:
a task receiving module 510, configured to receive a task to be executed submitted to a target thread pool;
an attribute obtaining module 520, configured to obtain attribute information of at least one target attribute corresponding to the task to be executed, where the target attribute is a user-defined task attribute;
a thread determining module 530, configured to determine, based on the attribute information of the at least one target attribute, a target thread for executing the task to be executed from the target thread pool;
a task allocating module 540, configured to allocate the task to be executed to the target thread, so that the target thread executes the task to be executed.
In one possible embodiment, the apparatus 500 may further include:
the configuration strategy determining module is used for determining a current task configuration strategy, and the task configuration strategy is a self-defined task configuration strategy;
and the analysis module is used for analyzing the task configuration strategy and determining at least one task attribute corresponding to the task configuration strategy as a target attribute.
In one possible embodiment, the apparatus 500 may further include:
the judging module is used for respectively judging whether the attribute information of each target attribute in the at least one target attribute meets the corresponding preset attribute condition;
the thread determining module 530 is configured to determine, based on the attribute information of the at least one target attribute, a target thread for executing the task to be executed from the target thread pool when the attribute information of all target attributes of the at least one target attribute satisfies the corresponding preset attribute condition.
In a possible embodiment, the thread determining module 530 is further configured to, when the attribute information of any one of the at least one target attribute does not satisfy the corresponding preset attribute condition, allocate a thread from the target thread pool to the task to be executed by using a preset thread allocation policy, where the thread is used as a target thread.
It should be noted that, when the apparatus provided in the foregoing embodiment implements the functions thereof, the division of each functional module is merely used as an example, and in practical applications, the above function distribution may be completed by different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules, so as to complete all or part of the functions described above. In addition, the apparatus provided in the above embodiments and the corresponding method embodiments belong to the same concept, and specific implementation processes thereof are detailed in the corresponding method embodiments and are not described herein again.
An embodiment of the present invention further provides an electronic device, which includes a processor and a memory, where the memory stores at least one instruction or at least one program, and the at least one instruction or the at least one program is loaded and executed by the processor to implement the task processing method provided by the above method embodiment.
The memory may be used to store software programs and modules, and the processor may execute various functional applications and data processing by operating the software programs and modules stored in the memory. The memory can mainly comprise a program storage area and a data storage area, wherein the program storage area can store an operating system, application programs needed by functions and the like; the storage data area may store data created according to use of the apparatus, and the like. Further, the memory may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other volatile solid state storage device. Accordingly, the memory may also include a memory controller to provide the processor access to the memory.
Referring to FIG. 6 in conjunction with the description, a block diagram of an electronic device 600 according to one embodiment of the application is shown. Electronic device 600 may include one or more processors 602, system control logic 608 coupled to at least one of processors 602, system memory 604 coupled to system control logic 608, non-volatile memory (NVM) 606 coupled to system control logic 608, and network interface 610 coupled to system control logic 608.
Processor 602 may include one or more single-core or multi-core processors. The processor 602 may include any combination of general-purpose processors and dedicated processors (e.g., graphics processors, application processors, baseband processors, etc.). In embodiments herein, the processor 602 may be configured to perform one or more embodiments in accordance with the various embodiments shown in fig. 2-4.
In some embodiments, system control logic 608 may include any suitable interface controllers to provide any suitable interface to at least one of processors 602 and/or any suitable device or component in communication with system control logic 608.
In some embodiments, system control logic 608 may include one or more memory controllers to provide an interface to system memory 604. System memory 604 may be used to load and store data and/or instructions. Memory 604 of device 600 may comprise any suitable volatile memory in some embodiments, such as suitable Dynamic Random Access Memory (DRAM).
NVM/memory 606 may include one or more tangible, non-transitory computer-readable media for storing data and/or instructions. In some embodiments, the NVM/memory 606 may include any suitable non-volatile memory, such as flash memory, and/or any suitable non-volatile storage device, such as at least one of a HDD (Hard Disk Drive), CD (Compact Disc) Drive, DVD (Digital Versatile Disc) Drive.
NVM/memory 606 may include a portion of a storage resource installed on a device of device 600 or it may be accessible by, but not necessarily a part of, the device. For example, NVM/storage 606 may be accessed over a network via network interface 610.
In particular, system memory 604 and NVM/storage 606 may include: a temporary copy and a permanent copy of instructions 620. The instructions 620 may include: instructions that when executed by at least one of the processors 602 cause the apparatus 600 to implement the task processing method as shown in fig. 2-4. In some embodiments, the instructions 620, hardware, firmware, and/or software components thereof may additionally/alternatively be located in the system control logic 608, the network interface 610, and/or the processor 602.
Network interface 610 may include a transceiver to provide a radio interface for device 600 to communicate with any other suitable devices (e.g., front end modules, antennas, etc.) over one or more networks. In some embodiments, the network interface 610 may be integrated with other components of the device 600. For example, the network interface 610 may be integrated with at least one of the communication module of the processor 602, the system memory 604, the nvm/storage 606, and a firmware device (not shown) having instructions that, when executed by at least one of the processors 602, the device 600 implements one or more of the various embodiments shown in fig. 2-4.
The network interface 610 may further include any suitable hardware and/or firmware to provide a multiple-input multiple-output radio interface. For example, network interface 610 may be a network adapter, a wireless network adapter, a telephone modem, and/or a wireless modem.
In one embodiment, at least one of the processors 602 may be packaged together with logic for one or more controllers of system control logic 608 to form a System In Package (SiP). In one embodiment, at least one of processors 602 may be integrated on the same die with logic for one or more controllers of system control logic 608 to form a system on a chip (SoC).
The apparatus 600 may further comprise: input/output (I/O) devices 612.I/O device 612 may include a user interface to enable a user to interact with device 600; the design of the peripheral component interface enables peripheral components to also interact with the device 600. In some embodiments, the device 600 further comprises a sensor for determining at least one of environmental conditions and location information associated with the device 600.
In some embodiments, the user interface may include, but is not limited to, a display (e.g., a liquid crystal display, a touch screen display, etc.), a speaker, a microphone, one or more cameras (e.g., still image cameras and/or video cameras), a flashlight (e.g., a light emitting diode flash), and a keyboard.
In some embodiments, the peripheral component interfaces may include, but are not limited to, a non-volatile memory port, an audio jack, and a power interface.
In some embodiments, the sensors may include, but are not limited to, a gyroscope sensor, an accelerometer, a proximity sensor, an ambient light sensor, and a positioning unit. The positioning unit may also be part of the network interface 610 or interact with the network interface 610 to communicate with components of a positioning network, such as Global Positioning System (GPS) satellites.
It is to be understood that the illustrated structure of the embodiment of the present invention does not specifically limit the electronic device 600. In other embodiments of the present application, the electronic device 600 may include more or fewer components than illustrated, or combine certain components, or split certain components, or a different arrangement of components. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
An embodiment of the present invention further provides a computer-readable storage medium, which can be disposed in an electronic device to store at least one instruction or at least one program for implementing a task processing method, where the at least one instruction or the at least one program is loaded and executed by the processor to implement the task processing method provided by the foregoing method embodiment.
Optionally, in an embodiment of the present invention, the storage medium may include, but is not limited to: a U-disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a removable hard disk, a magnetic disk, or an optical disk, and various media capable of storing program codes.
An embodiment of the present invention also provides a computer program product comprising a computer program/instructions which is loaded and executed by a processor to implement the steps of the task processing method provided in the various alternative embodiments described above, when the computer program product is run on an electronic device.
The computer programs/instructions may be implemented in a high level procedural or object oriented programming language to communicate with a processing system. The program/instruction code may also be implemented in assembly or machine language, if desired. Indeed, the mechanisms described herein are not limited in scope to any particular programming language. In any case, the language may be a compiled or interpreted language.
It should be noted that: the sequence of the above embodiments of the present invention is only for description, and does not represent the advantages or disadvantages of the embodiments. And that specific embodiments have been described above. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims can be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing may also be possible or may be advantageous.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, as for the apparatus embodiment, since it is substantially similar to the method embodiment, the description is relatively simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
It will be understood by those skilled in the art that all or part of the steps for implementing the above embodiments may be implemented by hardware, or may be implemented by a program instructing relevant hardware, where the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a magnetic disk or an optical disk, etc.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and should not be taken as limiting the scope of the present invention, which is intended to cover any modifications, equivalents, improvements, etc. within the spirit and scope of the present invention.

Claims (10)

1. A method for processing a task, comprising:
receiving a task to be executed submitted to a target thread pool;
acquiring attribute information of at least one target attribute corresponding to the task to be executed, wherein the target attribute is a self-defined task attribute;
determining a target thread for executing the task to be executed from the target thread pool based on the attribute information of the at least one target attribute;
and distributing the task to be executed to the target thread so that the target thread executes the task to be executed.
2. The method of claim 1, further comprising:
determining a current task configuration strategy, wherein the task configuration strategy is a self-defined task configuration strategy;
and analyzing the task configuration strategy, and determining at least one task attribute corresponding to the task configuration strategy as a target attribute.
3. The method of claim 1, further comprising:
respectively judging whether the attribute information of each target attribute in the at least one target attribute meets the corresponding preset attribute condition;
and when the attribute information of all the target attributes in the at least one target attribute meets the corresponding preset attribute condition, executing a step of determining a target thread for executing the task to be executed from the target thread pool based on the attribute information of the at least one target attribute.
4. The method of claim 3, further comprising:
when the attribute information of any one of the at least one target attribute does not meet the corresponding preset attribute condition, allocating a thread from the target thread pool by using a preset thread allocation strategy as a target thread;
and distributing the task to be executed to the target thread so that the target thread executes the task to be executed.
5. The method of claim 1, wherein the determining a target thread from the pool of target threads to execute the task based on the attribute information of the at least one target attribute comprises:
performing hash operation on the attribute information of the at least one target attribute to obtain a corresponding hash value;
determining the number of threads in the target thread pool;
performing modulus operation on the hash value by taking the thread number as a modulus to obtain a modulus value;
and determining a thread corresponding to the modulus value from the target thread pool as a target thread for executing the task to be executed.
6. The method of claim 1, wherein the target attribute comprises a device identification, a device type, a mesh point identification, a mesh point type, a task identification, or a task type.
7. A task processing apparatus, characterized by comprising:
the task receiving module is used for receiving the tasks to be executed submitted to the target thread pool;
the attribute acquisition module is used for acquiring attribute information of at least one target attribute corresponding to the task to be executed, wherein the target attribute is a self-defined task attribute;
a thread determining module, configured to determine, based on attribute information of the at least one target attribute, a target thread for executing the task to be executed from the target thread pool;
and the task distribution module is used for distributing the task to be executed to the target thread so as to enable the target thread to execute the task to be executed.
8. An electronic device, comprising a processor and a memory, wherein at least one instruction or at least one program is stored in the memory, and the at least one instruction or the at least one program is loaded by the processor and executed to implement the task processing method according to any one of claims 1 to 6.
9. A computer-readable storage medium, wherein at least one instruction or at least one program is stored in the computer-readable storage medium, and the at least one instruction or the at least one program is loaded and executed by a processor to implement the task processing method according to any one of claims 1 to 6.
10. A computer program product comprising computer programs/instructions, characterized in that the computer programs/instructions, when executed by a processor, implement the steps of the task processing method of any of claims 1-6.
CN202211147627.0A 2022-09-19 2022-09-19 Task processing method, device, equipment, storage medium and program product Pending CN115480897A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211147627.0A CN115480897A (en) 2022-09-19 2022-09-19 Task processing method, device, equipment, storage medium and program product

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211147627.0A CN115480897A (en) 2022-09-19 2022-09-19 Task processing method, device, equipment, storage medium and program product

Publications (1)

Publication Number Publication Date
CN115480897A true CN115480897A (en) 2022-12-16

Family

ID=84392852

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211147627.0A Pending CN115480897A (en) 2022-09-19 2022-09-19 Task processing method, device, equipment, storage medium and program product

Country Status (1)

Country Link
CN (1) CN115480897A (en)

Similar Documents

Publication Publication Date Title
US20200192707A1 (en) Performance-based hardware emulation in an on-demand network code execution system
CN109684065B (en) Resource scheduling method, device and system
CA3000422C (en) Workflow service using state transfer
CN115328663A (en) Method, device, equipment and storage medium for scheduling resources based on PaaS platform
TWI694700B (en) Data processing method and device, user terminal
US20240111549A1 (en) Method and apparatus for constructing android running environment
CN113821311A (en) Task execution method and storage device
CN112540841A (en) Task scheduling method and device, processor and electronic equipment
WO2016074130A1 (en) Batch processing method and device for system invocation commands
CN116166395A (en) Task scheduling method, device, medium and electronic equipment
CN113010265A (en) Pod scheduling method, scheduler, memory plug-in and system
CN115686805A (en) GPU resource sharing method and device, and GPU resource sharing scheduling method and device
US20200310828A1 (en) Method, function manager and arrangement for handling function calls
US20150100964A1 (en) Apparatus and method for managing migration of tasks between cores based on scheduling policy
CN111913792A (en) Service processing method and device
CN113051245A (en) Method, device and system for migrating data
CN116010093A (en) Data processing method, apparatus, computer device and readable storage medium
CN115480897A (en) Task processing method, device, equipment, storage medium and program product
CN115114022A (en) Method, system, device and medium for using GPU resources
CN114138444A (en) Task scheduling method, device, equipment, storage medium and program product
KR101558807B1 (en) Processor scheduling method for the cooperation processing between host processor and cooperation processor and host processor for performing the method
US10503557B2 (en) Method of processing OpenCL kernel and computing device therefor
CN113742646A (en) Compiling a single language compound function into a single entity
CN116032928B (en) Data collaborative computing method, device, system, electronic device and storage medium
CN113254180B (en) Data matching method and device, electronic equipment and storage medium

Legal Events

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