Repository navigation
[Swarming] Dispatch each utask_main Pub/Sub queue independently in run_bot #5639
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
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 |
|---|---|---|
|
|
@@ -139,6 +139,7 @@ def get_task_duration(command): | |
| SUBQUEUE_IDENTIFIER = ':' | ||
|
|
||
| UTASK_QUEUE_PULL_SECONDS = 150 | ||
| SWARMING_UTASK_QUEUE_PULL_SECONDS = 30 | ||
|
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. Add documentation |
||
|
|
||
| # The maximum number of utasks we will collect from the utask queue before | ||
| # scheduling on batch. | ||
|
|
@@ -846,14 +847,15 @@ def get_task_from_message(message, queue=None, can_defer=True, | |
| return task | ||
|
|
||
|
|
||
| def get_utask_mains(queue_name: str) -> List[PubSubTask]: | ||
| def get_utask_mains(queue_name: str, | ||
| pull_seconds: int = UTASK_QUEUE_PULL_SECONDS | ||
|
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. Add documentation for the arguments |
||
| ) -> List[PubSubTask]: | ||
| """Returns a list of tasks for preprocessing many utasks on this bot and then | ||
| running the uworker_mains in the same batch job.""" | ||
| subscription_name = subscription_name_for_queue(queue_name) | ||
| topic_queue = _strip_os_version_suffix(queue_name) | ||
| pubsub_puller = PubSubPuller(subscription_name) | ||
| messages = pubsub_puller.get_messages_time_limited(MAX_UTASKS, | ||
| UTASK_QUEUE_PULL_SECONDS) | ||
| messages = pubsub_puller.get_messages_time_limited(MAX_UTASKS, pull_seconds) | ||
| return handle_multiple_utask_main_messages(messages, topic_queue) | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,39 +93,54 @@ def lease_all_tasks(task_list): | |
| yield | ||
|
|
||
|
|
||
| def schedule_utask_mains(): | ||
| """Schedules utask_mains from preprocessed utasks on remote backends.""" | ||
|
|
||
| logs.info('Attempting to combine batch tasks.') | ||
| utask_mains = tasks.get_utask_mains(pub_sub_task_queue.UTASK_MAIN_QUEUE.name) | ||
|
|
||
| if feature_flags.FeatureFlags.SWARMING_REMOTE_EXECUTION.enabled: | ||
| swarming_utask_mains = tasks.get_utask_mains( | ||
| pub_sub_task_queue.SWARMING_UTASK_MAIN_QUEUE.name) | ||
| logs.info(f'Found {len(swarming_utask_mains)} swarming utask mains.') | ||
| utask_mains.extend(swarming_utask_mains) | ||
| def _schedule_utask_main_queue(queue_name: str, | ||
|
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. Add documentation for arguments |
||
| gate: remote_task_gate.RemoteTaskGate, | ||
| pull_seconds: int | None = None) -> None: | ||
| """Pulls and schedules utask_mains from a single Pub/Sub queue.""" | ||
| try: | ||
| if pull_seconds is None: | ||
| utask_mains = tasks.get_utask_mains(queue_name) | ||
| else: | ||
| utask_mains = tasks.get_utask_mains(queue_name, pull_seconds=pull_seconds) | ||
| except RuntimeError as e: | ||
|
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. Why this change?
Collaborator
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. IIUC, this is to avoid the scheduling bot from failing with an error if a queue doesn't exist. Which seems fair, but with this change we are introducing a new silent failure, i feel like its better that a CF bot crashes loudly when a queue doesn't exists rather than failing silently to schedule things. Mainly because, if i have a brand new CF instance i would prefeer to it not work because my queues are not well defined, rather than seeing no 'failures' nor tasks being scheduled, and having to dig in the logs to find out why |
||
| logs.warning(f'Skipping utask_main queue {queue_name}: {e}') | ||
| return | ||
|
|
||
| if not utask_mains: | ||
| logs.info('No utask mains.') | ||
| logs.info(f'No utask mains in {queue_name}.') | ||
| return | ||
|
|
||
| logs.info(f'Combining {len(utask_mains)} batch tasks.') | ||
| logs.info(f'Combining {len(utask_mains)} batch tasks from {queue_name}.') | ||
|
|
||
| with lease_all_tasks(utask_mains): | ||
| batch_tasks = [ | ||
| remote_task_types.RemoteTask( | ||
| task.command, task.job, task.argument, pubsub_task=task) | ||
| for task in utask_mains | ||
| ] | ||
| uncreated_tasks = remote_task_gate.RemoteTaskGate().create_utask_main_jobs( | ||
| batch_tasks) | ||
| logs.info(f'Not acking {len(uncreated_tasks)} uncreated tasks.') | ||
| # Tasks that couldn't be scheduled shoulnd't be acked. | ||
| uncreated_tasks = gate.create_utask_main_jobs(batch_tasks) | ||
| logs.info( | ||
| f'Not acking {len(uncreated_tasks)} uncreated tasks from {queue_name}.') | ||
| # Tasks that couldn't be scheduled shouldn't be acked. | ||
| for task in uncreated_tasks: | ||
| if task.pubsub_task: | ||
| task.pubsub_task.cancel_lease_ack() | ||
|
|
||
|
|
||
| def schedule_utask_mains(): | ||
| """Schedules utask_mains from preprocessed utasks on remote backends.""" | ||
| logs.info('Attempting to combine batch tasks.') | ||
| gate = remote_task_gate.RemoteTaskGate() | ||
| _schedule_utask_main_queue(pub_sub_task_queue.UTASK_MAIN_QUEUE.name, gate) | ||
|
|
||
| if feature_flags.FeatureFlags.SWARMING_REMOTE_EXECUTION.enabled: | ||
| for queue in pub_sub_task_queue.get_all_swarming_utask_main_queues(): | ||
| _schedule_utask_main_queue( | ||
| queue.name, | ||
| gate, | ||
| pull_seconds=tasks.SWARMING_UTASK_QUEUE_PULL_SECONDS) | ||
|
|
||
|
|
||
| def _get_max_task_executions(): # pylint: disable=inconsistent-return-statements | ||
| """Returns the MAX_TASK_EXECUTIONS limit as an int, or None if | ||
| invalid/unset.""" | ||
|
|
||
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.
What's our plan for validating these changes? Both for this PR and the PR chain in general, since I suspect you may not be able to validate things one-by-one.
Please also document the plan in the PR description.