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

Live viewer: Quick handle notification and defer slow work #2221

Merged
merged 3 commits into from
Jun 17, 2024

Conversation

samtygier-stfc
Copy link
Collaborator

@samtygier-stfc samtygier-stfc commented Jun 10, 2024

Issue

Closes #2204

Description

When a diectory is updated we have to check the age of every file in it, to find the newest (QFileSystemWatcher does not give the changed file name). This can be slow on windows, e.g. a second for a few thousand images. During this time new notifications can arrive.

Previously, each notification as acted when it was received. If the rate of notification was to high, then a queue of signals would build up, and MI would appear stuck.

Now we can quickly handle the notification in _handle_notified_of_directry_change(), and defer the work with a timer. Any extra notifications can get aborbed by this, and the actuall work in _handle_directory_change() only needs to run once.

Also adds a stress test script. e.g.
simulate_live_data_stress.py -d \mi_test\live -s 0 -f 1000 -r 0.1 -v
Creates 1000 files at a rate of one every 0.1 seconds.

Testing

Not easy to add an automated test

Acceptance Criteria

See bug report for methods to trigger issue. Check that you can trigger it on main. Test that there are not long hangs with changes.

Not that this does nothing to make finding the new file faster. So with a large number of files there will still be a few seconds between a file arriving and being displayed.

Documentation

release notes

@coveralls
Copy link

Coverage Status

coverage: 72.736% (-0.01%) from 72.75%
when pulling 810eee1 on 2204-fast-handle-changed
into f0def70 on main.

@samtygier-stfc samtygier-stfc marked this pull request as ready for review June 10, 2024 12:07
Copy link
Collaborator

@JackEAllen JackEAllen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, looks good, thanks for chasing down this bug and putting a measure in to better handle the build up of queued signals. The implementation of _handle_notified_of_directry_change looks good, just a small typo in a docstring.

The main bit of feedback I have is just to move scripts/simulate_live_data_stress.py into scripts/simulate_live_data.py. This would not only keep the number of utility scripts we have small, but also improve usability of scripts/simulate_live_data.py by no longer requiring users/devs from needing to enter a source directory if we draw an image if no source is provided.

mantidimaging/gui/windows/live_viewer/model.py Outdated Show resolved Hide resolved
scripts/simulate_live_data_stress.py Outdated Show resolved Hide resolved
Handle directory changed events quickly by storing the directory and
starting a timer (if not already started). Trigger the slow part of the
work with the timer. This means multiple changes can be flushed off the
Qt signal queue, and the slow part done once.
@coveralls
Copy link

Coverage Status

coverage: 72.69% (-0.02%) from 72.705%
when pulling 7b5f142 on 2204-fast-handle-changed
into 06f179e on main.

Copy link
Collaborator

@JackEAllen JackEAllen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes, I've re-tested and all looks good. Files don't fall out of sync as badly when copying a large number of images into a director watched by the live viewer at a high rep rate.

@JackEAllen JackEAllen added this pull request to the merge queue Jun 17, 2024
Merged via the queue into main with commit c16f2c1 Jun 17, 2024
8 checks passed
@JackEAllen JackEAllen deleted the 2204-fast-handle-changed branch June 17, 2024 14:31
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.

LiveViewer: Out of Synchronisation with Most Recent Image - Difference Increases with Dataset Size
3 participants