From c2e62efe75941c51b1dbb5296922c5bf000a6664 Mon Sep 17 00:00:00 2001 From: Edgar Aguilar Date: Mon, 30 Nov 2026 22:29:37 +0000 Subject: [PATCH 1/2] [Swarming] Key per-batch backpressure by OS in full_platforms --- src/clusterfuzz/_internal/swarming/service.py | 11 +++++------ .../_internal/tests/core/swarming/service_test.py | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/clusterfuzz/_internal/swarming/service.py b/src/clusterfuzz/_internal/swarming/service.py index b79311b035..8d3cb1ba8a 100644 --- a/src/clusterfuzz/_internal/swarming/service.py +++ b/src/clusterfuzz/_internal/swarming/service.py @@ -104,7 +104,7 @@ def create_utask_main_jobs(self, return remote_tasks logs.info(f'[Swarming] Pushing {len(remote_tasks)} tasks trough service.') - full_queues = set() + full_platforms = set() for task in remote_tasks: if not swarming.is_swarming_job(task.job_type): unscheduled_tasks.append(task) @@ -129,10 +129,9 @@ def create_utask_main_jobs(self, job_name=task.job_type) continue - # Apply backpressure per (pool, os) bucket within this batch so a full - # platform does not block tasks for other platforms. - queue_key = (pool_val, os_val) - if queue_key in full_queues: + # Apply backpressure per OS within this batch so a full platform does not + # block tasks for other platforms. + if os_val in full_platforms: unscheduled_tasks.append(task) continue @@ -146,7 +145,7 @@ def create_utask_main_jobs(self, # TODO(b/524280052): Memoize queue state check. if self._is_queue_full(count_request): - full_queues.add(queue_key) + full_platforms.add(os_val) unscheduled_tasks.append(task) continue diff --git a/src/clusterfuzz/_internal/tests/core/swarming/service_test.py b/src/clusterfuzz/_internal/tests/core/swarming/service_test.py index 7aa2a14b4b..3a3c59565b 100644 --- a/src/clusterfuzz/_internal/tests/core/swarming/service_test.py +++ b/src/clusterfuzz/_internal/tests/core/swarming/service_test.py @@ -234,7 +234,7 @@ def test_create_utask_main_jobs_backpressure(self): self.mock_api.push_task.assert_called_once_with(self.mock_request) def test_create_utask_main_jobs_backpressure_does_not_block_other_os(self): - """Tests per-(pool, os) backpressure skips repeat full buckets without blocking other OSes.""" + """Tests per-OS backpressure skips repeat full platforms without blocking other OSes.""" mac_request = swarming_pb2.NewTaskRequest(task_slices=[ swarming_pb2.TaskSlice( properties=swarming_pb2.TaskProperties(dimensions=[ From 7bc83127ea9b185b6c4e9d01729d2b6502bf8bc9 Mon Sep 17 00:00:00 2001 From: Edgar Aguilar Date: Mon, 30 Nov 2026 19:43:32 +0000 Subject: [PATCH 2/2] [Swarming] Give non-fuzz tasks higher queue and pending backpressure limits Scale the Swarming utask_main queue limit and Swarming pending task backpressure limit for non-fuzz commands using the live-tunable swarming_non_fuzz_queue_limit_multiplier feature flag (default 2.0, clamped to >= 1.0), and extend per-batch backpressure keys to (os, is_fuzz). Bug: 589717890 --- .../_internal/base/feature_flags.py | 2 ++ .../base/tasks/pub_sub_task_queue.py | 17 +++++++++++ .../_internal/bot/tasks/task_types.py | 4 +++ src/clusterfuzz/_internal/swarming/service.py | 23 +++++++++----- .../base/tasks/pub_sub_task_queue_test.py | 18 +++++++++++ .../tests/core/bot/tasks/task_types_test.py | 30 +++++++++++++++++++ .../tests/core/swarming/service_test.py | 29 ++++++++++++------ 7 files changed, 107 insertions(+), 16 deletions(-) diff --git a/src/clusterfuzz/_internal/base/feature_flags.py b/src/clusterfuzz/_internal/base/feature_flags.py index 18d11c9edb..7487836f54 100644 --- a/src/clusterfuzz/_internal/base/feature_flags.py +++ b/src/clusterfuzz/_internal/base/feature_flags.py @@ -41,6 +41,8 @@ class FeatureFlags(Enum): SWARMING_UTASK_MAIN_QUEUE_SIZE_LIMIT = 'swarming_utask_main_queue_size_limit' # TODO(b/516836939): Migrate feature flag to static config value. SWARMING_MAX_PENDING_TASKS = 'swarming_max_pending_tasks' + SWARMING_NON_FUZZ_QUEUE_LIMIT_MULTIPLIER = ( + 'swarming_non_fuzz_queue_limit_multiplier') ENABLE_FUZZ_FOR_BOTS = 'enable_fuzz_for_bots' STORAGE_THREADED_OPS_FUZZ_TARGETS = 'storage_threaded_ops_fuzz_targets' diff --git a/src/clusterfuzz/_internal/base/tasks/pub_sub_task_queue.py b/src/clusterfuzz/_internal/base/tasks/pub_sub_task_queue.py index e6860b82be..e78dec6ed8 100644 --- a/src/clusterfuzz/_internal/base/tasks/pub_sub_task_queue.py +++ b/src/clusterfuzz/_internal/base/tasks/pub_sub_task_queue.py @@ -55,6 +55,9 @@ def get_max_target_size(self) -> int: # Default limit for the swarming utask main queue. SWARMING_UTASK_MAIN_QUEUE_LIMIT_DEFAULT = 25 +# Default multiplier giving Swarming non-fuzz tasks headroom above the fuzz cap. +SWARMING_NON_FUZZ_QUEUE_LIMIT_MULTIPLIER_DEFAULT = 2.0 + PREPROCESS_QUEUE = PubSubTaskQueue( name=tasks.PREPROCESS_QUEUE, default_target_size=PREPROCESS_TARGET_SIZE_DEFAULT, @@ -95,3 +98,17 @@ def get_max_size_for_queue(default_size: int, if flag.enabled and flag.content is not None: return int(flag.content) return default_size + + +def get_swarming_non_fuzz_queue_limit(base_limit: int) -> int: + """Returns the queue limit for Swarming non-fuzz tasks. + + Scales |base_limit| by SWARMING_NON_FUZZ_QUEUE_LIMIT_MULTIPLIER (clamped to + >= 1.0) so fuzz backlog at |base_limit| still leaves headroom for non-fuzz + tasks while still capping runaway non-fuzz floods. + """ + flag = FeatureFlags.SWARMING_NON_FUZZ_QUEUE_LIMIT_MULTIPLIER + multiplier = SWARMING_NON_FUZZ_QUEUE_LIMIT_MULTIPLIER_DEFAULT + if flag.enabled and flag.content is not None: + multiplier = max(1.0, float(flag.content)) + return int(base_limit * multiplier) diff --git a/src/clusterfuzz/_internal/bot/tasks/task_types.py b/src/clusterfuzz/_internal/bot/tasks/task_types.py index c2631ca39e..5c23f3e59b 100644 --- a/src/clusterfuzz/_internal/bot/tasks/task_types.py +++ b/src/clusterfuzz/_internal/bot/tasks/task_types.py @@ -180,6 +180,10 @@ def execute(self, task_argument, job_type, uworker_env): utask_main_queue_size = tasks.get_utask_main_queue_size(queue.name) utask_main_queue_limit = queue.get_max_target_size() + if is_swarming_job and command != 'fuzz': + utask_main_queue_limit = ( + pub_sub_task_queue.get_swarming_non_fuzz_queue_limit( + utask_main_queue_limit)) if utask_main_queue_size > utask_main_queue_limit: display_queue_name = tasks.subscription_name_for_queue(queue.name) diff --git a/src/clusterfuzz/_internal/swarming/service.py b/src/clusterfuzz/_internal/swarming/service.py index 8d3cb1ba8a..f5631e4887 100644 --- a/src/clusterfuzz/_internal/swarming/service.py +++ b/src/clusterfuzz/_internal/swarming/service.py @@ -18,6 +18,8 @@ from clusterfuzz._internal.base.tasks import task_utils from clusterfuzz._internal.base.tasks.pub_sub_task_queue import \ get_max_size_for_queue +from clusterfuzz._internal.base.tasks.pub_sub_task_queue import \ + get_swarming_non_fuzz_queue_limit from clusterfuzz._internal.metrics import logs from clusterfuzz._internal.protos import swarming_pb2 from clusterfuzz._internal.remote_task import remote_task_types @@ -51,8 +53,10 @@ def _get_dimension(self, request: swarming_pb2.NewTaskRequest, return dimension.value return "" - def _is_queue_full(self, - count_request: swarming_pb2.TasksCountRequest) -> bool: # pylint: disable=no-member + def _is_queue_full( + self, + count_request: swarming_pb2.TasksCountRequest, # pylint: disable=no-member + is_fuzz: bool = True) -> bool: """Checks if the queue is full based on pending tasks count. Returns True if the queue is full or if the check fails (Fail Closed). @@ -70,6 +74,8 @@ def _is_queue_full(self, max_pending_tasks = get_max_size_for_queue( SWARMING_MAIN_QUEUE_LIMIT_DEFAULT, FeatureFlags.SWARMING_MAX_PENDING_TASKS) + if not is_fuzz: + max_pending_tasks = get_swarming_non_fuzz_queue_limit(max_pending_tasks) if count >= max_pending_tasks: logs.info(f'[Swarming] Backpressure applied. Queue size: {count}. ' 'Stopping scheduling.') @@ -129,9 +135,12 @@ def create_utask_main_jobs(self, job_name=task.job_type) continue - # Apply backpressure per OS within this batch so a full platform does not - # block tasks for other platforms. - if os_val in full_platforms: + # Apply backpressure per (os, is_fuzz) within this batch so a full fuzz + # platform does not block non-fuzz triage tasks (which have extra + # headroom) or other platforms. + is_fuzz = task.command == 'fuzz' + platform_key = (os_val, is_fuzz) + if platform_key in full_platforms: unscheduled_tasks.append(task) continue @@ -144,8 +153,8 @@ def create_utask_main_jobs(self, state=swarming_pb2.QUERY_PENDING) # pylint: disable=no-member # TODO(b/524280052): Memoize queue state check. - if self._is_queue_full(count_request): - full_platforms.add(os_val) + if self._is_queue_full(count_request, is_fuzz=is_fuzz): + full_platforms.add(platform_key) unscheduled_tasks.append(task) continue diff --git a/src/clusterfuzz/_internal/tests/core/base/tasks/pub_sub_task_queue_test.py b/src/clusterfuzz/_internal/tests/core/base/tasks/pub_sub_task_queue_test.py index eb11ecb4a6..035ea806ae 100644 --- a/src/clusterfuzz/_internal/tests/core/base/tasks/pub_sub_task_queue_test.py +++ b/src/clusterfuzz/_internal/tests/core/base/tasks/pub_sub_task_queue_test.py @@ -16,6 +16,8 @@ import unittest from clusterfuzz._internal.base.feature_flags import FeatureFlags +from clusterfuzz._internal.base.tasks.pub_sub_task_queue import \ + get_swarming_non_fuzz_queue_limit from clusterfuzz._internal.base.tasks.pub_sub_task_queue import PubSubTaskQueue from clusterfuzz._internal.datastore import data_types from clusterfuzz._internal.tests.test_libs import test_utils @@ -65,3 +67,19 @@ def test_get_max_target_size_with_disabled_flag(self): default_target_size=25, target_size_flag=FeatureFlags.SWARMING_MAX_PENDING_TASKS) self.assertEqual(queue.get_max_target_size(), 25) + + def test_get_swarming_non_fuzz_queue_limit(self): + """Tests default multiplier, feature flag override, and >= 1.0 clamp.""" + self.assertEqual(get_swarming_non_fuzz_queue_limit(25), 50) + + data_types.FeatureFlag( + id=FeatureFlags.SWARMING_NON_FUZZ_QUEUE_LIMIT_MULTIPLIER.value, + enabled=True, + value=3.0).put() + self.assertEqual(get_swarming_non_fuzz_queue_limit(25), 75) + + data_types.FeatureFlag( + id=FeatureFlags.SWARMING_NON_FUZZ_QUEUE_LIMIT_MULTIPLIER.value, + enabled=True, + value=0.5).put() + self.assertEqual(get_swarming_non_fuzz_queue_limit(25), 25) diff --git a/src/clusterfuzz/_internal/tests/core/bot/tasks/task_types_test.py b/src/clusterfuzz/_internal/tests/core/bot/tasks/task_types_test.py index 16f064025b..998265831c 100644 --- a/src/clusterfuzz/_internal/tests/core/bot/tasks/task_types_test.py +++ b/src/clusterfuzz/_internal/tests/core/bot/tasks/task_types_test.py @@ -367,6 +367,34 @@ def test_execute_proceeds_below_limit(self): self.utask.execute('arg', 'job', {}) self.utask.preprocess.assert_called() + def test_swarming_non_fuzz_gets_higher_queue_limit(self): + """Tests that Swarming non-fuzz tasks get headroom above fuzz, yet stay capped.""" + self.utask.preprocess = mock.Mock(return_value=None) + + with mock.patch( + 'clusterfuzz._internal.bot.tasks.task_types.swarming.is_swarming_job', + return_value=True), mock.patch( + 'clusterfuzz._internal.bot.tasks.task_types.environment.is_tworker', + return_value=True), mock.patch( + 'clusterfuzz._internal.bot.tasks.task_types.tasks.' + 'get_utask_main_queue_size') as mock_size: + mock_size.return_value = 26 + with mock.patch( + 'clusterfuzz._internal.base.tasks.task_utils.get_command_from_module', + return_value='fuzz'): + with self.assertRaises(errors.QueueLimitReachedError): + self.utask.execute('arg', 'job', {}) + + with mock.patch( + 'clusterfuzz._internal.base.tasks.task_utils.get_command_from_module', + return_value='analyze'): + self.utask.execute('arg', 'job', {}) + self.utask.preprocess.assert_called_once() + + mock_size.return_value = 51 + with self.assertRaises(errors.QueueLimitReachedError): + self.utask.execute('arg', 'job', {}) + class TaskExecuteLocalOrRemoteTest(unittest.TestCase): """Tests that executing a task either runs it locally or queues it for remote @@ -395,6 +423,7 @@ def setUp(self): 'clusterfuzz._internal.base.tasks.add_utask_main', 'clusterfuzz._internal.base.tasks.get_utask_main_queue_size', 'clusterfuzz._internal.base.tasks.pub_sub_task_queue.PubSubTaskQueue.get_max_target_size', + 'clusterfuzz._internal.base.tasks.pub_sub_task_queue.get_swarming_non_fuzz_queue_limit', 'clusterfuzz._internal.base.tasks.task_utils.is_remotely_executing_utasks', 'clusterfuzz._internal.batch.service.is_remote_task', 'clusterfuzz._internal.bot.tasks.task_types.BaseUTask.execute_locally', @@ -408,6 +437,7 @@ def setUp(self): self.mock.is_swarming_job.return_value = False self.mock.get_utask_main_queue_size.return_value = 0 self.mock.get_max_target_size.return_value = 1000 + self.mock.get_swarming_non_fuzz_queue_limit.return_value = 2000 self.mock.preprocess.return_value = 'https://download-url' def _execute(self, command): diff --git a/src/clusterfuzz/_internal/tests/core/swarming/service_test.py b/src/clusterfuzz/_internal/tests/core/swarming/service_test.py index 3a3c59565b..137db6ffb1 100644 --- a/src/clusterfuzz/_internal/tests/core/swarming/service_test.py +++ b/src/clusterfuzz/_internal/tests/core/swarming/service_test.py @@ -233,8 +233,9 @@ def test_create_utask_main_jobs_backpressure(self): self.assertEqual(self.mock_api.push_task.call_count, 1) self.mock_api.push_task.assert_called_once_with(self.mock_request) - def test_create_utask_main_jobs_backpressure_does_not_block_other_os(self): - """Tests per-OS backpressure skips repeat full platforms without blocking other OSes.""" + def test_create_utask_main_jobs_backpressure_does_not_block_non_fuzz_or_os( + self): + """Tests two-tier backpressure across fuzz, non-fuzz, and different OSes.""" mac_request = swarming_pb2.NewTaskRequest(task_slices=[ swarming_pb2.TaskSlice( properties=swarming_pb2.TaskProperties(dimensions=[ @@ -245,18 +246,24 @@ def test_create_utask_main_jobs_backpressure_does_not_block_other_os(self): ]) tasks = [ remote_task_types.RemoteTask('fuzz', 'linux_job1', 'url1'), - remote_task_types.RemoteTask('fuzz', 'linux_job2', 'url2'), - remote_task_types.RemoteTask('fuzz', 'mac_job', 'url3'), + remote_task_types.RemoteTask('analyze', 'linux_job2', 'url2'), + remote_task_types.RemoteTask('fuzz', 'linux_job3', 'url3'), + remote_task_types.RemoteTask('analyze', 'linux_job4', 'url4'), + remote_task_types.RemoteTask('fuzz', 'mac_job', 'url5'), ] self.mock.is_swarming_job.return_value = True self.mock.create_new_task_request.side_effect = [ + self.mock_request, + self.mock_request, self.mock_request, self.mock_request, mac_request, ] self.mock_api.count_tasks.side_effect = [ - swarming_pb2.TasksCount(count=25), # linux hits 25 cap - swarming_pb2.TasksCount(count=0), # mac passes (< 25) + swarming_pb2.TasksCount(count=25), # linux fuzz hits 25 cap + swarming_pb2.TasksCount(count=25), # linux analyze passes (< 50) + swarming_pb2.TasksCount(count=50), # linux analyze hits 50 cap + swarming_pb2.TasksCount(count=0), # mac fuzz passes (< 25) ] self.mock_api.push_task.return_value = swarming_pb2.TaskRequestResponse( task_id='123') @@ -264,9 +271,13 @@ def test_create_utask_main_jobs_backpressure_does_not_block_other_os(self): unscheduled = self.service.create_utask_main_jobs(tasks) self.assertEqual([t.job_type for t in unscheduled], - ['linux_job1', 'linux_job2']) - self.mock_api.push_task.assert_called_once_with(mac_request) - self.assertEqual(self.mock_api.count_tasks.call_count, 2) + ['linux_job1', 'linux_job3', 'linux_job4']) + self.mock_api.push_task.assert_has_calls([ + mock.call(self.mock_request), + mock.call(mac_request), + ]) + self.assertEqual(self.mock_api.push_task.call_count, 2) + self.assertEqual(self.mock_api.count_tasks.call_count, 4) def test_create_utask_main_jobs_count_tasks_failure(self): """Test that count_tasks failure fails closed (not scheduling) when