sartography / SpiffWorkflow

A powerful workflow engine implemented in pure Python
GNU Lesser General Public License v3.0
1.69k stars 313 forks source link

Feature/performance improvements #398

Closed essweine closed 7 months ago

essweine commented 7 months ago

This PR

The impetus for these improvements were workflow getting bogged down when large numbers of branches are active at once. The main bottleneck turned out to be repeatedly updating waiting joins. When a merge point is reached on any branch, the task transitions to waiting until enough branches complete. Every time any task completes, all waiting tasks in workflow are re-checked to see if they've become runnable.

So what I've done is maintain only the most recently completed task in a waiting state and preemptively cancelled the others incrementally rather than cancelling all but one when the gateway threshold is finally reached. This is where the bulk of the improvment comes from. But not constantly updating waiting subprocesses also helps.

Additionally, checking whether the subprocess is finished involves finding the subprocess, so that should alleviate some runtime errors regarding the size of the dictionary where they're maintained changing as well.

In one example, processing time went from 11 seconds to 5 seconds. We are seeing huge improvements for some processes.