-
Notifications
You must be signed in to change notification settings - Fork 22
Introducing fault tolerance in preprocessing #1361
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
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 os | ||
| from pdb import run | ||
| import yaml | ||
| import time | ||
| import logging | ||
|
|
@@ -371,34 +372,69 @@ def _main(executor: Union["MPICommExecutor", "ProcessPoolExecutor"], | |
| n_fail = 0 | ||
|
|
||
| # Run write_block obs-ids in parallel at once then write all to the sqlite db. | ||
| futures = [executor.submit(preprocess_tod, obs_id=r[0]['obs_id'], | ||
| group_list=r[1], verbosity=verbosity, | ||
| configs=configs, | ||
| overwrite=overwrite, run_parallel=True) for r in run_list] | ||
| for future in as_completed_callable(futures): | ||
| logger.info('New future as_completed result') | ||
| try: | ||
| err, db_datasets = future.result() | ||
| futures = [] | ||
| for r in run_list: | ||
| fut = executor.submit( | ||
| preprocess_tod, | ||
| obs_id=r[0]["obs_id"], | ||
| group_list=r[1], | ||
| verbosity=verbosity, | ||
| configs=configs, | ||
| overwrite=overwrite, | ||
| run_parallel=True, | ||
|
||
| ) | ||
| fut.kargs = {"obs_id": r[0]["obs_id"], | ||
| "group_list": r[1], | ||
| "verbosity": verbosity, | ||
| "configs": configs, | ||
| "overwrite": overwrite, | ||
| "run_parallel": True, | ||
| "try": 1} | ||
| futures.append(fut) | ||
|
|
||
| while futures: | ||
|
Contributor
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. Ok so now futures are checked in a loop for completion and errors. If a future raised OSError, it is retried up to 3 times before logging as failed. I think this is great! One comment: lines 395-398 - I think this repeatedly checks if a task (future) has completed by polling its status in a loop without e.g. any delay. I wonder if there's a more efficient way in terms of CPU usage? Would it be possible to use something like
Member
Author
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. We do not need a new dictionary for the As far as the two loops there is no reason to have both, since the inner loop does what the outer loop was supposed to do. In addition, changing the iterator of a
|
||
| future_to_check = futures.pop(0) | ||
| if future_to_check.done(): | ||
| err, db_datasets = future_to_check.result() | ||
| if err is not None: | ||
| n_fail += 1 | ||
| except Exception as e: | ||
| errmsg = f'{type(e)}: {e}' | ||
| tb = ''.join(traceback.format_tb(e.__traceback__)) | ||
| if db_datasets: | ||
| if err is None: | ||
| logger.info(f'Processing future result db_dataset: {db_datasets}') | ||
| for db_dataset in db_datasets: | ||
| pp_util.cleanup_mandb(err, db_dataset, configs, logger) | ||
| else: | ||
| pp_util.cleanup_mandb(err, db_datasets, configs, logger) | ||
| elif isinstance(future_to_check.exception(), OSError) and future_to_check.kargs["try"] <= 3: | ||
| logger.info(f"Future raised an OSError: {future_to_check.exception()}, resubmitting") | ||
| new_future = executor.submit( | ||
| preprocess_tod, | ||
| obs_id=future_to_check.kargs["obs_id"], | ||
| group_list=future_to_check.kargs["group_list"], | ||
| verbosity=future_to_check.kargs["verbosity"], | ||
| configs=future_to_check.kargs["configs"], | ||
| overwrite=future_to_check.kargs["overwrite"], | ||
| run_parallel=future_to_check.kargs["run_parallel"], | ||
| ) | ||
| new_future.kargs = {"obs_id": future_to_check.kargs["obs_id"], | ||
| "group_list": future_to_check.kargs["group_list"], | ||
| "verbosity": future_to_check.kargs["verbosity"], | ||
| "configs": future_to_check.kargs["configs"], | ||
| "overwrite": future_to_check.kargs["overwrite"], | ||
| "run_parallel": future_to_check.kargs["run_parallel"], | ||
| "try": future_to_check.kargs["try"] + 1} | ||
| futures.append(new_future) | ||
| elif isinstance(future_to_check.exception(), OSError) and future_to_check.kargs["try"] > 3: | ||
|
||
| logger.info(f"Future failed after 3 attempts: {future_to_check.exception()}") | ||
| errmsg = f'{type(future_to_check.exception())}: {future_to_check.exception()}' | ||
| tb = ''.join(traceback.format_tb(future_to_check.exception().__traceback__)) | ||
| logger.info(f"ERROR: future.result()\n{errmsg}\n{tb}") | ||
| f = open(errlog, 'a') | ||
| f.write(f'\n{time.time()}, future.result() error\n{errmsg}\n{tb}\n') | ||
| f.close() | ||
| n_fail+=1 | ||
|
Member
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. It looks like you haven't handled the case where Seems that the logic is complex enough that this nshould have a test. I would also like to see an explanation for why OSError and ValueError are the two things being tracked specially here. What does each kind of error mean, in this context? |
||
| continue | ||
| futures.remove(future) | ||
|
|
||
| if db_datasets: | ||
| if err is None: | ||
| logger.info(f'Processing future result db_dataset: {db_datasets}') | ||
| for db_dataset in db_datasets: | ||
| pp_util.cleanup_mandb(err, db_dataset, configs, logger) | ||
| else: | ||
| pp_util.cleanup_mandb(err, db_datasets, configs, logger) | ||
| else: | ||
| futures.append(future_to_check) | ||
|
||
|
|
||
| if raise_error and n_fail > 0: | ||
| raise RuntimeError(f"preprocess_tod: {n_fail}/{len(run_list)} obs_ids failed") | ||
|
|
||
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 don't think you're using this anywhere, please remove