Skip to content

Conversation

Sn0w3y
Copy link
Contributor

@Sn0w3y Sn0w3y commented Jul 31, 2025

This update introduces an interruptible wait mechanism to the Modbus bridge's WaitTask and CycleTasksManager classes, allowing for more responsive task switching and reducing unnecessary delays in task execution. Specifically:

  1. Added a Mutex-based interrupt mechanism in WaitTask to replace the fixed Thread.sleep() delay, enabling the task to be interrupted and proceed immediately with the next operation. This change allows for more dynamic task management and reduces latency in processing Modbus operations.

  2. Modified CycleTasksManager to interrupt the current WaitDelayTask upon executing a write operation, ensuring that write tasks are executed immediately without waiting for the delay to complete. This enhancement addresses a specific issue where write tasks were delayed by up to the Cycle Time due to unexpired wait times, thereby improving the system's responsiveness and throughput.

  3. Extended CycleTasksManagerTest to include a test case verifying the immediate execution of write tasks following an onExecuteWrite() call, demonstrating the elimination of the previously observed delay and validating the effectiveness of the interrupt mechanism.

Discussed here

=== TEST: Write task executes immediately after onExecuteWrite ===
Starting cycle with onBeforeProcessImage()
Got WaitDelayTask with delay: 0ms
Delay task thread started, beginning wait...
Delay task completed normally
Calling onExecuteWrite() to interrupt the delay
Got write task immediately: DummyWriteTask [name=WT_1, delay=90]
Test passed: Write task was available immediately without waiting for delay!
=== END TEST ===

The test confirms that:

  1. The cycle starts with a WaitDelayTask (0ms in this test case)
  2. When onExecuteWrite() is called, it interrupts the delay
  3. The write task WT_1 is available immediately
  4. The implementation successfully fixes the delay issue

This update introduces an interruptible wait mechanism to the Modbus bridge's WaitTask and CycleTasksManager classes, allowing for more responsive task switching and reducing unnecessary delays in task execution. Specifically:

1. Added a Mutex-based interrupt mechanism in WaitTask to replace the fixed Thread.sleep() delay, enabling the task to be interrupted and proceed immediately with the next operation. This change allows for more dynamic task management and reduces latency in processing Modbus operations.

2. Modified CycleTasksManager to interrupt the current WaitDelayTask upon executing a write operation, ensuring that write tasks are executed immediately without waiting for the delay to complete. This enhancement addresses a specific issue where write tasks were delayed by up to 8 seconds due to unexpired wait times, thereby improving the system's responsiveness and throughput.

3. Extended CycleTasksManagerTest to include a test case verifying the immediate execution of write tasks following an onExecuteWrite() call, demonstrating the elimination of the previously observed delay and validating the effectiveness of the interrupt mechanism.
Copy link

codecov bot commented Jul 31, 2025

Codecov Report

❌ Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.

Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #3261      +/-   ##
=============================================
+ Coverage      59.42%   59.43%   +0.01%     
  Complexity       113      113              
=============================================
  Files           2763     2763              
  Lines         119343   119349       +6     
  Branches        8889     8890       +1     
=============================================
+ Hits           70911    70925      +14     
+ Misses         45757    45747      -10     
- Partials        2675     2677       +2     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Sn0w3y
Copy link
Contributor Author

Sn0w3y commented Aug 1, 2025

@sfeilmeier could you please re-run the Test as this is a false-positive test run :D It actually succeeds locally and also on my CI.

sfeilmeier and others added 2 commits August 1, 2025 17:33
This commit streamlines the modbus task handling by removing the interrupt mechanism in WaitTask and simplifying the state machine in CycleTasksManager. Specifically, it replaces the interruptible wait mechanism with a straightforward Thread.sleep in WaitTask, and it consolidates the state machine by removing the READ_BEFORE_WRITE, WAIT_FOR_WRITE, and READ_AFTER_WRITE states in favor of a simpler WRITE and READ sequence. This change aims to simplify the codebase, making it easier to understand and maintain, while also potentially improving performance by eliminating unnecessary complexity and synchronization points. The associated tests have been adjusted to reflect these changes, ensuring that the system's behavior remains consistent and predictable.
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.

2 participants