CN105303307B - Method and device for distributing work tasks - Google Patents

Method and device for distributing work tasks Download PDF

Info

Publication number
CN105303307B
CN105303307B CN201510674211.8A CN201510674211A CN105303307B CN 105303307 B CN105303307 B CN 105303307B CN 201510674211 A CN201510674211 A CN 201510674211A CN 105303307 B CN105303307 B CN 105303307B
Authority
CN
China
Prior art keywords
work item
work
task
item type
serial number
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.)
Active
Application number
CN201510674211.8A
Other languages
Chinese (zh)
Other versions
CN105303307A (en
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.)
Hefei Jingbei Information Technology Co.,Ltd.
Original Assignee
North Capital Infotech Share 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 North Capital Infotech Share Co Ltd filed Critical North Capital Infotech Share Co Ltd
Priority to CN201510674211.8A priority Critical patent/CN105303307B/en
Publication of CN105303307A publication Critical patent/CN105303307A/en
Application granted granted Critical
Publication of CN105303307B publication Critical patent/CN105303307B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

The embodiment of the invention discloses a method and a device for distributing work tasks, wherein a work item task queue is loaded into a two-dimensional array, one dimension of the two-dimensional array represents the type of a work item, and the other dimension represents a specific work item task queue, so that a request for processing the work task sent by a user is obtained; creating a task allocation thread for the request, abandoning locking and unlocking processing, reducing time-consuming processing such as queuing and the like, and supporting multi-path concurrent requests of work tasks sent by users; executing atomic operation through the task allocation thread, and allocating work item sequence numbers to the requests; if the assigned work item serial number exceeds the value range of the work item serial number corresponding to the work item type, returning no task, otherwise, extracting the work task according to the work item serial number and sending the work task to the user. According to the technical scheme, atomic operation is executed through the task allocation thread, and locking and unlocking operations are abandoned, so that the aim of multi-path concurrent request work tasks is fulfilled, and the system processing performance is greatly improved.

Description

Method and device for distributing work tasks
Technical Field
The embodiment of the invention relates to the technical field of information systems, in particular to a method and a device for distributing work tasks.
Background
Work items in an information system are prioritized, requiring that work items ranked ahead be processed first, and that the same work item can only be sent to one requester. When multiple persons acquire work items, the work items are required to be issued in sequence according to the arrival sequence of requesters, the first requester acquires the work item arranged at the front, the second requester acquires the 2 nd work item, and the rest of the requesters are analogized.
For the requirement, the common method is to put the work items into the memory queues in sequence, the implementation modes of the queues are various, and arrays, lists, linked lists and the like can be used; when a requester requests a task, the whole queue is locked, then the first work item is taken out, and finally the lock on the queue is released. During the process of locking the queue by one requester, other requesters can only wait. The scheme of locking the memory queue ensures that the tasks are issued in sequence, simultaneously ensures that the same work item can not be distributed to more than two requesters, and greatly improves the performance compared with the method of directly acquiring the tasks from a database or a hard disk file because the memory queue is adopted.
However, the method of locking the shared memory queue has obvious disadvantages: first, it results in resource overhead; secondly, the execution of other threads is blocked, so that other threads can only wait in the process that 1 thread occupies the lock, the blocked threads can be suspended by the system or enter a sleep state without occupying the processor, the blocked threads can not be awakened until the queue lock is acquired, a great deal of time is wasted in sleep waiting, preemption locking and awakening, and the processing speed is low, the number of supported concurrency is small, and the requirement that a great number of operating personnel concurrently acquire work items cannot be met.
Disclosure of Invention
The embodiment of the invention aims to provide a method and a device for distributing work tasks, and aims to solve the problem of how to realize efficient multithreading concurrent acquisition of work item tasks.
To achieve the purpose, the embodiment of the invention adopts the following technical scheme:
in a first aspect, a method of distributing work tasks, the method comprising:
loading a work item task queue into a two-dimensional array, wherein one dimension of the two-dimensional array represents a work item type, the other dimension represents a specific work item task queue, and a work item sequence number value range is set for each work item type;
acquiring a request for processing a work task sent by a user;
creating a task allocation thread for the request;
executing atomic operation through the task allocation thread, and allocating work item sequence numbers to the requests;
if the assigned work item serial number exceeds the value range of the work item serial number corresponding to the work item type, returning no task, otherwise, extracting the work task according to the work item serial number and sending the work task to the user.
Preferably, executing an atomic operation by the task allocation thread, and allocating a work item sequence number to the request includes:
calculating the count value of the work item sequence number device according to a set rule through the task allocation thread, and calculating a determined numerical value as an allocated work item sequence number;
and adding 1 or subtracting 1 to the count value of the work item sequence number device to obtain a numerical value as the sequence number of the distributed work items.
Preferably, before the calculating, by the task allocation thread, the count value of the work item sequencer according to a set rule and calculating a determined value as the allocated work item sequencer, the method further includes:
determining whether the request comprises a preset work item type parameter;
if the request is determined to comprise preset work item type parameters, distributing work item type serial numbers corresponding to the work item type parameters to the request through atomic operation;
if the request does not comprise the preset work item type parameter, allocating a work item type serial number to the request;
and determining a corresponding work item sequence number device according to the work item type parameters.
Preferably, the assigning a work item type number to the request includes:
executing atomic operation to add 1 or subtract 1 to the current count value of the work item type sequence number device to obtain a new count value;
if the new count value exceeds the value range of the work item type sequence number, setting the count value of the work item type sequence number device as the minimum value or the maximum value of the value range, and taking the modified value as the new count value;
the new value is used as the work item type number assigned to the request.
Preferably, the extracting the work task according to the work item sequence number and sending the work task to the user includes:
and acquiring a work task from a pre-stored two-dimensional array according to the work item type serial number and the work item serial number, wherein the row serial number of the two-dimensional array corresponds to the work item type serial number, and the column serial number corresponds to the work item serial number.
Preferably, the method further comprises:
if the assigned work item sequence number exceeds the value range of the work item sequence number corresponding to the work item type, if the task loading thread of the work item type is not started, the task loading thread of the work item type is started, otherwise, the task loading thread does not need to be started;
the task loading thread of the work item type firstly sets the value range of the work item serial number of the work item type to be empty, clears all work tasks corresponding to the work item serial number in the two-dimensional array, reloads the work tasks of the work item type into the two-dimensional array, and sets the value range of the work item serial number of the work item type to be matched with the number of the loaded work items.
In a second aspect, an apparatus for obtaining a work task, the apparatus comprising:
the loading module is used for loading the work item task queue into a two-dimensional array, wherein one dimension of the two-dimensional array represents the work item type, the other dimension represents the specific work item task queue, and a work item sequence number value range is set for each work item type;
the first acquisition module is used for acquiring a request for processing a work task sent by a user;
the creating module is used for creating a task distribution thread for the request;
the first allocation module is used for executing atomic operation through the task allocation thread and allocating work item sequence numbers to the requests;
and the sending module returns no task if the assigned work item serial number exceeds the value range of the work item serial number corresponding to the work item type, and otherwise, extracts the work task according to the work item serial number and sends the work task to the user.
Preferably, the first distribution module comprises:
the computing unit is used for computing the counting value of the work item sequence number device according to a set rule through the task allocation thread, and computing a determined numerical value as an allocated work item sequence number;
the computing unit is configured to:
and adding 1 or subtracting 1 to the count value of the work item sequence number device through the task allocation thread, and taking the determined numerical value as the allocated work item sequence number.
Preferably, the apparatus further comprises:
the first determining module is used for determining whether the request comprises preset workitem type parameters or not before the counting value of the workitem sequence number device is calculated according to a set rule through the task allocation thread and the determined numerical value is calculated as the allocated workitem sequence number;
the second allocation module is used for allocating a work item type sequence number corresponding to the work item type parameter to the request through atomic operation if the request is determined to comprise the preset work item type parameter;
the third allocation module is used for allocating a work item type sequence number to the request if the request does not comprise the preset work item type parameter;
and the second determining module is used for determining the corresponding work item sequence number device according to the work item type parameters.
Preferably, the third allocating module is configured to:
executing atomic operation to add 1 or subtract 1 to the current count value of the work item type sequence number device to obtain a new count value;
if the new count value exceeds the value range of the work item type sequence number, setting the count value of the work item type sequence number device as the minimum value or the maximum value of the value range, and taking the modified value as the new count value;
the new value is used as the work item type number assigned to the request.
Preferably, the sending module is configured to:
and acquiring a work task from a pre-stored two-dimensional array according to the work item type serial number and the work item serial number, wherein the row serial number of the two-dimensional array corresponds to the work item type serial number, and the column serial number corresponds to the work item serial number.
Preferably, the apparatus further comprises:
the starting module is used for starting the task loading thread of the work item type if the assigned work item serial number exceeds the value range of the work item serial number corresponding to the work item type, otherwise, the task loading thread does not need to be started;
and the processing module is used for the task loading thread of the work item type to set the value range of the work item serial number of the work item type to be empty, clear all work tasks corresponding to the work item type serial number in the two-dimensional array, reload the work tasks of the work item type into the two-dimensional array and set the value range of the work item serial number of the work item type to be matched with the number of the loaded work items.
The embodiment of the invention loads the work item task queue into the two-dimensional array, wherein one dimension of the two-dimensional array represents the work item type, the other dimension represents the specific work item task queue, and the value range of the work item sequence number is set for each work item type to obtain the request for processing the work task sent by the user; creating a task allocation thread for the request, abandoning locking and unlocking processing, reducing processing such as queuing and time consumption, and supporting multi-path concurrent requests of work tasks sent by users; executing atomic operation through the task allocation thread, and allocating work item sequence numbers to the requests; if the assigned work item serial number exceeds the value range of the work item serial number corresponding to the work item type, returning no task, otherwise, extracting the work task according to the work item serial number and sending the work task to the user, thereby realizing the purpose of multi-path concurrent request of the work task and greatly improving the processing performance of the system.
Drawings
FIG. 1 is a schematic flow chart diagram of a first embodiment of a method for assigning work tasks in accordance with an embodiment of the present invention;
FIG. 2 is a flowchart illustrating a second embodiment of a method for assigning work tasks according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of another method for distributing work tasks according to an embodiment of the present invention;
FIG. 4 is a functional block diagram of an apparatus for distributing work tasks in accordance with an embodiment of the present invention;
FIG. 5 is a functional block diagram of a first distribution module 504 according to an embodiment of the present invention;
FIG. 6 is a functional block diagram illustrating assignment of work tasks according to an embodiment of the present invention;
FIG. 7 is a functional block diagram illustrating assignment of work tasks according to an embodiment of the present invention.
Detailed Description
The embodiments of the present invention will be described in further detail with reference to the drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of and not restrictive on the broad invention. It should be further noted that, for convenience of description, only some structures, not all structures, relating to the embodiments of the present invention are shown in the drawings.
Example one
Referring to fig. 1, fig. 1 is a schematic flow chart of a first embodiment of a method for distributing work tasks according to an embodiment of the present invention. The scheme is suitable for the condition of distributing the work items to the users. The method may be performed by a device for distributing work tasks, which may be implemented in software and/or hardware, typically deployed in a server for distributing work items.
In one embodiment, the method for distributing the work task includes:
step 101, loading a work item task queue into a two-dimensional array, wherein one dimension of the two-dimensional array represents a work item type, the other dimension represents a specific work item task queue, and a work item sequence number value range is set for each work item type;
102, acquiring a request for processing a work task sent by a user;
103, creating a task allocation thread for the request;
specifically, when a plurality of users concurrently send requests for processing work tasks to the server, a thread is created for each request, and the requests of each user are processed respectively.
104, executing atomic operation through the task allocation thread, and allocating work item sequence numbers to the requests;
the atomic operation can ensure that all other incoming threads do not access the same resource at the same time when the multiple threads access the resource. Atomic operations are indivisible and are not interrupted by any other task or event until the execution is complete.
Preferably, the executing an atomic operation by the task allocation thread and allocating a work item sequence number to the request includes:
and calculating the count value of the work item sequence number device according to a set rule through the task allocation thread, and calculating the determined numerical value as the allocated work item sequence number.
Preferably, the calculating, by the task allocation thread, the count value of the work item sequencer according to a set rule, and the calculating the determined value as the allocated work item sequencer includes:
and adding 1 or subtracting 1 to the count value of the work item sequence number device through the task allocation thread, and taking the determined numerical value as the allocated work item sequence number.
Preferably, before the calculating, by the task allocation thread, the count value of the work item sequencer according to a set rule and calculating a determined value as the allocated work item sequencer, the method further includes:
determining whether the request comprises a preset work item type parameter;
if the request is determined to comprise preset work item type parameters, distributing work item type serial numbers corresponding to the work item type parameters to the request through atomic operation;
if the request does not comprise the preset work item type parameter, allocating a work item type serial number to the request;
and determining a corresponding work item sequence number device according to the work item type parameters.
Preferably, the assigning a work item type number to the request includes:
executing atomic operation to add 1 or subtract 1 to the current count value of the work item type sequence number device to obtain a new count value;
if the new count value exceeds the value range of the work item type sequence number, setting the count value of the work item type sequence number device as the minimum value or the maximum value of the value range, and taking the modified value as the new count value;
the new value is used as the work item type number assigned to the request.
Specifically, the different types of work item tasks refer to the work items being divided into a plurality of types, such as a number entry work item, a money entry work item, a name entry work item, and the like; different requesters may obtain different types of work items.
The thread judges the work item type parameter of the user request, if the work item type is not specified, the process is divided into two conditions:
in the first case, if it is determined that the request does not include the preset work item type parameter, allocating a sequence number of any work item type in the two-dimensional array to the request, that is, if the user does not specify any work item type parameter, a row corresponding to one work item type is arbitrarily selected from the two-dimensional array;
in the second case, if the request does not include the preset work item type parameter, the work item type serial number of the request is distributed according to the work item type serial number distributed for the last request not including the preset work item type parameter;
the allocating the serial number of the requested work item type according to the serial number of the work item type allocated to the last request which does not include the preset work item type parameter comprises the following steps:
if the serial number of the work item type allocated for the last request which does not include the preset work item type parameter is y, the serial number of the work item type allocated for the request is y + 1; or,
and if the serial number of the work item type allocated to the last request which does not include the preset work item type parameter is y, the serial number of the work item type allocated to the request is y-1, y is greater than 0, and the value of y is not greater than the total number of the work item types.
Specifically, if the last request is the m-1 th line in the two-dimensional array, the serial number of the type of the work item allocated by the current request is m; and if the last request is the m-1 th line in the two-dimensional array, the serial number of the work item type allocated to the current request is m-2.
Preferably, the allocating a work item serial number to the request according to a last work item serial number in the allocated work item type serial numbers includes:
if the last work item sequence number in the distributed work item type sequence numbers is x, the work item sequence number distributed for the request is x + 1; or,
and if the sequence number of the last work item in the assigned sequence numbers of the work item types is x, the sequence number of the work item assigned to the request is x-1, and x is not more than the total work task corresponding to the work item type.
Specifically, if the user requests a specific work type, and the row sequence number corresponding to the specific work type is 2, the row sequence number of the work task corresponding to the row sequence number is obtained, and if the row sequence number of the work task that requested the row sequence number last time is 3, the row sequence number of the work task that requested the row sequence number currently is 2 or 4.
And 105, if the assigned work item sequence number exceeds the value range of the work item sequence number corresponding to the work item type, returning to no task, otherwise, extracting the work task according to the work item sequence number and sending the work task to the user.
Preferably, the extracting the work task according to the work item sequence number and sending the work task to the user includes:
and acquiring a work task from a pre-stored two-dimensional array according to the work item type serial number and the work item serial number, wherein the row serial number of the two-dimensional array corresponds to the work item type serial number, and the column serial number corresponds to the work item serial number.
Specifically, a two-dimensional array is used for storing work tasks, for example, the form of the two-dimensional array is workItem [ m ] [ n ], wherein the first dimension m represents the serial number of work item types, and each work item type corresponds to a work item queue; the second dimension is the specific work item content under that type. A work item type sequencer typeNo is set. And a work item sequence number device itemNO is arranged in the work item queue corresponding to each work item type, and is smaller than the length of the queue. Thus, if there are m work item types, there are m itemN sequencers.
The row number and the column number of the two-dimensional array are calculated from 1. When the rows of the two-dimensional array store different working types, the serial numbers of the working types corresponding to the rows should be preset, and it is ensured that the allocated row serial numbers and column serial numbers can correspond to the rows and columns corresponding to the two-dimensional array.
The embodiment of the invention obtains the request for processing the work task sent by the user by loading the work item task queue into a two-dimensional array, wherein one dimension of the two-dimensional array represents the type of the work item, and the other dimension represents the specific work item task queue; creating a task allocation thread for the request, abandoning locking and unlocking processing, reducing processing such as queuing and time consumption, and supporting multi-path concurrent requests of work tasks sent by users; executing atomic operation through the task allocation thread, and allocating work item sequence numbers to the requests; if the assigned work item serial number exceeds the value range of the work item serial number corresponding to the work item type, returning no task, otherwise, extracting the work task according to the work item serial number and sending the work task to the user, thereby realizing the purpose of multi-path concurrent request of the work task and greatly improving the processing performance of the system.
Example two
Referring to fig. 2, fig. 2 is a flowchart illustrating a method for assigning work tasks according to a second embodiment of the present invention.
On the basis of the first embodiment, the method further comprises:
step 106, if the value range of the work item sequence number corresponding to the assigned work item type is exceeded by the assigned work item sequence number, if the task loading thread of the work item type is not started, the task loading thread of the work item type is started, otherwise, the task loading thread does not need to be started;
and 107, the task loading thread of the work item type firstly sets the value range of the work item serial number of the work item type to be empty, clears all work tasks corresponding to the work item type serial number in the two-dimensional array, reloads the work tasks of the work item type into the two-dimensional array, and sets the value range of the work item serial number of the work item type to be matched with the number of the loaded work items.
Through testing, under the condition of certain same hardware, 280 elements can be obtained from an array (or a set) per second by using a background technology; with the scheme herein, 5 ten thousand elements per second can be obtained from an array (or set).
The embodiment of the invention obtains the request for processing the work task sent by the user by loading the work item task queue into a two-dimensional array, wherein one dimension of the two-dimensional array represents the type of the work item, and the other dimension represents the specific work item task queue; creating a task allocation thread for the request, abandoning locking and unlocking processing, reducing processing such as queuing and time consumption, and supporting multi-path concurrent requests of work tasks sent by users; executing atomic operation through the task allocation thread, and allocating work item sequence numbers to the requests; if the assigned work item serial number exceeds the value range of the work item serial number corresponding to the work item type, returning no task, otherwise, extracting the work task according to the work item serial number and sending the work task to the user, thereby realizing the aim of multi-path concurrent request work task by adopting light-weight array operation and greatly improving the processing performance of the system; by effectively emptying the work item contents stored in the data group in time, the storage space of the system is improved, and the efficiency of the system for distributing work tasks is further improved.
EXAMPLE III
Referring to fig. 3, fig. 3 is a schematic diagram of another method for distributing work tasks according to an embodiment of the present invention.
Reading the work item task into a two-dimensional array workItem [ m ] [ n ] at one time, wherein m and n are natural numbers; multiple users concurrently access the system to request work item tasks.
In step 301, the system creates a thread for each request.
Step 302, the thread determines the work item type parameter requested by the user, if the work item type is not specified, then the thread is executed to execute the atomic operation to allocate the work item type for the request, the operation is the atomic operation, its function is to add 1 (or subtract 1) to the type no of the work item type sequencer (or called work item type pointer), the specific logic is: if typeNo is less than m (or greater than 0), then add 1 (or subtract 1) to typeNo, otherwise set typeNo to 0 (or m-1);
otherwise, setting typeNo as the serial number of the work item type corresponding to the specified work item type, with the numeric area of typeNo ranging from 0 to m-1, and executing step 403;
step 303, finding out a corresponding workitem sequence number device (or called a workitem pointer) itemNO according to typeNo; the thread executes the atomic operation to allocate the work item sequence number for the request, the operation is the atomic operation, the function of the operation is to add 1 (or subtract 1) to the work item sequence number unit itemsno, and the specific logic is as follows: if itemNo is less than the length of the queue (or greater than 0), then 1 is added to itemNo (or 1 is subtracted), otherwise itemNo is set to 0 (or the queue length-1).
And step 304, the thread directly obtains the work item content, namely workItem [ typeNo ] [ itemNo ], from the two-dimensional array according to the work item sequence number and the work item sequence number obtained in the step. And the cell of this work item in the array is left blank.
The method for putting the new work item into the system work item queue comprises the following steps:
the special daemon thread polls every small time period to judge whether all the workitems in the queue are acquired. If so, then the queue is emptied and filled with work item tasks from the database, and then itemNo of the queue is set to 0 (or queue length-1). Otherwise, waiting for next polling judgment.
The embodiment of the invention obtains the request for processing the work task sent by the user by loading the work item task queue into a two-dimensional array, wherein one dimension of the two-dimensional array represents the type of the work item, and the other dimension represents the specific work item task queue; creating a task allocation thread for the request, abandoning locking and unlocking processing, reducing processing such as queuing and time consumption, and supporting multi-path concurrent requests of work tasks sent by users; executing atomic operation through the task allocation thread, and allocating work item sequence numbers to the requests; if the assigned work item serial number exceeds the value range of the work item serial number corresponding to the work item type, returning no task, otherwise, extracting the work task according to the work item serial number and sending the work task to the user, thereby realizing the aim of multi-path concurrent request work task by adopting light-weight array operation and greatly improving the processing performance of the system; by effectively emptying the work item contents stored in the data group in time, the storage space of the system is improved, and the efficiency of the system for distributing work tasks is further improved.
Example four
Referring to fig. 4, fig. 4 is a functional block diagram of an apparatus for distributing work tasks according to an embodiment of the present invention.
In a fourth embodiment, the device for distributing the work task includes:
the loading module 401 is configured to load a work item task queue into a two-dimensional array, where one dimension of the two-dimensional array represents a work item type, and the other dimension represents a specific work item task queue, and a value range of a work item sequence number is set for each work item type;
a first obtaining module 402, configured to obtain a request for processing a job task sent by a user;
a creating module 403, configured to create a task allocation thread for the request;
specifically, when a plurality of users concurrently send requests for processing work tasks to the server, a thread is created for each user, and the requests of each user are processed respectively.
A first allocating module 404, configured to execute an atomic operation through the task allocation thread, and allocate a work item sequence number to the request;
the atomic operation can ensure that all other incoming threads do not access the same resource at the same time when the multiple threads access the resource. Atomic operations are indivisible and are not interrupted by any other task or event until the execution is complete.
Referring preferably to fig. 5, fig. 5 is a functional block diagram of the first assignment module 404 according to an embodiment of the present invention. The first distribution module 404 includes:
and the calculating unit 501 is configured to calculate the count value of the work item sequence number device according to a set rule through the task allocation thread, and calculate a determined numerical value as an allocated work item sequence number.
Preferably, the calculating unit 501 is configured to:
and adding 1 or subtracting 1 to the count value of the work item sequence number device through the task allocation thread, and taking the determined numerical value as the allocated work item sequence number.
Preferably, referring to fig. 6, fig. 6 is a functional module diagram of a device for distributing work tasks according to an embodiment of the present invention. The device further comprises:
a first determining module 406, configured to determine whether the request includes a preset work item type parameter before calculating a count value of a work item sequencer according to a set rule and calculating a determined value as an assigned work item sequence number through the task allocation thread;
a second allocating module 407, configured to allocate, by an atomic operation, a work item type sequence number corresponding to a preset work item type parameter to the request if it is determined that the request includes the preset work item type parameter;
a third allocating module 408, configured to allocate a work item type sequence number to the request if it is determined that the request does not include the preset work item type parameter;
preferably, the third distribution module 408 is configured to:
executing atomic operation to add 1 or subtract 1 to the current count value of the work item type sequence number device to obtain a new count value;
if the new count value exceeds the value range of the work item type sequence number, setting the count value of the work item type sequence number device as the minimum value or the maximum value of the value range, and taking the modified value as the new count value;
the new value is used as the work item type number assigned to the request.
And a second determining module 409, configured to determine a corresponding work item sequencer according to the work item type parameter.
Specifically, the different types of work item tasks refer to the work items being divided into a plurality of types, such as a number entry work item, a money entry work item, a name entry work item, and the like; different requesters may obtain different types of work items.
The thread judges the work item type parameter of the user request, if the work item type is not specified, the process is divided into two conditions:
in the first case, if it is determined that the request does not include the preset work item type parameter, allocating a sequence number of any work item type in the two-dimensional array to the request, that is, if the user does not specify any work item type parameter, a row corresponding to one work item type is arbitrarily selected from the two-dimensional array;
in the second case, if the request does not include the preset work item type parameter, the work item type serial number of the request is distributed according to the work item type serial number distributed for the last request not including the preset work item type parameter;
the allocating the serial number of the requested work item type according to the serial number of the work item type allocated to the last request which does not include the preset work item type parameter comprises the following steps:
if the serial number of the work item type allocated for the last request which does not include the preset work item type parameter is y, the serial number of the work item type allocated for the request is y + 1; or,
and if the serial number of the work item type allocated to the last request which does not include the preset work item type parameter is y, the serial number of the work item type allocated to the request is y-1, y is greater than 0, and the value of y is not greater than the total number of the work item types.
Specifically, if the last request is the m-1 th line in the two-dimensional array, the serial number of the type of the work item allocated by the current request is m; and if the last request is the m-1 th line in the two-dimensional array, the serial number of the work item type allocated to the current request is m-2.
Preferably, the allocating a work item serial number to the request according to a last work item serial number in the allocated work item type serial numbers includes:
if the last work item sequence number in the distributed work item type sequence numbers is x, the work item sequence number distributed for the request is x + 1; or,
and if the sequence number of the last work item in the assigned sequence numbers of the work item types is x, the sequence number of the work item assigned to the request is x-1, and x is not more than the total work task corresponding to the work item type.
Specifically, if the user requests a specific work type, and the row sequence number corresponding to the specific work type is 2, the row sequence number of the work task corresponding to the row sequence number is obtained, and if the row sequence number of the work task that requested the row sequence number last time is 3, the row sequence number of the work task that requested the row sequence number currently is 2 or 4.
A sending module 405, configured to return no task if the assigned work item sequence number exceeds the value range of the work item sequence number corresponding to the work item type, and otherwise, extract a work task according to the work item sequence number and send the work task to the user.
Preferably, the sending module 405 is configured to:
and acquiring a work task from a pre-stored two-dimensional array according to the work item type serial number and the work item serial number, wherein the row serial number of the two-dimensional array corresponds to the work item type serial number, and the column serial number corresponds to the work item serial number.
Specifically, a two-dimensional array is used for storing work tasks, for example, the form of the two-dimensional array is workItem [ m ] [ n ], wherein the first dimension m represents the serial number of work item types, and each work item type corresponds to a work item queue; the second dimension is the specific work item content under that type. A work item type sequencer typeNo is set. And a work item sequence number device itemNO is arranged in the work item queue corresponding to each work item type, and is smaller than the length of the queue. Thus, if there are m work item types, there are m itemN sequencers.
The row number and the column number of the two-dimensional array are calculated from 1. When the rows of the two-dimensional array store different working types, the serial numbers of the working types corresponding to the rows should be preset, and it is ensured that the allocated row serial numbers and column serial numbers can correspond to the rows and columns corresponding to the two-dimensional array.
The embodiment of the invention obtains the request for processing the work task sent by the user by loading the work item task queue into a two-dimensional array, wherein one dimension of the two-dimensional array represents the type of the work item, and the other dimension represents the specific work item task queue; creating a task allocation thread for the request, abandoning locking and unlocking processing, reducing processing such as queuing and time consumption, and supporting multi-path concurrent requests of work tasks sent by users; executing atomic operation through the task allocation thread, and allocating work item sequence numbers to the requests; if the assigned work item serial number exceeds the value range of the work item serial number corresponding to the work item type, returning no task, otherwise, extracting the work task according to the work item serial number and sending the work task to the user, thereby realizing the aim of multi-path concurrent request work task by adopting light-weight array operation and greatly improving the processing performance of the system.
EXAMPLE five
Referring to fig. 7, fig. 7 is a functional block diagram illustrating assignment of work tasks according to an embodiment of the present invention.
On the basis of the third embodiment, the apparatus further includes:
a starting module 410, configured to start a task loading thread of the work item type if the assigned work item sequence number exceeds a value range of a work item sequence number corresponding to the work item type, and otherwise, not need to start the task loading thread;
the processing module 411 is configured to set, by the task loading thread of the work item type, the value range of the work item serial number of the work item type to be empty, empty all work tasks corresponding to the work item type serial number in the two-dimensional array, reload the work tasks of the work item type into the two-dimensional array, and set the value range of the work item serial number of the work item type to match the number of the loaded work items.
Through testing, under the condition of certain same hardware, 280 elements can be obtained from an array (or a set) per second by using a background technology; with the scheme herein, 5 ten thousand elements per second can be obtained from an array (or set).
The embodiment of the invention obtains the request for processing the work task sent by the user by loading the work item task queue into a two-dimensional array, wherein one dimension of the two-dimensional array represents the type of the work item, and the other dimension represents the specific work item task queue; creating a task allocation thread for the request, abandoning locking and unlocking processing, reducing processing such as queuing and time consumption, and supporting multi-path concurrent requests of work tasks sent by users; executing atomic operation through the task allocation thread, and allocating work item sequence numbers to the requests; if the assigned work item serial number exceeds the value range of the work item serial number corresponding to the work item type, returning no task, otherwise, extracting the work task according to the work item serial number and sending the work task to the user, thereby realizing the aim of multi-path concurrent request work task by adopting light-weight array operation and greatly improving the processing performance of the system; by effectively emptying the work item contents stored in the data group in time, the storage space of the system is improved, and the efficiency of the system for distributing work tasks is further improved.
The technical principle of the embodiment of the present invention is described above in conjunction with the specific embodiments. The description is only intended to explain the principles of embodiments of the invention and should not be taken in any way as limiting the scope of the embodiments of the invention. Based on the explanations herein, those skilled in the art will be able to conceive of other embodiments of the present invention without inventive step, and these embodiments will fall within the scope of the present invention.

Claims (8)

1. A method of distributing work tasks, the method comprising:
loading a work item task queue into a two-dimensional array, wherein one dimension of the two-dimensional array represents a work item type, the other dimension represents a specific work item task queue, and a work item sequence number value range is set for each work item type;
acquiring a request for processing a work task sent by a user;
creating a task allocation thread for the request;
executing atomic operation through the task allocation thread, and allocating work item sequence numbers to the requests;
if the assigned work item serial number exceeds the value range of the work item serial number corresponding to the work item type, returning no task, otherwise, extracting the work task according to the work item serial number and sending the work task to the user;
if the assigned work item sequence number exceeds the value range of the work item sequence number corresponding to the work item type, if the task loading thread of the work item type is not started, the task loading thread of the work item type is started, otherwise, the task loading thread does not need to be started;
the task loading thread of the work item type firstly sets the value range of the work item serial number of the work item type to be empty, clears all work tasks corresponding to the work item serial number in the two-dimensional array, reloads the work tasks of the work item type into the two-dimensional array, and sets the value range of the work item serial number of the work item type to be matched with the number of the loaded work items;
executing an atomic operation by the task allocation thread, wherein allocating the work item sequence number to the request comprises:
calculating the count value of the work item sequence number device according to a set rule through the task allocation thread, and calculating a determined numerical value as an allocated work item sequence number;
and adding 1 or subtracting 1 to the count value of the work item sequence number device to obtain a numerical value as the sequence number of the distributed work items.
2. The method of claim 1, wherein before the task assigning the thread, calculating a work item sequencer count value according to a set rule, and calculating the determined value as the assigned work item sequence number, further comprises:
determining whether the request comprises a preset work item type parameter;
if the request is determined to comprise preset work item type parameters, distributing work item type serial numbers corresponding to the work item type parameters to the request through atomic operation;
if the request does not comprise the preset work item type parameter, allocating a work item type serial number to the request;
and determining a corresponding work item sequence number device according to the work item type parameters.
3. The method of claim 2, wherein assigning a work item type sequence number to the request comprises:
executing atomic operation to add 1 or subtract 1 to the current count value of the work item type sequence number device to obtain a new count value;
if the new count value exceeds the value range of the work item type sequence number, setting the count value of the work item type sequence number device as the minimum value or the maximum value of the value range, and taking the modified value as the new count value;
the new value is used as the work item type number assigned to the request.
4. The method of claim 2, wherein the extracting the work task according to the work item sequence number and sending the work task to the user comprises:
and acquiring a work task from a pre-stored two-dimensional array according to the work item type serial number and the work item serial number, wherein the row serial number of the two-dimensional array corresponds to the work item type serial number, and the column serial number corresponds to the work item serial number.
5. An apparatus for distributing work tasks, the apparatus comprising:
the loading module is used for loading the work item task queue into a two-dimensional array, wherein one dimension of the two-dimensional array represents the work item type, the other dimension represents the specific work item task queue, and a work item sequence number value range is set for each work item type;
the first acquisition module is used for acquiring a request for processing a work task sent by a user;
the creating module is used for creating a task distribution thread for the request;
the first allocation module is used for executing atomic operation through the task allocation thread and allocating work item sequence numbers to the requests;
the sending module returns no task if the assigned work item serial number exceeds the value range of the work item serial number corresponding to the work item type, and otherwise, extracts a work task according to the work item serial number and sends the work task to the user;
the starting module is used for starting the task loading thread of the work item type if the assigned work item serial number exceeds the value range of the work item serial number corresponding to the work item type, otherwise, the task loading thread does not need to be started;
the processing module is used for the task loading thread of the work item type to set the value range of the work item serial number of the work item type to be empty, clear all work tasks corresponding to the work item type serial number in the two-dimensional array, reload the work tasks of the work item type into the two-dimensional array and set the value range of the work item serial number of the work item type to be matched with the number of the loaded work items;
the first distribution module comprising:
the computing unit is used for computing the counting value of the work item sequence number device according to a set rule through the task allocation thread, and computing a determined numerical value as an allocated work item sequence number;
the computing unit is configured to:
and adding 1 or subtracting 1 to the count value of the work item sequence number device through the task allocation thread, and taking the determined numerical value as the allocated work item sequence number.
6. The apparatus of claim 5, further comprising:
the first determining module is used for determining whether the request comprises preset workitem type parameters or not before the counting value of the workitem sequence number device is calculated according to a set rule through the task allocation thread and the determined numerical value is calculated as the allocated workitem sequence number;
the second allocation module is used for allocating a work item type sequence number corresponding to the work item type parameter to the request through atomic operation if the request is determined to comprise the preset work item type parameter;
the third allocation module is used for allocating a work item type sequence number to the request if the request does not comprise the preset work item type parameter;
and the second determining module is used for determining the corresponding work item sequence number device according to the work item type parameters.
7. The apparatus of claim 6, wherein the third allocation module is configured to:
executing atomic operation to add 1 or subtract 1 to the current count value of the work item type sequence number device to obtain a new count value;
if the new count value exceeds the value range of the work item type sequence number, setting the count value of the work item type sequence number device as the minimum value or the maximum value of the value range, and taking the modified value as the new count value;
the new value is used as the work item type number assigned to the request.
8. The apparatus of claim 6, wherein the sending module is configured to:
and acquiring a work task from a pre-stored two-dimensional array according to the work item type serial number and the work item serial number, wherein the row serial number of the two-dimensional array corresponds to the work item type serial number, and the column serial number corresponds to the work item serial number.
CN201510674211.8A 2015-10-16 2015-10-16 Method and device for distributing work tasks Active CN105303307B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510674211.8A CN105303307B (en) 2015-10-16 2015-10-16 Method and device for distributing work tasks

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510674211.8A CN105303307B (en) 2015-10-16 2015-10-16 Method and device for distributing work tasks

Publications (2)

Publication Number Publication Date
CN105303307A CN105303307A (en) 2016-02-03
CN105303307B true CN105303307B (en) 2020-02-14

Family

ID=55200544

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510674211.8A Active CN105303307B (en) 2015-10-16 2015-10-16 Method and device for distributing work tasks

Country Status (1)

Country Link
CN (1) CN105303307B (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107967549B (en) * 2016-10-20 2022-02-01 南京途牛科技有限公司 Multi-process task processing device and method
CN110704112B (en) * 2019-08-30 2021-04-02 创新先进技术有限公司 Method and apparatus for concurrently executing transactions in a blockchain
CN113141235B (en) * 2020-01-20 2022-07-22 华为技术有限公司 Method and related device for processing data
CN113342871A (en) * 2021-05-17 2021-09-03 浪潮软件股份有限公司 Queue design method applied to government affair service entity hall queuing
CN114003203B (en) * 2021-09-29 2024-01-09 苏州浪潮智能科技有限公司 Maintenance method, device and equipment for activity counting variable and readable medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101504754A (en) * 2009-03-27 2009-08-12 中国工商银行股份有限公司 Banking business data sorting and processing system based on image information
CN103684874A (en) * 2013-12-31 2014-03-26 成都金铠甲科技有限公司 Method and device for automatically distributing online customer service executives to conduct customer service
CN104463482A (en) * 2014-12-16 2015-03-25 用友软件股份有限公司 Task allocation method and task allocation device
CN104835063A (en) * 2015-05-06 2015-08-12 北京京东尚科信息技术有限公司 E-commerce platform communication queuing method and system

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP3365551B2 (en) * 1999-05-20 2003-01-14 日本電気株式会社 Lot supply system and lot supply method
BR112012001629B1 (en) * 2009-07-28 2019-10-22 Ericsson Telefon Ab L M method of synchronizing event processing associated with application sessions on a telecommunications processing platform, resource adapter, and java enterprise edition teaming
US9736034B2 (en) * 2012-09-19 2017-08-15 Oracle International Corporation System and method for small batching processing of usage requests
CN102929585B (en) * 2012-09-25 2016-01-13 上海证券交易所 A kind of batch processing method and system supporting the distributed data processing of many main frames
CN103366249A (en) * 2013-07-11 2013-10-23 北京金和软件股份有限公司 Procedure batch examining and approving tool based on workflow

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101504754A (en) * 2009-03-27 2009-08-12 中国工商银行股份有限公司 Banking business data sorting and processing system based on image information
CN103684874A (en) * 2013-12-31 2014-03-26 成都金铠甲科技有限公司 Method and device for automatically distributing online customer service executives to conduct customer service
CN104463482A (en) * 2014-12-16 2015-03-25 用友软件股份有限公司 Task allocation method and task allocation device
CN104835063A (en) * 2015-05-06 2015-08-12 北京京东尚科信息技术有限公司 E-commerce platform communication queuing method and system

Also Published As

Publication number Publication date
CN105303307A (en) 2016-02-03

Similar Documents

Publication Publication Date Title
CN105303307B (en) Method and device for distributing work tasks
US10545789B2 (en) Task scheduling for highly concurrent analytical and transaction workloads
CN106547612B (en) Multitasking method and device
US7565651B1 (en) Parallel task scheduling system for computers
CN107430529B (en) Load balancing device for large-scale memory database
US9875139B2 (en) Graphics processing unit controller, host system, and methods
JP2002063148A (en) Multiple processor system
CN109086135B (en) Resource scaling method and device, computer equipment and storage medium
US20060195845A1 (en) System and method for scheduling executables
CN107704322B (en) Request distribution method and device
US9047121B2 (en) System and method for scheduling jobs in a multi-core processor
US7984439B2 (en) Efficient mechanism for preventing starvation in counting semaphores
CN103279388A (en) Systems and methods for use in performing one or more tasks
CN106528288A (en) Resource management method, device and system
CN111488206A (en) Deep learning task scheduling method, system, terminal and storage medium
Yang et al. PK-OMLP: An OMLP based k-exclusion real-time locking protocol for multi-GPU sharing under partitioned scheduling
CN108833505B (en) Data request processing method, server and storage medium
US20150212859A1 (en) Graphics processing unit controller, host system, and methods
CN107391253B (en) Method for reducing system memory allocation release conflict
Wang et al. DDS: A deadlock detection-based scheduling algorithm for workflow computations in HPC systems with storage constraints
CN111125070A (en) Data exchange method and platform
CN116260876A (en) AI application scheduling method and device based on K8s and electronic equipment
CN113806049A (en) Task queuing method and device, computer equipment and storage medium
EP3550421A1 (en) Storage controller and io request processing method
GB2504812A (en) Load balancing in a SAP (RTM) system for processors allocated to data intervals based on system load

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
CB02 Change of applicant information

Address after: 100089 Beijing, West Third Ring Road North, No. 25, green building, level 7, Haidian District

Applicant after: NORTHKING INFORMATION TECHNOLOGY CO.,LTD.

Address before: 100089 Beijing, West Third Ring Road North, No. 25, green building, room 701, Haidian District

Applicant before: Beijing Northking Information Technology Co.,Ltd.

CB02 Change of applicant information
GR01 Patent grant
GR01 Patent grant
TR01 Transfer of patent right

Effective date of registration: 20220902

Address after: 4th, 5th and 6th Floor, AB Area, Building 2, E-Commerce Park, No. 1201 Wenshui Road, Economic Development Zone, Shushan District, Hefei City, Anhui Province, 230088

Patentee after: Hefei Jingbei Information Technology Co.,Ltd.

Address before: 100089 7th floor, Qingzheng building, No.25, Xisanhuan North Road, Haidian District, Beijing

Patentee before: NORTHKING INFORMATION TECHNOLOGY CO.,LTD.

TR01 Transfer of patent right