Is there any way in temporal to resequence the messages to process them as a group identified by a functional key in the message?
Here is the proposed approach.
Have a single workflow per unique functional key which receives a message (possibly with SignalWithStart) and queues, workflow will complete processing everything in the queue and go to wait state and wait for more messages to process.
The actual processing is implemented as a child workflow or directly as part of the parent workflow.
Once after I finish processing all the events in the queue,
I am moving the workflow to await state until it receive a new request using getEntry-Signal.
Any new entry will be processed by coming out from the wait state. Once after processing all the events in the WorkflowQueue, the workflow will await for new requests to be added to the queue.
When I checked the logs, I see that the workflow thread ID is same, every time a new request come and the workflow start running.
Does it mean that this thread is not release when it go to await state?
We are planning to run a million instances of such workflows (not always active) and would like to understand the performance and memory impact.
WorkflowQueue.take blocks until a message is available.
To support graceful cancellation consider using WorkflowQueue.cancellableTake.
Don’t use the offer without checking the result as this is going to lose a message if the queue is full.
I would use an unbounded queue and deal with the message shedding in the consumer code if necessary.
Running such workflow infinitely is going to grow its history to an unbounded size. To keep the history size bounded the workflow has to call continue as new periodically.
To not lose messages when calling continue as new the buffered messages have to be passed from one run to another as a workflow argument.
Hi regarding the original question does the await() blocks the thread ? Or it’s suspends the flow and later recover it from the the event source ?
We plan to use it as a batch aggregator, a signal will add to the batch and as soon the batch will meet size or time window requirements the messages will be processed by a child flow.
The question, is it better to use await or the timer sleep call, in order not to block the executing thread and cause performance degradation. Please advise ?
Hi regarding the original question does the await() blocks the thread ? Or it’s suspends the flow and later recover it from the the event source ?
It suspends the workflow execution and later recovers it. So a workflow that is blocked for a long time doesn’t consume resources on the worker.
We plan to use it as a batch aggregator, a signal will add to the batch and as soon the batch will meet size or time window requirements the messages will be processed by a child flow.
Keep in mind that a single workflow instance cannot grow very large or process a large update rate. What is the batch size and number of signals per second processed by a single workflow execution (instance)?