-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(api): Remove concurrency from
LegacyContextPlugin
(#16098)
## Overview This removes a potential source of deadlocks and race conditions. I originally thought this would help with EXEC-417. I'm not sure it actually will at this point, but maybe we should still do it. ## Background When the robot executes a Python protocol, the `ProtocolEngine` and higher-level HTTP stuff live in the main thread, and the user's Python script runs in a worker thread. For older (`apiLevel`≤2.13) protocols, `LegacyContextPlugin` transports progress reports from the worker thread to the main thread. When we initially built all of this, we had [severe performance problems](#9133) where the main thread would get bogged down serializing a big HTTP response or something, and then the backpressure through `LegacyContextPlugin` would stall the protocol thread, causing visible jankiness in robot motion. We did a bunch of stuff to try to fix this. One fix was to [insert an infinite non-blocking queue](#9238) between the two threads to remove the backpressure. I strongly suspect that that fix is unnecessary today. As evidence: It only ever applied to older, `apiLevel`≤2.13, protocols. Newer, `apiLevel`≥2.14 ones, have always run through a different pipeline, which still has backpressure. And the newer pipeline is apparently not perceived to have janky motion. Removing the fix would remove concurrency, which would be a meaningful simplification. For instance, I've seen hints that [this part](https://github.com/Opentrons/opentrons/blob/45e14ca26359720740db744124b464bdcc84264c/api/src/opentrons/protocol_engine/execution/hardware_stopper.py#L70) of run cleanup is racy, because it depends on whether all the `pickUpTip`/`dropTip` commands got consumed from the queue by the time we reach there. ## Test Plan and Hands on Testing * [x] On an OT-2, run some protocols that are movement-intensive (e.g. lots of `touch_tip()`s) and have `apiLevel` ≤ 2.13. Click around in the app and induce some network requests. There might be some jankiness, but make sure it's not severe. Really, I think we just need to make sure it's not any worse than `apiLevel` ≥ 2.14. * I'm noticing jank lasting ~0-1 seconds when you: navigate to the device details page (understandable); navigate through the device settings (weird); and navigate to the device list page (concerning). All of this applies equally to `apiLevel≥2.14`, so if we're concerned about this, retaining this non-blocking queue in `LegacyContextPlugin` is not the correct solution. ## Changelog * Delete the non-blocking queue between the Python protocol thread . Replace it with simple inter-thread function calls. ## Review requests Is this a good idea? ## Risk assessment Medium. There is a risk that this *is* covering up enduring jankiness problems, and removing it will bring the problems back. This may not be obvious to us in the office because we're more focused on Flexes, which don't run `apiLevel`≤2.13 protocols. But there's also risk to having the concurrency, so... 🤷
- Loading branch information
1 parent
534fb53
commit 6451bdb
Showing
5 changed files
with
34 additions
and
447 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
174 changes: 0 additions & 174 deletions
174
api/src/opentrons/protocol_runner/thread_async_queue.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.