Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize Workflow Execution and Messaging #5243

Merged
merged 19 commits into from
Apr 18, 2024
Merged

Conversation

sfmskywalker
Copy link
Member

This PR introduces several optimizations and improvements to enhance the performance and reliability of Elsa Workflows:

  • Optimized Workflow Dispatching: Modifies the workflow inbox service to first identify all relevant workflow instances before dispatching execution requests. This change ensures that "dispatch workflow" messages are only sent when applicable, significantly reducing unnecessary message traffic.

  • Enhanced Message Handling: Ensures workflow inputs are stored with the workflow instance prior to dispatching messages to the queue. This approach prevents potential message rejection due to input mismatches at the service bus level.

  • Robust JSON Serialization: Improves the custom JSON serializer to handle TargetTypeExceptions more effectively. This enhancement prevents errors during deserialization when the target type is not suitable.

  • Streamlined Application Startup: Reduces redundancy in the workflow startup process by indexing workflow triggers only once after all workflows are populated, thereby improving the startup time.

These changes aim to streamline workflow processing, reduce overhead, and improve overall system stability.

Fixes #5241

The trigger indexing in the workflow populator is now conditional. A boolean parameter has been added to the PopulateStoreAsync and AddAsync methods to determine whether to index triggers or not. Additionally, some code cleanups and refactoring have been made for efficient and cleaner code.
The method `AddAsync` in `DefaultWorkflowRegistry` has been updated to include a new first parameter set to true. This change aligns with recent modifications to the `AddAsync` method signature, ensuring proper function execution.
The updated GitHub workflow now includes triggers for branches with 'feat/*', 'enh/*', 'perf/*', 'hotfix/*', and 'chore/*' prefixes. This is to ensure that the workflow runs not only for the main, feature, issue, bug, enhancement, patch, and fix branches, but also on all new branches, improving coverage and visibility on all changes.
This commit introduces a new method, FindByIdAsync, to the WorkflowInstanceManager service. This method fetches a WorkflowInstance using its Id. Also, an interface declaration for the new method is added to IWorkflowInstanceManager.
The code for creating workflow definition filters has been refactored for brevity. Additionally, two sets of overloaded methods named `PopulateStoreAsync` and `AddAsync` were added to "IWorkflowDefinitionStorePopulator" and implemented in "DefaultWorkflowDefinitionStorePopulator". These methods allow specifying whether triggers should be indexed.
The refactoring is focused on an improved way of finding and passing ActivityDescriptor within WorkflowDefinitionActivity class. Previously, the service provider was passed to the DeclareInputAsVariables and DeclareOutputAsVariables methods, leading to a less readable and harder to maintain code. Now, we pass the ActivityDescriptor directly, making the code easier to understand and modify.
Fixes have been applied to the PolymorphicObjectConverter by adding the handling of TargetException. Additionally, the System.Reflection namespace has been included, and the addSetMethod invocation for the HashSet has been streamlined for better readability and performance.
This change simply removes an unneeded line of whitespace in the corresponding Middleware file. This change is consistent with the goal of maintaining clean and easy-to-read code.
Systematic refactor of the MassTransitWorkflowDispatcher class which initially focused on restructuring the DispatchAsync methods. New methods have been added that deal specifically with triggering and bookmarking workflows thus enhancing the readability of the code while also improving its autonomous function. The logging for non-found workflows has been improved as well.
Evicting the cache prior to triggers being indexed fixes a bug where publishing workflow changes would not result in new triggers being found.
The commit adjusts calls to AddAsync in DefaultWorkflowRegistry and DispatchAsync in DefaultWorkflowInbox to improve readability. Also, it marks DispatchResumeWorkflows and DispatchTriggerWorkflows in the Elsa.MassTransit.Messages namespace as obsolete, indicating their pending removal in future releases.
@sfmskywalker sfmskywalker requested review from a team April 18, 2024 13:12
sfmskywalker and others added 6 commits April 18, 2024 17:34
The changes remove duplication and improve readability by extracting the code responsible for dispatching a workflow into a separate method called DispatchWorkflowAsync. This method creates a workflow instance, gets the send endpoint, and then sends the message.
This commit simplifies the two separate catch blocks for NotSupportedException and TargetException into a single block using the new 'or' pattern in C#. It also makes minor adjustments to improve the clarity and readability of the code relating to the 'addSetMethod' invocation.
…tcher.cs

Co-authored-by: raymonddenhaan <155616759+raymonddenhaan@users.noreply.github.com>
The MassTransitWorkflowDispatcher.cs file is updated to improve readability and clarity. This includes changing the way bookmark and trigger filter objects are initialized, by breaking down the single-line initialization into multiple lines. Additionally, some logic has been updated in the DispatchBookmarksAsync function for better handling of workflow instance properties and input merging.
The SendHttpRequestBase activity in the Elsa.Http module is updated to utilize the ILogger service. This extension enables the capture of HttpRequestException and TaskCanceledException events and logs their warnings, providing insight into potential issues during HTTP request sending.
@sfmskywalker sfmskywalker merged commit 568cefa into main Apr 18, 2024
6 checks passed
@sfmskywalker sfmskywalker deleted the enhancement/optimizations branch April 18, 2024 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[PERF] Optimize Message Handling in IWorkflowInbox to Reduce Workflow Dispatch Latency
2 participants