-
Notifications
You must be signed in to change notification settings - Fork 795
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
Run post-breach phase in separate thread #758
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import logging | ||
from multiprocessing.dummy import Pool | ||
from typing import Sequence | ||
|
||
from infection_monkey.post_breach.pba import PBA | ||
|
@@ -24,12 +25,8 @@ def execute_all_configured(self): | |
""" | ||
Executes all post breach actions. | ||
""" | ||
for pba in self.pba_list: | ||
try: | ||
LOG.debug("Executing PBA: '{}'".format(pba.name)) | ||
pba.run() | ||
except Exception as e: | ||
LOG.error("PBA {} failed. Error info: {}".format(pba.name, e)) | ||
pool = Pool(5) | ||
pool.map(self.run_pba, self.pba_list) | ||
LOG.info("All PBAs executed. Total {} executed.".format(len(self.pba_list))) | ||
|
||
@staticmethod | ||
|
@@ -38,3 +35,10 @@ def config_to_pba_list() -> Sequence[PBA]: | |
:return: A list of PBA objects. | ||
""" | ||
return PBA.get_instances() | ||
|
||
def run_pba(self, pba): | ||
try: | ||
LOG.debug("Executing PBA: '{}'".format(pba.name)) | ||
pba.run() | ||
except Exception as e: | ||
LOG.error("PBA {} failed. Error info: {}".format(pba.name, e)) | ||
Comment on lines
+41
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Logging doesn't get messed up? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No? Just that all PBA logs are not logged together now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I'm concerned with is the possibility of log showing:
This might be a bit misleading, but I think we'll manage. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tried this with multithreading? Performance was worse? Processes take longer to spawn, but are truly "parallel". If I/O is long, maybe we don't really need parallel execution, maybe we just need to init all I/O asap?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm importing
Pool
from multiprocessing.dummy.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, I see!