Hi,
As per link - How to develop a Worker Program in Java | Temporal Documentation , need a clarification on creation of worker threads as below :
- Is it required to explicitly call newWorker() in a loop, if we need to create multiple worker threads on the same queue?
- Also, can someone please detail on the parameter Max Workflow/Activity Execution Size while building WorkerOptions? Default value of these params is 200, does it mean that Temporal Java SDK manages and creates those many number of threads to process workflow/activity tasks?
Please guide on the same.
- Is it required to explicitly call newWorker() in a loop, if we need to create multiple worker threads on the same queue?
WorkerFactory.newWorker(tq)
creates a new worker, yes. I guess you can create them inside a loop if you wanted. You cannot create new workers after you call WorkerFactory.start()
.
Typically you would have a single worker for a tq per process and multiple worker processes for scalability.
please detail on the parameter Max Workflow/Activity Execution Size
- maxConcurrentActivityExecutionSize - worker specific limit on number of parallel activities
- maxConcurrentWorkflowTaskExecutionSize - max number of simultaneously executed workflow tasks
There is more info on these in worker tuning guide
@tihomir Followup question on the same : If I need to have 10 worker threads on a taskQueue, then do I need to call newWorker() for 10 times in a loop. Is this the appropriate way when you mention about scaling worker processes?
Also, regarding execution size parameters, does Temporal SDK handle the logic to create those many threads based on tasks received after polling?
A single worker can execute a large number of parallel workflow executions.
WorkerFactoryOptions.maxWorkflowThreadCount
defines max number of threads are available for workflow exec across all workers created from this factory (includes cached workflows). Default is 600.
If you want to create ten workers, then yes you would need to create via WorkflowFactory->newWorker.
A single worker can also support many parallel activities which are internally executed by a thread pool that has its max size set to maxConcurrentActivityExecutionSize.
1 Like
Thanks for all the clarification!