Parallel file read - #19
Open
jcumby wants to merge 7 commits into
Open
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When reading highly compressed image files a fairly large amount of time is spent decompressing the images, rather than performing the reconstruction.
Potential solution
Using multiprocessing, it's possible to split the work of reading files and reconstructing asynchronously across processors. Ideally this would parallelise both the reading and reconstruction steps, but given that h5py cannot perform parallel writes I opted to just parallelise the read operation.
This fork uses a Pool of workers (default 4) to read image files and yield the results as needed to a single worker which does the reconstruction. To avoid i/o out-running the reconstruction (and filling memory) the Pool is restricted to storing a maximum of 8 images. On the few test-cases I've run, it seems to give a fairly good speedup.
To use the parallel processing, meerkat must be called as an importable script - I've used argparse to collect (some of) the parameters for
reconstruct_datafrom the command line, and the whole lot can be called withpython -m meerkat.meerkat --helpPossible Downsides
reconstuct_datato take an iterable of (image_number, data) pairs instead of the previousfilename_template, and also asemaphoreobject (default None) to work with multiprocessing. This change would change the API, but could also allow the use offabio.frame_serieswhich has some (potential) speed advantages.