Repository navigation
Add parallel.py - #178
Open
JuhoErvasti wants to merge 1 commit into
Open
Add parallel.py#178JuhoErvasti wants to merge 1 commit into
JuhoErvasti wants to merge 1 commit into
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.
Description
Add a new core module
parallel.pyto handle multithreaded geometry processing in parallel usingThreadPoolExecutor.Design remarks
On import
parallel.pyinstantiates a_ThreadManagersingleton instance which manages aThreadPoolExecutor. This removes some overhead of spawning threads multiple times per a process run. By default it uses one thread per logical core on the CPU, but this can be configured by environment variable or explicitly setting the worker count withset_num_workers, which takes precedence over env variable.Parallel processing is exposed mainly through a
ParallelGeometryProcessobject, which is meant to be instantiated from thein_parallelfunction. This allows one to write code and chain operations like:I'm not a 100% happy with this, but this felt like the best solution, first I had just something like
but chaining operations this way makes for really unreadable and awkward code. Pandas also supports defining a custom property accessor like
but this way you don't get any type information or autocomplete in an IDE.
Multithreading improves performance on intermediate size datasets mostly only with heavier operations like buffer/intersection etc. With cheap operations like
area()etc. it's typically not even worth it to parallelize. This is why I've only defined some methods forParallelGeometryProcess, but you can use other shapely functions too by passing it inrun(), I think if necessary we can also add more methods as we go.This PR doesn't yet actually use the parallel processing anywhere.
Obviously it's hard to pinpoint a clear speed-up because really it depends a lot on the type of data and the vertex count of geometries (and worker count). In the included benchmarks we do get a decent speed-up (3-5x) especially in the larger datasets and heavier operations like buffering or intersections; with small datasets and cheap operations it either breaks even or is slower.
Type of change
Bug fix
New feature
Other
Non-breaking change
Breaking change
Developer checklist