This repository has been archived by the owner on Aug 10, 2024. It is now read-only.
Use processes and threads in Azure cloud plugins #138
Merged
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.
Both
AzCloud
andAzVM
now rely on multiprocessing and multithreadingto pull resources concurrently from Azure cloud in order to complete its
scan faster.
All of the multiprocessing and multithreading code involved is put in a
new
ioworkers
module.AzCloud
andAzVM
invokeioworkers.run()
tolaunch multiple worker processes each of which launch multiple worker
threads. The callers, i.e.,
AzCloud
andAzVM
, need to provide thisioworkers.run()
function two callback functions:defines a unit of work.
function, does something with it, and then yields outputs.
The output functions are run concurrently by
ioworkers
in multipleworker threads within multiple worker processes. This two-level
approach, i.e., worker threads within worker processes, has been chosen
to maximize utilization of CPUs. This approaches provides a good balance
between the following two extremes:
resources and increase the overhead of context switching for
processes.
due to global interpreter lock (GIL) which allows only one thread to
execute at a time.
Lauching multiple workers sidesteps GIL and lets us utilize multiple
CPUs. Launching multiple threads within each process lets us scale even
further without incurring the overhead of more processes.