elsa-workflows / elsa-core

A .NET workflows library
https://v3.elsaworkflows.io/
MIT License
6.02k stars 1.1k forks source link

Optimize SignalR Broadcasting in Realtime Workflows to Enhance Performance #5179

Open sfmskywalker opened 2 months ago

sfmskywalker commented 2 months ago

When the "realtime workflows" feature is active, a SignalR hub facilitates connections from Elsa Studio applications to receive updates on running workflow instances. This feature is useful for real-time monitoring but has been identified as a potential performance bottleneck, particularly under heavy workflow execution loads. The current implementation involves broadcasting workflow status changes and execution log entries directly from the workflow execution thread, which has been pinpointed as a hotspot during profiling.

Objective

The goal is to investigate and implement more efficient methods for handling SignalR broadcasting to mitigate any adverse effects on workflow execution performance. One proposed strategy is to offload SignalR interactions to a background task, thereby decoupling the broadcasting process from the workflow execution thread.

Expected Outcome

Steps for Investigation/Implementation

  1. Profile the current implementation to quantify the impact of SignalR broadcasting on workflow execution performance.
  2. Explore the feasibility of handling SignalR broadcasts in a background task or using alternative efficient approaches.
  3. Implement the chosen solution and conduct performance comparisons to ensure that the issue is resolved.
glime-ai[bot] commented 2 months ago

To address the performance bottleneck associated with the "realtime workflows" feature and SignalR broadcasting, the following steps can be taken:

  1. Profiling the Current Implementation: Use profiling tools to measure the impact of SignalR broadcasting on workflow execution performance. This will help identify the specific areas where performance degradation occurs.

  2. Background Task Offloading: Investigate the possibility of offloading SignalR message broadcasting to a background service or task. This would involve capturing workflow events and queuing them for broadcast without doing so directly on the workflow execution thread.

  3. Alternative Broadcasting Approaches: Consider alternative methods for broadcasting updates, such as batching messages to reduce the number of broadcasts or using asynchronous messaging patterns to minimize blocking on the execution thread.

  4. Implementation of Solution: Once a suitable method is identified, implement the changes in the system. This may involve changes to the workflow execution engine to publish events to a queue and a separate background service to handle broadcasting these events to connected clients via SignalR.

  5. Performance Testing: After implementing the new broadcasting mechanism, conduct thorough performance testing to compare it against the previous implementation. Ensure that the new approach resolves the bottleneck without introducing new issues.

  6. Monitoring and Optimization: Continuously monitor the system's performance to ensure that the real-time updates feature operates efficiently. Be prepared to make further optimizations as necessary based on real-world usage patterns.

By following these steps, you can aim to improve the performance of the Elsa Workflows system under heavy load, ensuring that real-time updates are delivered efficiently without negatively impacting the core workflow execution.