Skip to content

Make it possible to keep workflows in worker cache also if they're only queried #1716

Open
@recht

Description

@recht

Is your feature request related to a problem? Please describe.

Currently, when sending a query to a workflow that is in running state but not active on any worker, a worker will receive the request, replay history, process the query, and forget everything again. On next query the same thing happens. This is in contrast to starting the workflow from scratch without restarting the worker. Then the workflow is in the worker cache, ready to serve queries. Same if the worker has restarted, but workflow state has changed so that the workflow got loaded into the cache.

Because replays can get a bit expensive, especially if encryption/offloading codecs are used (which we do), it would be nice if querying a workflow would add it to the worker sticky cache.

Describe the solution you'd like
A config property that allows us to specify that workflows that are queried should also be inserted into the cache.

While debugging locally I did this:

diff --git a/internal/internal_task_handlers.go b/internal/internal_task_handlers.go
index 8312587..342f7f4 100644
--- a/internal/internal_task_handlers.go
+++ b/internal/internal_task_handlers.go
@@ -812,7 +812,7 @@ func (wth *workflowTaskHandlerImpl) GetOrCreateWorkflowContext(
                        return
                }
 
-               if wth.cache.MaxWorkflowCacheSize() > 0 && task.Query == nil {
+               if wth.cache.MaxWorkflowCacheSize() > 0 {
                        workflowContext, _ = wth.cache.putWorkflowContext(runID, workflowContext)
                        workflowContext.Lock()
                        workflowContext.cached = true

It's unclear if that's the right solution or if that has other unintended consequences, but at least it keeps the workflow in the sticky worker cache, making queries much faster.

Describe alternatives you've considered
Doing less queries, or faster codecs. Regardless, it seems wasteful to have to replay on every single query.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions