Simple WorkMgr example

Attached code contains a very basic $system.WorkMgr example.

It uses several jobs (workers) to update different chunks of rows of a table.

Steps:

  • Creates a table with 100 records.
  • Split table  in chunks 
  • Initialize WorkMgr and queue chunks to workers.
    • Every worker simply sets its process number in the Job field of the processed row. 

In this case, I have tested the example in a 8-core laptop:

USER>do ##class(IAT.S04.WorkMgr.Simple).%DeleteExtent()
USER>do ##class(IAT.S04.WorkMgr.Simple).Populate(100)
USER>do ##class(IAT.S04.WorkMgr.Simple).UpdateWorkMgr()
**Split
pChunks=8
returnCode=1
chunks=$lb("12","24","36","49","62","75","88")
^Samples.Log=8
^Samples.Log(1)="UpdateOneChunk [11224] (12,24)"
^Samples.Log(2)="UpdateOneChunk [13404] (,12)"
^Samples.Log(3)="UpdateOneChunk [15752] (24,36)"
^Samples.Log(4)="UpdateOneChunk [3352] (36,49)"
^Samples.Log(5)="UpdateOneChunk [6664] (49,62)"
^Samples.Log(6)="UpdateOneChunk [15892] (62,75)"
^Samples.Log(7)="UpdateOneChunk [19872] (75,88)"
^Samples.Log(8)="UpdateOneChunk [13896] (88,)"

After running the test, we can have a look at the Job field in the table:

Comments