Disclosure of Invention
In order to overcome the problems in the related art, the specification provides a method, a device and equipment for updating configuration parameters of a task executor.
According to a first aspect of the embodiments of the present specification, there is provided a method for updating configuration parameters of a task executor, where the method is used to update configuration parameters of an original task executor that currently hosts a task, and the method includes:
acquiring configuration parameters to be updated, and generating a configuration file by using the configuration parameters to be updated;
and after a target task executor is created based on the configuration file, distributing the received task to the target task executor.
Optionally, after the received task is assigned to the target task executor, the method further includes: and logging out the original task executor.
Optionally, the original task executor is logged out after all threads of the original task executor process the completed tasks, or is logged out after the target time arrives.
Optionally, the allocating the received task to the target task executor includes:
and sending the identification of the target task executor to a task scheduler, and distributing the received task to the task executor corresponding to the identification by the task scheduler.
Optionally, the task executor includes one or more of the following: a thread pool or an object pool.
According to a second aspect of embodiments herein, there is provided a task processing system including:
a dynamic configuration manager to: acquiring configuration parameters to be updated and task executor identifiers to be switched, and sending the task executor identifiers to a task scheduler;
an executor management unit to: generating a configuration file by using the configuration parameters, and creating a task executor based on the configuration file; and managing the created one or more task executors;
a task scheduler to: receiving a task to be processed; and after receiving the task executor identifier, sending the task to be processed to a task executor corresponding to the task executor identifier.
Optionally, the executor management unit is configured to: and logging out the original task executor.
Optionally, the original task executor is logged out after all threads of the original task executor process the completed tasks, or is logged out after the target time arrives.
According to a third aspect of the embodiments of the present specification, there is provided a configuration parameter updating apparatus for a task executor, configured to update configuration parameters of an original task executor currently hosting a task, the apparatus including:
an acquisition module to: acquiring configuration parameters to be updated, and generating a configuration file by using the configuration parameters to be updated;
an assignment module to: and after a target task executor is created based on the configuration file, distributing the received task to the target task executor.
Optionally, after the received task is assigned to the target task executor, the method further includes: and logging out the original task executor.
Optionally, the original task executor is logged out after all threads of the original task executor process the completed tasks, or is logged out after the target time arrives.
According to a fourth aspect of embodiments herein, there is provided a computer apparatus comprising: the system comprises a memory, a processor and a computer program stored on the memory and capable of running on the processor, wherein the processor executes the program to realize the configuration parameter updating method of the task executor.
The technical scheme provided by the embodiment of the specification can have the following beneficial effects:
in this embodiment, if a need for updating the configuration parameters of the task executor is encountered, a new configuration parameter may be obtained, the new configuration parameter is used to generate a new configuration file, a new task executor may be created based on the configuration file, which is referred to as a target task executor in this embodiment, then the target task executor replaces an original task executor, and a newly received task may be allocated to the target task executor for processing, so as to achieve the purpose of updating the configuration parameters of the task executor. The embodiment can not interrupt the original task processing work, thereby supporting the dynamic configuration of the thread pool parameters, and when the traffic volume changes, the configuration parameters can be adjusted at any time, thereby being capable of meeting various service requirements.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the specification.
Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present specification. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the specification, as detailed in the appended claims.
The terminology used in the description herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the description. As used in this specification and the appended claims, the singular forms "a", "an", and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should also be understood that the term "and/or" as used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items.
It should be understood that although the terms first, second, third, etc. may be used herein to describe various information, these information should not be limited to these terms. These terms are only used to distinguish one type of information from another. For example, the first information may also be referred to as second information, and similarly, the second information may also be referred to as first information, without departing from the scope of the present specification. The word "if" as used herein may be interpreted as "at … …" or "when … …" or "in response to a determination", depending on the context.
With the continuous development of internet technology, the requirements for the processing capability of devices such as terminals or servers are higher and higher. For example, at some point, a device may receive multiple tasks, and how to handle these tasks becomes a concern to technicians.
Optionally, the apparatus may adopt a multi-thread processing form, as shown in fig. 1, which is a multi-thread processing schematic diagram according to an exemplary embodiment shown in this specification, and involves a thread pool and a task scheduler; the treatment process comprises the following steps: creating a thread pool based on a configuration file, wherein configuration parameters of the thread pool, such as the number of core threads, the maximum number of concurrent threads or the idle time of threads, are written in the file; the task scheduler adds the tasks to be processed to the task queue; after finding that the task waiting for processing in the task queue arrives, the thread pool can create threads to execute the task, and one thread processes one task.
And after the thread pool is established, the set configuration parameters are kept unchanged. For example, after the thread pool is created, the number of threads may be controlled by setting the maximum number of concurrent threads, for example, if the maximum number of concurrent threads of a thread pool is set to 5, then a maximum of 5 threads may be created in the thread pool to process tasks. However, since the number of the to-be-processed tasks in the task queue is variable and the maximum number of the concurrent threads is fixed, the number of the to-be-processed tasks in the task queue may be too large, and particularly in a high-concurrency scenario, a situation that the to-be-processed tasks cannot be executed in time often occurs.
In practical application, with the development of services, the requirement for updating the configuration parameters of the thread pool may be met; for example, due to upgrading of hardware functions of the device or increase of service requests, the maximum number of concurrent threads of the thread pool needs to be enlarged. At this time, the task processing is interrupted because the work of the thread pool needs to be terminated, and then the configuration file of the thread pool is modified, and the thread pool is re-created according to the new configuration file, so that the maximum concurrent thread number of the thread pool is increased.
Similar to thread pools, task executors such as object pools also have a need for configuration parameter updates. The thread pool can be used for processing various tasks, and the object pool can be used for managing task objects such as index files, webpage content resources and the like. Based on this, an embodiment of the present specification provides a configuration parameter updating scheme for a task executor, and an application scenario of the configuration parameter updating method for a task executor in the embodiment of the present specification is illustrated first, as shown in fig. 2A, fig. 2A relates to a plurality of terminal devices, a network, and a plurality of servers (which may also be a server cluster, a cloud server, and the like). The network serves as a medium for providing a communication link between the terminal device and the server. The network may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
A user may use a terminal device to interact with a server over a network to receive or transmit data, etc. Various applications can be installed on the terminal device, such as a social application, a web browser application, a search engine application, a shopping application, an instant messaging application, a mobile phone assistant application, and the like.
The terminal device may be a variety of electronic devices including, but not limited to, smart phones, tablet computers, electronic book readers, multimedia players, laptop portable computers, desktop computers, and the like.
The server may be a server providing various services, such as a background server providing support for applications installed on the terminal device. The background server can receive the request of the terminal equipment, process data according to the request and feed back the processing result to the terminal equipment.
The method for updating the configuration parameters of the task executor in the embodiment of the present description may be executed by the server or the terminal device, and accordingly, the apparatus for updating the configuration parameters of the task executor may be disposed in the server 1 or the terminal device. It should be understood that the number of terminal devices, networks, and servers in fig. 2A are merely illustrative. There may be any number of terminal devices, networks, and servers, as desired.
In this embodiment, a task executor currently accepting a task is referred to as an original task executor, and if a configuration parameter of the original task executor needs to be updated, a device may apply a method for updating a configuration parameter of a task executor as shown in fig. 2B, where the method includes the following steps:
in step 202, the configuration parameters of the actuator to be updated are obtained, and a configuration file is generated by using the configuration parameters of the actuator.
In step 204, after creating the target task executor based on the configuration file, the received task is switched from being allocated to the original task executor to being allocated to the target task executor.
In this embodiment, if a need for updating the configuration parameters of the task executor is met, a new configuration parameter may be obtained, the new configuration parameter is used to generate a new configuration file, a new task executor may be created based on the new configuration file, which is called as a target task executor, and then the target task executor replaces an original task executor to support a task, and a newly received task may be allocated to the target task executor to be processed, so as to achieve the purpose of updating the configuration parameters of the task executor. The embodiment can not interrupt the original task processing work, so that the dynamic configuration parameters can be supported, and when the traffic volume changes, the configuration parameters can be adjusted at any time, thereby meeting various service requirements.
After the target task executor is created, two task executors are involved in the embodiment: optionally, the original task executor and the target task executor may have unique identifiers, and the identifiers may uniquely distinguish the original task executor from the target task executor by using a name, a pointer address, and the like. In some examples, a task scheduler is used to take over tasks and distribute the received tasks to task executors; the task scheduler needs to obtain an identification of the task executor so that the task scheduler can know to which task executor the task should be allocated. Thus, the switching the assignment of the received task from the assignment to the original task executor to the target thread pool may include:
and sending the identification of the target task executor to a task scheduler, and informing the task scheduler to switch and allocate the received task from the original task executor to the target task executor.
The target task executor replaces an original task executor, updating of configuration parameters of the task executor is achieved, the original task executor does not need to take over a new task, and in order to release resources occupied by the original task executor, the original task executor can be cancelled after a received task is distributed to the task executor.
The logout time can be flexibly configured according to needs, and in some examples, the logout can be directly performed after the target task executor accepts the tasks; in some examples, since the original task executor has accepted some tasks for processing, if direct logout would cause the tasks to fail to be processed, logout may be performed after processing has completed all accepted tasks. In other examples, the original task executor may take a long time to process the accepted tasks, and considering that the original task executor may occupy a large amount of resources, it may also set a target time, and after the target time is reached, the original task executor is logged off to release the resources regardless of whether all tasks in the original task executor are completed. The target time can be flexibly determined according to actual needs.
The above method for updating configuration parameters of a task executor may be applied to a task processing scenario, as shown in fig. 3, which is an architectural diagram of a task processing system according to an exemplary embodiment shown in this specification, and includes:
a dynamic configuration manager 31 for: the method comprises the steps of obtaining configuration parameters to be updated, obtaining task executor identifiers to be switched, and sending the task executor identifiers to a task scheduler.
An executor management unit 32 to: generating a configuration file by using the configuration parameters, and creating a task executor based on the configuration file; and managing the created one or more task executors.
A task scheduler 33 for: receiving a task to be processed; and after receiving the task executor identifier, sending the task to be processed to a task executor corresponding to the task executor identifier.
In the task management system of this embodiment, the executor management unit may manage at least one task executor, where the task executor is configured to process a task; the creation process of the task executor may be that a configuration file is generated by using the configuration parameters, and the task executor is created based on the configuration file. As business evolves, a need to update configuration parameters of task performers may be faced. In the embodiment, the configuration parameters are updated by newly building another task executor to replace the existing task executor.
The embodiment provides a dynamic configuration manager, which can be used for acquiring configuration parameters to be updated; the configuration parameters to be updated may be configured by a technician, or may be automatically obtained by a dynamic configuration manager according to a set policy. After acquiring the new configuration parameters, the executor management unit may generate a new configuration file by using the configuration parameters to be updated, and create a new task executor based on the configuration file. Under the condition that one or more task executors exist, a task scheduler needs to send the task to be processed to the task executor corresponding to the task executor identifier according to the task executor identifier. Based on the above framework, after a new task executor is created, the task scheduler can be notified of the identifier of the new task executor, the task to be processed is sent to the newly created task executor through the task scheduler, and the old task executor does not carry the task any more, thereby realizing the update of the configuration parameters.
In this embodiment, the task executor that accepts the task before the dynamic configuration manager receives the task executor identifier is an original task executor, and the executor management unit is configured to: and after the dynamic configuration manager receives the task executor identifier, canceling the original task executor so as to release the resources occupied by the original thread pool.
Optionally, the executor management unit is configured to: and logging out the original task executor after the original task executor processes the completed task, or logging out the original task executor after the target time is reached. In some examples, since the original task executor has accepted some tasks for processing, if direct logout would cause the tasks to fail to be processed, logout may be performed after processing has completed all accepted tasks. In other examples, the original task executor may take a long time to process the accepted tasks, and considering that the original task executor may occupy a large amount of resources, it may also set a target time, and after the target time is reached, the original task executor is logged off to release the resources regardless of whether all tasks in the original task executor are completed.
Corresponding to the foregoing embodiments of the method for updating configuration parameters of a task executor, the present specification further provides embodiments of a device for updating configuration parameters of a task executor and a computer device to which the device is applied.
The embodiment of the configuration parameter updating device of the task executor in the specification can be applied to computer equipment, such as a server or terminal equipment. The device embodiments may be implemented by software, or by hardware, or by a combination of hardware and software. The software implementation is taken as an example, and as a logical device, the device is formed by reading corresponding computer program instructions in the nonvolatile memory into the memory for operation through the processor in which the file processing is located. From a hardware aspect, as shown in fig. 4, it is a hardware structure diagram of a computer device where a configuration parameter updating apparatus of a task executor in this description is located, except for the processor 410, the memory 430, the network interface 420, and the nonvolatile memory 440 shown in fig. 4, a server or an electronic device where the apparatus 431 is located in this embodiment may also include other hardware according to an actual function of the computer device, which is not described again.
As shown in fig. 5, fig. 5 is a block diagram of a configuration parameter updating apparatus for a task executor according to an exemplary embodiment, for updating a configuration parameter of an original task executor of a currently hosted task, the apparatus including:
an obtaining module 51, configured to: acquiring configuration parameters to be updated, and generating a configuration file by using the configuration parameters to be updated;
an assignment module 52 to: and after a target task executor is created based on the configuration file, distributing the received task to the target task executor.
Optionally, after the received task is assigned to the target task executor, the method further includes: and logging out the original task executor.
Optionally, the original task executor is logged out after all threads of the original task executor process the completed tasks, or is logged out after the target time arrives.
Optionally, the allocating module is further configured to:
and sending the identification of the target task executor to a task scheduler, and distributing the received task to the task executor corresponding to the identification by the task scheduler.
Optionally, the task executor includes one or more of the following: a thread pool, an object pool, or a resource pool.
The implementation process of the function and the action of each module in the configuration parameter updating apparatus of the task executor is specifically described in the implementation process of the corresponding step in the configuration parameter updating method of the task executor, and is not described herein again.
For the device embodiments, since they substantially correspond to the method embodiments, reference may be made to the partial description of the method embodiments for relevant points. The above-described embodiments of the apparatus are merely illustrative, wherein the modules described as separate parts may or may not be physically separate, and the parts displayed as modules may or may not be physical modules, may be located in one place, or may be distributed on a plurality of network modules. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution in the specification. One of ordinary skill in the art can understand and implement it without inventive effort.
The foregoing description has been directed to specific embodiments of this disclosure. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims may 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.
Other embodiments of the present description will be apparent to those skilled in the art from consideration of the specification and practice of the invention disclosed herein. This specification is intended to cover any variations, uses, or adaptations of the specification following, in general, the principles of the specification and including such departures from the present disclosure as come within known or customary practice within the art to which the specification pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the specification being indicated by the following claims.
It will be understood that the present description is not limited to the precise arrangements described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present description is limited only by the appended claims.
The above description is only a preferred embodiment of the present disclosure, and should not be taken as limiting the present disclosure, and any modifications, equivalents, improvements, etc. made within the spirit and principle of the present disclosure should be included in the scope of the present disclosure.