CN116028167A - Task processing method and device, electronic equipment and storage medium - Google Patents

Task processing method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN116028167A
CN116028167A CN202111254890.5A CN202111254890A CN116028167A CN 116028167 A CN116028167 A CN 116028167A CN 202111254890 A CN202111254890 A CN 202111254890A CN 116028167 A CN116028167 A CN 116028167A
Authority
CN
China
Prior art keywords
preset
thread
queue
executed
execution
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
CN202111254890.5A
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.)
Beijing Zitiao Network Technology Co Ltd
Original Assignee
Beijing Zitiao Network Technology Co Ltd
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 Beijing Zitiao Network Technology Co Ltd filed Critical Beijing Zitiao Network Technology Co Ltd
Priority to CN202111254890.5A priority Critical patent/CN116028167A/en
Publication of CN116028167A publication Critical patent/CN116028167A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the disclosure discloses a task processing method, a device, electronic equipment and a storage medium, wherein the method comprises the following steps: adding tasks to be executed to a preset queue; configuring thread creation amount for a preset thread pool corresponding to the preset queue according to current processing resources, and determining the creation of an execution thread according to the thread creation amount based on the preset thread pool; executing tasks to be executed in the preset queue based on the execution threads created in the preset thread pool, and outputting an execution result. When a large number of tasks are executed concurrently, the thread creation amount of each preset thread pool is configured according to the current processing resources, so that the creation number of execution threads can be limited, and the consumption of CPU resources in the high concurrent task is effectively reduced.

Description

Task processing method and device, electronic equipment and storage medium
Technical Field
The embodiment of the disclosure relates to the technical field of computers, in particular to a task processing method, a task processing device, electronic equipment and a storage medium.
Background
In the prior art, when an application program concurrently executes a large number of tasks in the background, a large number of threads are created for executing the tasks in a short time. Some tasks may be blocked by waiting for a thread lock, and applications may create more threads to meet the demand in order to execute subsequent tasks.
The shortcomings of the prior art at least include that when the concurrent task of the application program rises sharply in a short time, a large number of threads are created, run, blocked and destroyed at the same time, and a large amount of central processing unit (Central Processing Unit, CPU) resources are consumed.
Disclosure of Invention
The embodiment of the disclosure provides a task processing method, a device, electronic equipment and a storage medium, which can effectively reduce the consumption of CPU resources in high-concurrency tasks.
In a first aspect, an embodiment of the present disclosure provides a task processing method, including:
adding tasks to be executed to a preset queue;
configuring thread creation amount for a preset thread pool corresponding to the preset queue according to current processing resources, and determining the creation of an execution thread according to the thread creation amount based on the preset thread pool;
executing tasks to be executed in the preset queue based on the execution threads created in the preset thread pool, and outputting an execution result.
In a second aspect, an embodiment of the present disclosure further provides a task processing device, including:
the task adding module is used for adding the task to be executed to a preset queue;
the thread creation module is used for configuring thread creation amount for a preset thread pool corresponding to the preset queue according to the current processing resource, and determining the creation of an execution thread according to the thread creation amount based on the preset thread pool;
the task processing module is used for executing the task to be executed in the preset queue based on the execution thread created in the preset thread pool and outputting an execution result.
In a third aspect, embodiments of the present disclosure further provide an electronic device, including:
one or more processors;
storage means for storing one or more programs,
the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the task processing method as described in any of the embodiments of the present disclosure.
In a fourth aspect, the disclosed embodiments also provide a storage medium containing computer-executable instructions for performing the task processing method according to any of the disclosed embodiments when executed by a computer processor.
According to the technical scheme, tasks to be executed are added to a preset queue; configuring thread creation amount for a preset thread pool corresponding to a preset queue according to current processing resources, and determining the creation of an execution thread according to the thread creation amount based on the preset thread pool; executing tasks to be executed in a preset queue based on execution threads created in a preset thread pool, and outputting an execution result.
When a large number of tasks are executed concurrently, the thread creation amount of each preset thread pool is configured according to the current processing resources, whether to create an execution thread is determined based on the preset thread pool according to the configured thread creation amount, and tasks to be executed in the corresponding preset queue are executed based on the created execution threads in the preset thread pool, so that the creation amount of the execution threads can be limited, and the consumption of CPU resources in the high-concurrency task can be effectively reduced.
Drawings
The above and other features, advantages, and aspects of embodiments of the present disclosure will become more apparent by reference to the following detailed description when taken in conjunction with the accompanying drawings. The same or similar reference numbers will be used throughout the drawings to refer to the same or like elements. It should be understood that the figures are schematic and that elements and components are not necessarily drawn to scale.
Fig. 1 is a flow chart of a task processing method according to a first embodiment of the disclosure;
fig. 2 is a flow chart of a task processing method according to a second embodiment of the disclosure;
fig. 3 is a task processing block diagram in a task processing method according to a second embodiment of the present disclosure;
fig. 4 is a schematic structural diagram of a task processing device according to a third embodiment of the present disclosure;
fig. 5 is a schematic structural diagram of an electronic device according to a fourth embodiment of the disclosure.
Detailed Description
Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While certain embodiments of the present disclosure have been shown in the accompanying drawings, it is to be understood that the present disclosure may be embodied in various forms and should not be construed as limited to the embodiments set forth herein, but are provided to provide a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are for illustration purposes only and are not intended to limit the scope of the present disclosure.
It should be understood that the various steps recited in the method embodiments of the present disclosure may be performed in a different order and/or performed in parallel. Furthermore, method embodiments may include additional steps and/or omit performing the illustrated steps. The scope of the present disclosure is not limited in this respect.
The term "including" and variations thereof as used herein are intended to be open-ended, i.e., including, but not limited to. The term "based on" is based at least in part on. The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments. Related definitions of other terms will be given in the description below.
It should be noted that the terms "first," "second," and the like in this disclosure are merely used to distinguish between different devices, modules, or units and are not used to define an order or interdependence of functions performed by the devices, modules, or units.
It should be noted that references to "one", "a plurality" and "a plurality" in this disclosure are intended to be illustrative rather than limiting, and those of ordinary skill in the art will appreciate that "one or more" is intended to be understood as "one or more" unless the context clearly indicates otherwise.
Example 1
Fig. 1 is a flowchart of a task processing method according to an embodiment of the disclosure. The task processing method provided by the embodiment of the disclosure is suitable for the situation of executing tasks, and is especially suitable for the situation of executing high concurrency asynchronous tasks by application programs. The method may be performed by a task processing device, which may be implemented in software and/or hardware, which may be configured in an electronic device, such as a mobile phone, a computer.
As shown in fig. 1, the task processing method provided in this embodiment includes:
s110, adding the task to be executed to a preset queue.
The apparatus for performing the task processing method may be integrated with the application program and may be installed in the electronic device with the application program. In the running process of the application program, different tasks to be executed can be generated for realizing different service functions. The tasks to be performed may include, but are not limited to, parallel tasks, concurrent asynchronous tasks, and the like. Wherein, parallel tasks may refer to multiple tasks that execute different threads based on different CPU cores to run simultaneously; concurrent asynchronous tasks may refer to multiple tasks that switch execution based on the same CPU core switching execution of different threads, but concurrent asynchronous tasks may be perceived as being executed simultaneously by the same CPU core. For example, an application program may generate a large number of asynchronous tasks that need to be performed concurrently for processing rendering of complex pages.
In this embodiment, the task to be executed generated in the application program may be monitored in real time, and the execution task may be added to the preset queue when the generation of the execution task is monitored, so that task queuing may be implemented, so that the queued tasks may be executed sequentially.
During the running of an application, there are situations where a large number of tasks need to be performed in a short time in order to implement some business functions. In some alternative implementations, adding the task to be performed to the preset queue may include: and adding the tasks to be executed to a preset queue when the number of the tasks to be executed in unit time is greater than a preset threshold value.
In these alternative implementations, the tasks to be executed generated in the unit time in the application program may be specifically monitored in real time, and when the number of tasks to be executed generated in the unit time is monitored to be greater than the preset threshold, it may be considered that a situation in which a large number of tasks need to be executed in a short time currently occurs. The unit time and the preset threshold value can be adjusted according to specific application scenes. When the number of tasks to be executed in unit time is monitored to be larger than a preset threshold, the tasks to be executed are added into a preset queue, and the creation of threads is managed based on the preset queue, so that performance pressure caused by executing a large number of tasks can be effectively buffered.
S120, configuring thread creation amount for a preset thread pool corresponding to the preset queue according to the current processing resource, and determining the creation of an execution thread according to the thread creation amount based on the preset thread pool.
Wherein the processing resources may include, but are not limited to, the remaining number of cores of a Central Processing Unit (CPU). The CPU may refer to a CPU of an electronic device in which the above-described application program is installed. The kernel number may refer to the kernel number of a hardware CPU, or a logically emulated CPU. The remaining number of cores of the CPU may refer to the number of cores of the CPU that are currently available, idle. In addition, the processing resources may also include other resources, such as remaining space that may be memory/cache, and so on.
The preset queue may correspond to a preset thread pool. The preset thread pool can be regarded as a multithreading processing form, tasks to be executed can be added to a preset queue in the processing process, and the tasks to be executed in the preset queue can be automatically started after the execution thread is created.
Where the thread creation amount may refer to the number of threads allowed to be created. The configuring the thread creation amount for the preset thread pool corresponding to the preset queue according to the current processing resource may include at least one of the following: determining the corresponding thread creation amount according to the preset corresponding relation between the processing resources and the creation amount, and configuring a preset queue according to the current processing resources; calculating the corresponding thread creation amount according to the pre-established mathematical model of the processing resource-creation amount, and configuring a preset queue according to the current processing resource; and outputting the corresponding thread creation amount according to the current processing resource according to a pre-trained processing resource-creation amount network model, and configuring a preset queue. In general, the more abundant the current processing resources, the greater the amount of thread creation for a preset queue configuration.
The execution threads may be maintained based on a preset thread pool, and may include, but not limited to, creating, running, blocking, destroying, etc. the execution threads based on the preset thread pool. After the thread creation amount is configured for the preset thread pool, whether to create the execution threads or not can be determined according to the thread creation amount based on the preset thread pool, so that the number of the execution threads created in the preset thread pool does not exceed the thread creation amount. Wherein the creation of the execution thread may be performed based on a predefined thread creation interface.
In addition, the preset thread pool can also synthesize queuing conditions of tasks to be executed in the preset queue on the basis of the thread creation amount, so that the creation of the execution thread can be determined. For example, when the preset queue is empty, i.e., all tasks to be executed have been executed, it may be determined directly that a new execution thread is not created, and/or it may be determined to destroy the idle execution thread.
The number of the execution threads can be limited by configuring the thread creation amount of each preset thread pool according to the current processing resources and determining whether to create the execution threads according to the thread creation amount, so that the consumption of CPU resources under the condition that tasks rise sharply in a short time can be effectively reduced.
In some alternative implementations, determining creation of the execution thread according to the thread creation amount based on the preset thread pool may include: and determining the creation of the execution threads based on a comparison result of the number of the execution threads which are currently created and the thread creation amount by a preset thread pool.
In these alternative implementations, if the number of currently created execution threads within the preset thread pool is less than the thread creation amount, then it may be determined to create a new execution thread; if the number of currently created execution threads within the preset thread pool is equal to the thread creation amount, it may be determined that no new execution threads are created. In other embodiments, when the number of currently created execution threads in the preset thread pool is less than the thread creation amount and the preset queue is empty, it may also be determined that no new execution thread is created. Thus, the number of the execution threads created in the preset thread pool can be ensured not to exceed the thread creation amount.
S130, executing tasks to be executed in a preset queue based on execution threads created in a preset thread pool, and outputting an execution result.
The task to be executed can be provided with a scheduling interface for scheduling the execution thread which is built in the corresponding preset thread pool. The execution thread can sequentially schedule the tasks to be executed from a preset queue, can also schedule a plurality of tasks to be executed at the same time, and can output an execution result when the tasks to be executed are executed. When the task to be executed is scheduled or executed, the task to be executed can be removed from the preset queue until the preset queue is empty.
In a conventional task processing scheme, for a short number of tasks to be executed, a large number of threads are created to process the tasks. Some tasks to be executed may be blocked due to waiting for a thread lock, and an application may create more threads to satisfy the demand in order to execute a subsequent task. Creating threads, blocking, creating new threads.
In the embodiment of the disclosure, for a short-time large number of tasks to be executed, the thread creation amount of the preset thread pool corresponding to the preset queue may be configured based on the current processing resource, and the threads may be created according to the thread creation amount, so as to execute the tasks to be executed cached in the preset queue. Therefore, the thread number created by the application program can be effectively controlled, and the consumption of CPU resources is reduced.
According to the technical scheme, tasks to be executed are added to a preset queue; configuring thread creation amount for a preset thread pool corresponding to a preset queue according to current processing resources, and determining the creation of an execution thread according to the thread creation amount based on the preset thread pool; executing tasks to be executed in a preset queue based on execution threads created in a preset thread pool, and outputting an execution result.
When a large number of tasks are executed concurrently, the thread creation amount of each preset thread pool is configured according to the current processing resources, whether to create an execution thread is determined based on the preset thread pool according to the configured thread creation amount, and tasks to be executed in the corresponding preset queue are executed based on the created execution threads in the preset thread pool, so that the creation amount of the execution threads can be limited, and the consumption of CPU resources in the high-concurrency task can be effectively reduced.
Example two
The embodiments of the present disclosure may be combined with each of the alternatives in the task processing method provided in the above embodiments. In the task processing method provided by the embodiment, the task to be executed is provided with the task priority, the preset queue is provided with the queue priority, and the two priorities have the corresponding relation. By adding the tasks to be executed to the corresponding preset queues according to the corresponding relation of the two priorities and configuring different thread creation amounts for each preset thread pool according to the priorities of the queues, the thread resources for processing the tasks to be executed with different execution priorities can be distinguished, the thread creation amount of the corresponding preset thread pool is larger when the priorities of the queues are higher, and therefore the tasks to be executed with high execution priorities can be processed more quickly.
Fig. 2 is a flow chart of a task processing method according to a second embodiment of the disclosure. As shown in fig. 2, the task processing method provided in this embodiment includes:
s210, adding the task to be executed to a corresponding preset queue according to the corresponding relation between the execution priority and the queue priority.
In this embodiment, the task to be executed is provided with an execution priority, the preset queue is provided with a queue priority, and the execution priority and the queue priority have a corresponding relationship. Wherein, each task to be executed can set the execution priority when generating, and each preset queue can also set the queue priority when creating. The execution priority and the queue priority have a corresponding relation, which means that the number of execution priority divisions is consistent with the number of queue priority divisions, and the priorities of the same level correspond to each other.
Illustratively, execution priority may be categorized as high, medium, and low, and queue priority may be categorized as high, medium, and low. And the high-level execution priority corresponds to the high-level queue priority; the execution priority of the middle level corresponds to the queue priority of the middle level; the low-level execution priority corresponds to the low-level queue priority. It can be considered that the task to be executed with the high-level execution priority can be added into a preset queue with the high-level queue priority; the task to be executed with the middle-level execution priority can be added into a preset queue with the middle-level queue priority; the task to be executed with the low-level execution priority can be added to a preset queue with the low-level queue priority.
In addition, since the preset queues may correspond to preset thread pools, each preset queue corresponds to a preset thread pool. The preset thread pools may also be considered to have thread pool priorities, and the thread pool priority of each preset thread pool is consistent with the queue priority of the corresponding preset queue.
S220, configuring thread creation amount for a preset thread pool corresponding to a preset queue according to current processing resources based on the queue priority, and determining the creation of an execution thread according to the thread creation amount based on the preset thread pool.
Since the preset queues correspond to the preset thread pools, different thread creation amounts are configured for the preset thread pools corresponding to the preset queues with different queue priorities, and the different thread creation amounts can be configured for the preset thread pools with different thread pool priorities. The higher the queue priority, the higher the thread pool priority, and the larger the thread creation amount configured for the corresponding preset thread pool according to the current processing resource. For preset queues of each queue priority level, corresponding execution threads can be created according to respective thread creation amounts based on corresponding preset thread pools.
S230, executing tasks to be executed in a preset queue based on execution threads created in a preset thread pool, and outputting an execution result.
Based on the execution threads created in each preset thread pool, the task to be executed in the corresponding preset queue can be executed, and an execution result is output. Fig. 3 is a task processing block diagram in a task processing method according to a second embodiment of the present disclosure. Referring to fig. 3, the execution priority of the task to be executed may be classified into high, medium and low levels, the queue priority of the preset queue may be classified into high, medium and low levels, and the thread pool priority of the preset thread pool may be classified into high, medium and low levels.
In fig. 3, when a large number of concurrent tasks (i.e., tasks to be executed) occur in a short time, first, the large number of concurrent tasks may be divided into three levels of high, medium, and low according to the execution priority of the concurrent tasks, and 0, 1, or more concurrent tasks may be included in each level. Secondly, concurrent tasks with high/medium/low execution priority can be respectively added into custom concurrent queues (i.e. preset queues) with high/medium/low queue priority. Again, thread creation amounts may be configured for corresponding levels of thread pools (i.e., preset thread pools) respectively, based on the queue priorities of the custom concurrency queues, respectively. Next, for thread pools of different thread pool priorities, corresponding execution threads may be created based on different thread creation amounts. For example, a high thread pool priority thread pool may create up to three threads (e.g., thread 1, thread 2, thread 3); a thread pool of medium thread pool priorities may create a maximum of two threads (e.g., thread 4, thread 5); a thread pool of low thread pool priority may create at most one thread (e.g., thread 6). And finally, the created execution threads can respectively execute the tasks to be executed in the preset queues corresponding to the priority levels of the queues, and output the execution results.
According to the technical scheme, tasks to be executed are provided with task priorities, the preset queue is provided with queue priorities, and the two priorities have a corresponding relation. By adding the tasks to be executed to the corresponding preset queues according to the corresponding relation of the two priorities and configuring different thread creation amounts for each preset thread pool according to the priorities of the queues, the thread resources for processing the tasks to be executed with different execution priorities can be distinguished, and therefore the tasks to be executed with high execution priorities can be processed more quickly.
In addition, the task processing method provided by the embodiment of the present disclosure belongs to the same disclosure concept as the task processing method provided by the above embodiment, technical details which are not described in detail in the present embodiment can be referred to the above embodiment, and the same technical features have the same beneficial effects in the present embodiment and the above embodiment.
Example III
Fig. 4 is a schematic structural diagram of a task processing device according to a third embodiment of the present disclosure. The task processing device provided by the embodiment is suitable for executing tasks, and is especially suitable for executing high concurrency asynchronous tasks by application programs.
As shown in fig. 4, the task processing device provided in this embodiment includes:
a task adding module 410, configured to add a task to be executed to a preset queue;
the thread creation module 420 is configured to configure a thread creation amount for a preset thread pool corresponding to the preset queue according to the current processing resource, and determine creation of an execution thread according to the thread creation amount based on the preset thread pool;
the task processing module 430 is configured to execute a task to be executed in a preset queue based on an execution thread created in the preset thread pool, and output an execution result.
In some alternative implementations, the task adding module may be configured to:
and adding the tasks to be executed to a preset queue when the number of the tasks to be executed in unit time is greater than a preset threshold value.
In some optional implementation manners, the task to be executed is provided with an execution priority, the preset queue is provided with a queue priority, and the execution priority and the queue priority have a corresponding relation;
correspondingly, the task adding module is used for adding the task to be executed into the corresponding preset queue according to the corresponding relation between the execution priority and the queue priority;
correspondingly, the thread creation module is used for configuring thread creation amount for a preset thread pool corresponding to the preset queue according to the current processing resource based on the queue priority.
In some alternative implementations, for each preset queue, the higher the queue priority, the greater the amount of thread creation for the corresponding preset thread pool configuration according to the current processing resources.
In some alternative implementations, the thread creation module may also be configured to:
and determining the creation of the execution threads based on a comparison result of the number of the execution threads which are currently created and the thread creation amount by a preset thread pool.
In some alternative implementations, the processing resources include a remaining number of cores of the central processor.
In some alternative implementations, the tasks to be performed include concurrent asynchronous tasks.
The task processing device provided by the embodiment of the disclosure can execute the task processing method provided by any embodiment of the disclosure, and has the corresponding functional modules and beneficial effects of the execution method.
It should be noted that each unit and module included in the above apparatus are only divided according to the functional logic, but not limited to the above division, so long as the corresponding functions can be implemented; in addition, the specific names of the functional units are also only for convenience of distinguishing from each other, and are not used to limit the protection scope of the embodiments of the present disclosure.
Example IV
Referring now to fig. 5, a schematic diagram of an electronic device (e.g., a terminal device or server in fig. 5) 500 suitable for use in implementing embodiments of the present disclosure is shown. The terminal devices in the embodiments of the present disclosure may include, but are not limited to, mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and the like, and stationary terminals such as digital TVs, desktop computers, and the like. The electronic device shown in fig. 5 is merely an example and should not be construed to limit the functionality and scope of use of the disclosed embodiments.
As shown in fig. 5, the electronic device 500 may include a processing means (e.g., a central processor, a graphics processor, etc.) 501 that may perform various appropriate actions and processes according to a program stored in a Read-Only Memory (ROM) 502 or a program loaded from a storage 506 into a random access Memory (Random Access Memory, RAM) 503. In the RAM 503, various programs and data required for the operation of the electronic apparatus 500 are also stored. The processing device 501, the ROM502, and the RAM 503 are connected to each other via a bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
In general, the following devices may be connected to the I/O interface 505: input devices 506 including, for example, a touch screen, touchpad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; an output device 507 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage 508 including, for example, magnetic tape, hard disk, etc.; and communication means 509. The communication means 509 may allow the electronic device 500 to communicate with other devices wirelessly or by wire to exchange data. While fig. 5 shows an electronic device 500 having various means, it is to be understood that not all of the illustrated means are required to be implemented or provided. More or fewer devices may be implemented or provided instead.
In particular, according to embodiments of the present disclosure, the processes described above with reference to flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a non-transitory computer readable medium, the computer program comprising program code for performing the method shown in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via the communication means 509, or from the storage means 506, or from the ROM 502. When executed by the processing device 501, the computer program performs the above-described functions defined in the task processing method of the embodiment of the present disclosure.
The electronic device provided by the embodiment of the present disclosure and the task processing method provided by the foregoing embodiment belong to the same disclosure concept, and technical details not described in detail in the present embodiment may be referred to the foregoing embodiment, and the present embodiment has the same beneficial effects as the foregoing embodiment.
Example five
The present disclosure provides a computer storage medium having stored thereon a computer program which, when executed by a processor, implements the task processing method provided by the above embodiments.
It should be noted that the computer readable medium described in the present disclosure may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-Only Memory (ROM), an erasable programmable read-Only Memory (EPROM) or FLASH Memory (FLASH), an optical fiber, a portable compact disc read-Only Memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this disclosure, a computer-readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present disclosure, however, the computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, with the computer-readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, fiber optic cables, RF (radio frequency), and the like, or any suitable combination of the foregoing.
In some implementations, the clients, servers may communicate using any currently known or future developed network protocol, such as HTTP (Hyper Text Transfer Protocol ), and may be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), the internet (e.g., the internet), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future developed networks.
The computer readable medium may be contained in the electronic device; or may exist alone without being incorporated into the electronic device.
The computer readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to:
adding tasks to be executed to a preset queue; configuring thread creation amount for a preset thread pool corresponding to a preset queue according to current processing resources, and determining the creation of an execution thread according to the thread creation amount based on the preset thread pool; executing tasks to be executed in a preset queue based on execution threads created in a preset thread pool, and outputting an execution result.
Computer program code for carrying out operations of the present disclosure may be written in one or more programming languages, including, but not limited to, an object oriented programming language such as Java, smalltalk, C ++ and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computer (for example, through the Internet using an Internet service provider).
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units involved in the embodiments of the present disclosure may be implemented by means of software, or may be implemented by means of hardware. The names of the units and modules do not limit the units and modules themselves in some cases.
The functions described above herein may be performed, at least in part, by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: a field programmable gate array (Field Programmable Gate Array, FPGA), an application specific integrated circuit (Application Specific Integrated Circuit, ASIC), a special standard product (Application Specific Standard Parts, ASSP), a System On Chip (SOC), a Complex Programmable Logic Device (CPLD), and the like.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. The machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
According to one or more embodiments of the present disclosure, there is provided a task processing method [ example one ], the method comprising:
adding tasks to be executed to a preset queue;
configuring thread creation amount for a preset thread pool corresponding to the preset queue according to current processing resources, and determining the creation of an execution thread according to the thread creation amount based on the preset thread pool;
executing tasks to be executed in the preset queue based on the execution threads created in the preset thread pool, and outputting an execution result.
According to one or more embodiments of the present disclosure, there is provided a task processing method [ example two ] further comprising:
in some optional implementations, the adding the task to be performed to the preset queue includes:
and adding the tasks to be executed to a preset queue when the number of the tasks to be executed in unit time is larger than a preset threshold value.
According to one or more embodiments of the present disclosure, there is provided a task processing method [ example three ], further comprising:
in some optional implementations, the task to be executed is provided with an execution priority, the preset queue is provided with a queue priority, and the execution priority and the queue priority have a corresponding relationship;
correspondingly, the adding the task to be executed to a preset queue includes: adding the task to be executed to a corresponding preset queue according to the corresponding relation between the execution priority and the queue priority;
correspondingly, configuring the thread creation amount for the preset thread pool corresponding to the preset queue according to the current processing resource, including: and configuring thread creation amount for a preset thread pool corresponding to the preset queue according to the current processing resource based on the queue priority.
According to one or more embodiments of the present disclosure, there is provided a task processing method [ example four ], further comprising:
in some alternative implementations, for each of the preset queues, the higher the queue priority, the greater the amount of threads created for the corresponding preset thread pool configuration according to the current processing resource.
According to one or more embodiments of the present disclosure, there is provided a task processing method [ example five ], further comprising:
in some optional implementations, the determining, based on the preset thread pool, creation of an execution thread according to the thread creation amount includes:
and determining the creation of the execution threads based on the comparison result of the number of the execution threads which are created currently and the thread creation amount by the preset thread pool.
According to one or more embodiments of the present disclosure, there is provided a task processing method [ example six ], further comprising:
in some alternative implementations, the processing resources include a remaining number of cores of the central processor.
According to one or more embodiments of the present disclosure, there is provided a task processing method [ example seventh ], further comprising:
in some alternative implementations, the task to be performed includes a concurrent asynchronous task.
The foregoing description is only of the preferred embodiments of the present disclosure and description of the principles of the technology being employed. It will be appreciated by persons skilled in the art that the scope of the disclosure referred to in this disclosure is not limited to the specific combinations of features described above, but also covers other embodiments which may be formed by any combination of features described above or equivalents thereof without departing from the spirit of the disclosure. Such as those described above, are mutually substituted with the technical features having similar functions disclosed in the present disclosure (but not limited thereto).
Moreover, although operations are depicted in a particular order, this should not be understood as requiring that such operations be performed in the particular order shown or in sequential order. In certain circumstances, multitasking and parallel processing may be advantageous. Likewise, while several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of the present disclosure. Certain features that are described in the context of separate embodiments can also be implemented in combination in a single embodiment. Conversely, various features that are described in the context of a single embodiment can also be implemented in multiple embodiments separately or in any suitable subcombination.
Although the subject matter has been described in language specific to structural features and/or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are example forms of implementing the claims.

Claims (10)

1. A method of task processing, comprising:
adding tasks to be executed to a preset queue;
configuring thread creation amount for a preset thread pool corresponding to the preset queue according to current processing resources, and determining the creation of an execution thread according to the thread creation amount based on the preset thread pool;
executing tasks to be executed in the preset queue based on the execution threads created in the preset thread pool, and outputting an execution result.
2. The method of claim 1, wherein adding the task to be performed to a preset queue comprises:
and adding the tasks to be executed to a preset queue when the number of the tasks to be executed in unit time is larger than a preset threshold value.
3. The method according to claim 1, wherein the task to be executed is provided with an execution priority, the preset queue is provided with a queue priority, and the execution priority has a corresponding relationship with the queue priority;
correspondingly, the adding the task to be executed to the preset queue includes: adding the task to be executed to a corresponding preset queue according to the corresponding relation between the execution priority and the queue priority;
correspondingly, the configuring the thread creation amount for the preset thread pool corresponding to the preset queue according to the current processing resource includes: and configuring thread creation amount for a preset thread pool corresponding to the preset queue according to the current processing resource based on the queue priority.
4. A method according to claim 3, wherein for each of said preset queues, the higher the queue priority, the greater the amount of thread creation for the corresponding preset thread pool configuration according to the current processing resource.
5. The method of claim 1, wherein the determining creation of an execution thread based on the thread creation amount based on the preset thread pool comprises:
and determining the creation of the execution threads based on the comparison result of the number of the execution threads which are created currently and the thread creation amount by the preset thread pool.
6. The method of any of claims 1-5, wherein the processing resources comprise a remaining number of cores of a central processing unit.
7. The method of any of claims 1-5, wherein the task to be performed comprises a concurrent asynchronous task.
8. A task processing device, comprising:
the task adding module is used for adding the task to be executed to a preset queue;
the thread creation module is used for configuring thread creation amount for a preset thread pool corresponding to the preset queue according to the current processing resource, and determining the creation of an execution thread according to the thread creation amount based on the preset thread pool;
the task processing module is used for executing the task to be executed in the preset queue based on the execution thread created in the preset thread pool and outputting an execution result.
9. An electronic device, the electronic device comprising:
one or more processors;
storage means for storing one or more programs,
when executed by the one or more processors, causes the one or more processors to implement the task processing method as recited in any one of claims 1-7.
10. A storage medium containing computer executable instructions for performing the task processing method as claimed in any one of claims 1 to 7 when executed by a computer processor.
CN202111254890.5A 2021-10-27 2021-10-27 Task processing method and device, electronic equipment and storage medium Pending CN116028167A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111254890.5A CN116028167A (en) 2021-10-27 2021-10-27 Task processing method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111254890.5A CN116028167A (en) 2021-10-27 2021-10-27 Task processing method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN116028167A true CN116028167A (en) 2023-04-28

Family

ID=86090053

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111254890.5A Pending CN116028167A (en) 2021-10-27 2021-10-27 Task processing method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN116028167A (en)

Similar Documents

Publication Publication Date Title
CN109523187B (en) Task scheduling method, device and equipment
CN114020470B (en) Resource allocation method and device, readable medium and electronic equipment
CN107832143B (en) Method and device for processing physical machine resources
CN111240834B (en) Task execution method, device, electronic equipment and storage medium
CN112379982B (en) Task processing method, device, electronic equipment and computer readable storage medium
CN110764892A (en) Task processing method, device and computer readable storage medium
CN114911385A (en) Secure sharing of multiple applications during a remote session
CN114461393A (en) Multitask scheduling method, multitask scheduling device, electronic equipment, multitask scheduling system and automatic driving vehicle
CN111026552B (en) Resource scheduling method and device, electronic equipment and computer readable storage medium
CN111858040A (en) Resource scheduling method and device
CN115237589A (en) SR-IOV-based virtualization method, device and equipment
CN113157439B (en) Resource statistics method, device and terminal
CN111813541B (en) Task scheduling method, device, medium and equipment
CN110489219B (en) Method, device, medium and electronic equipment for scheduling functional objects
CN110960857B (en) Game data monitoring method and device, electronic equipment and storage medium
CN116821187A (en) Database-based data processing method and device, medium and electronic equipment
CN116661964A (en) Task processing method and device and electronic equipment
CN111324387A (en) Application task control method, device, terminal and system
CN110837419A (en) Inference engine system and method based on elastic batch processing and electronic equipment
CN116028167A (en) Task processing method and device, electronic equipment and storage medium
CN113138883B (en) Message processing method and device, storage medium and electronic equipment
CN116360971A (en) Processing method, device, equipment and medium based on heterogeneous computing framework
CN114741175A (en) Task execution method and device, central node and downstream node equipment
CN114138427A (en) SLO guarantee method, SLO guarantee device, node, and storage medium
CN111538717B (en) Data processing method, device, electronic equipment and computer readable 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