当前位置:网站首页>Chapter 19 using work queue manager (2)
Chapter 19 using work queue manager (2)
2022-07-06 22:36:00 【yaoxin521123】
List of articles
Chapter 19 Use the work queue manager ( Two )
Basic workflow
You can use the work queue manager by performing the following steps :
- take
ObjectScript
The code is divided into work units , These units of work are class methods or subroutines that meet specific requirements . - Create a work queue , It is
%SYSTEM.WorkMgr
An instance of a class . So , Please call%SYSTEM.WorkMgr
Class%New()
Method . This method returns a work queue .
You can specify the parallelism to use worker jobs The number of , You can also use the default value , It depends on the machine and the operating system . Besides , If you have created a category , You can specify from which job Categories .
When creating a work queue , The work queue manager creates the following artifacts :
- Global variables that contain information about work queues , For example, in which namespace does the work queue run
- The location and event queue of the serialized unit of work that the work queue must handle
- The location and event queue of the completion event created when the work queue finishes processing the unit of work
- Add work unit ( Also known as work items ) Add to work queue . So , You can call
Queue()
orQueueCallback()
Method . As a parameter , Pass class methods ( Or subroutine ) Name of and any corresponding parameters .
Start processing immediately for items added to the queue .
If there are more items in the queue than are available in the queue worker jobs, be job Will compete to clear the queue . for example , If there is 100
Projects and four job, Then each job Remove an item from the head of the queue , Deal with it , Then return to the head of the queue to remove and process another item . This mode continues until the queue is empty .
The work queue manager uses the caller's security context when running work items .
When queuing work items , The work queue manager performs the following tasks :
- Serialize the parameters that make up the unit of work 、 Security context and class methods or subroutines , The serialized data is then inserted into the global... That lists the units of work associated with the work queue global in
- Signal events on the work queue
- If additional worker jobs And it can be used to deal with work units , Lead to worker jobs Attach to the work queue and reduce worker jobs The number of
- Wait for the work to be completed . So , Work queue can be called
WaitForComplete()
Method .
The work queue manager then performs the following tasks :
- Wait for the completion event
- Display workload indicators and other outputs to the terminal
- Collect any errors related to the unit of work
- If you use
QueueCallback()
Method to add a unit of work to a work queue , Then run the callback code
- Continue processing according to the application .
The following example shows these basic steps :
ClassMethod WorkJob(){
s queue = ##class(%SYSTEM.WorkMgr).%New()
for i = 1 : 1 : filelist.Count() {
s sc = queue.Queue("..Load", filelist.GetAt(i))
if $$$ISERR(sc) {
ret sc
}
}
s sc = queue.WaitForComplete()
if $$$ISERR(sc) {
ret sc
}
}
This code initializes the work queue manager , Then traverse the file list . For each file , The code adds a work queue item that loads the file . After adding all work queue items , The code waits for the work to finish .
Be careful : %SYSTEM.WorkMgr
Class supports more complex workflows and methods described later in this document .
The basic method
To complete the steps described in the previous section , have access to %SYSTEM.WorkMgr
Class :
%New()
classmethod %New(qspec As %String = "", numberjobs As %Integer, category) as WorkMgr
establish 、 Initialize and return a work queue , It can be used to perform parallel processing %SYSTEM.WorkMgr
An instance of a class . The method takes the following parameters :
qspec
- A string of compiler flags and qualifiers that affect code running in this work queue .numberjobs
- Maximum parallelism used in this work queue worker jobs Count . The default value depends on the characteristics of the machine and the operating system .category
- Provide the worker jobs The name of the category .
The system will not assign any work tasks to the queue when it is created . Only after adding the unit of work to the work queue , Will assign staff jobs .
Queue()
method Queue(work As %String, args... As %String) as %Status
Add units of work to the work queue . The method takes the following parameters :
work
Code to execute . Usually , The code should return a %Status
Value to indicate success or failure .
If the code returns %Status
value , The following syntax can be used :
##class(Classname).ClassMethod
For class methods , amongClassname
Is the fully qualified name of the class ,ClassMethod
Is the name of the method . If the method is in the same class , You can use grammar..ClassMethod
, As shown in the example .$$entry^rtn
For subroutines , amongentry
Is the name of the subroutine ,rtn
Is the name of the routine .
If the code does not return %Status
value , Please use the following syntax instead :
=##class(Classname).ClassMethod
For class methods ( or=..ClassMethod
If the method is in the same class )entry^rtn
Subroutinesargs
A comma separated list of parameters of a class method or subroutine . To pass a multidimensional array as a parameter , Please add a period before this parameter as usual , In order to pass .
The size of the data passed in these parameters should be relatively small , To take full advantage of the framework . To convey a lot of information , Please use global instead of parameters .
When queuing work units , The system will assign one working program job at a time , Up to... Specified when creating a work queue numberjobs
Value or default value at most . Besides , The security context of the caller is recorded , Each work item runs in this security context .
WaitForComplete()
method WaitForComplete(qspec As %String, errorlog As %String) as %Status
Wait for the work queue to complete all projects , And then return a %Status
Value to indicate success or failure . %Status
The value contains all returned from the work item %Status
Value information . The method takes the following parameters :
qspec
- A string of compiler flags and qualifiers .errorlog
- String of any error messages , Return as output .
Properties of the work queue
Each work queue ( or %SYSTEM.WorkMgr
Example ) All have the following properties :
NumWorkers
Assigned to the work queue worker jobs Count .
NumActiveWorkers
Currently active worker The number of .
Besides , The properties of the category to which the work queue belongs determine the behavior of the work queue .
边栏推荐
- qt quick项目offscreen模式下崩溃的问题处理
- return 关键字
- Puppeter connects to the existing Chrome browser
- What are the specific steps and schedule of IELTS speaking?
- Inno setup packaging and signing Guide
- How to confirm the storage mode of the current system by program?
- UVa 11732 – strcmp() Anyone?
- 【雅思口语】安娜口语学习记录part1
- 做接口测试都测什么?有哪些通用测试点?
- volatile关键字
猜你喜欢
随机推荐
sizeof关键字
Aardio - integrate variable values into a string of text through variable names
How to confirm the storage mode of the current system by program?
[IELTS speaking] Anna's oral learning record part1
使用云服务器搭建代理
Sword finger offer question brushing record 1
【雅思口语】安娜口语学习记录part1
(18) LCD1602 experiment
MySQL----初识MySQL
Jafka来源分析——Processor
Unity3d minigame-unity-webgl-transform插件转换微信小游戏报错To use dlopen, you need to use Emscripten‘s...问题
The SQL response is slow. What are your troubleshooting ideas?
BasicVSR_PlusPlus-master测试视频、图片
【编译原理】做了一半的LR(0)分析器
Adavit -- dynamic network with adaptive selection of computing structure
Lora sync word settings
UDP编程
重磅新闻 | Softing FG-200获得中国3C防爆认证 为客户现场测试提供安全保障
UVa 11732 – strcmp() Anyone?
2022-07-05 stonedb sub query processing parsing time analysis