当前位置:网站首页>Chapter 20 using work queue manager (3)

Chapter 20 using work queue manager (3)

2022-07-07 20:05:00 yaoxin521123

Chapter 20 Use the work queue manager ( 3、 ... and )

Manage categories

A category is an independent worker jobs pool . When initializing a group worker jobs when , You can specify to provide worker Categories . If any in the set worker jobs In execution work Request additional worker jobs, It's new worker jobs From the same category .

for example , Suppose the system provides SQL The category is assigned the most 8 individual worker. then , Hypothesis and BusinessIntelligence Related processes create a category , And a maximum of four worker Assign to this category . If SQL All in the pool worker Participated in the work at a given time , be BusinessIntelligence In category worker Work items may still be processed immediately .

The system includes two categories that cannot be deleted :SQL and Default. SQL The category applies to any SQL Handle , Including parallel processing of queries . When initializing a group without specifying a category worker jobs when , Default category withdrawal worker jobs.

Each category has attributes that affect the behavior of each work queue in that category . These properties are :

DefaultWorkers

When a work queue in this category is created and is not specified worker job When counting , This will become a work queue worker job The number of . The default value of this attribute is the number of cores .

MaxActiveWorkers

In this category job Activities reserved in the service request pool worker job Maximum number of . Idle detected job And automatically start a new job To maximize activity job Keep the number near this limit . The default value is twice the number of cores .

MaxWorkers

The largest number of work queues in this category worker job Count . If more... Are specified when creating the work queue worker job, Then use this limitation . The default value is twice the number of cores .

To create a category 、 Adjust category properties and delete custom categories , Please navigate to System Administration > Configuration > System Configuration > WQM Categories.. The name of the custom category is case sensitive , May contain letters 、 Numbers 、 Underline 、 Dashes and periods .

Use callback

Callback is the code that the work queue manager must execute after completing the work item . Callbacks can be used for two reasons :

  • Perform work that depends on work items
  • If you choose to complete work items asynchronously , It means that all the queued work has been completed

Including callback of work item

To add a callback , Call when you add a work item to the work queue QueueCallback() Method, not Queue() Method :

method QueueCallback(work As %String, callback As %String, args... As %String) as %Status

work and args Methods and Queue() In the same way . however , Callback parameters use the following syntax to specify the callback code to execute :

  • ##class(Classname).ClassMethod For class methods
  • $$entry^rtn For subroutines

Class methods or subroutines must accept the same parameters as the main work item in the same order . The main process passes the same parameters to the main work item and callback code .

The callback code can access the following public variables :

  • %job, Jobs that contain processes that actually complete the work ID
  • %status, It contains %Status value
  • %workqueue, That is, of the work queue instance OREF

These public variables are available in callbacks , But not available in work items .

Include callbacks to confirm completion

You can poll the work queue manager to determine completion , Instead of using WaitForComplete() Method waits for all queued work in the work queue to complete before returning to the main process , As shown below :

  • As mentioned in the previous section , Use QueueCallback() Method, not Queue() Method to add a work item to the work queue .
  • When all work items are completed , In the callback code, the public variable %exit Set to 1.
  • Use Wait() Method, not WaitForComplete() Method :
method Wait(qspec As %String, byRef AtEnd As %Boolean) as %Status

Wait() Method waits for the signal from the callback to return to the caller . say concretely , It waits for the callback code to put the public variable %exit Set equal to 1.Wait() Returns... By reference AtEnd. AtEnd by 1 when , All the work has been done . perhaps , If AtEnd by 0, Then one or more work items are not completed .

Control the output of the current device

By default , If the work item generates output to the current device (WRITE sentence ), The work queue saves the output in a buffer , until WaitForComplete() or Wait() end . If you want the work item to generate output earlier , Please let this work item call %SYSTEM.Context.WorkMgr Class Flush() Class method , for example :

set sc = $system.Context.WorkMgr().Flush()

When a work item calls this method , Will cause the parent work queue to write all saved outputs of the work item .

Besides , have access to -d Flag to disable all outputs to the current device . under these circumstances ,Flush() Methods do nothing , Because there is no output .

Pause and resume work queues

%SYSTEM.WorkMgr Class provides methods that can be used to pause and resume work in a work queue :

Pause()

method Pause(timeout As %Integer, ByRef completed As %Boolean = 0) as %Status

Block... Associated with this work queue worker jobs Accept other items from this work queue . Pause() Method also stops any work items in progress .

timeout The parameter represents the amount of time the method waits before stopping the work item in progress ( In seconds ). After the timeout , This method returns the completion value , This value indicates that Pause() Whether the work item in progress at the time of method has been completed . therefore , You can pass in the timeout value 0 To know immediately worker jobs Whether all work items in the work queue have been completed .

Resume()

method Resume() as %Status

If used before Pause() Method pause , Then resume the work in this work queue . say concretely , This method enables the work queue process to accept and start any other items in the work queue .

原网站

版权声明
本文为[yaoxin521123]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071755496071.html

随机推荐