Repository navigation
[batch] resolve a broken user share counter in the scheduler #15862
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
Open
cjllanwarne
wants to merge
2
commits into
hail-is:main
Choose a base branch
from
cjllanwarne:cjl_fix_user_share_in_scheduler
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| import os | ||
| from types import SimpleNamespace | ||
| from typing import Any, Dict, List | ||
|
|
||
| import pytest | ||
|
|
||
| # The driver modules read these at import time. | ||
| for _name, _value in { | ||
| 'CLOUD': 'gcp', | ||
| 'HAIL_DEFAULT_NAMESPACE': 'default', | ||
| 'HAIL_SCOPE': 'test', | ||
| 'HAIL_DOCKER_ROOT_IMAGE': 'ubuntu:24.04', | ||
| 'HAIL_DOCKER_PREFIX': 'docker.io', | ||
| 'KUBERNETES_SERVER_URL': 'https://kubernetes.default', | ||
| 'INTERNAL_GATEWAY_IP': '10.0.0.1', | ||
| 'HAIL_BATCH_STORAGE_URI': 'gs://test-bucket', | ||
| 'HAIL_SHA': 'test-sha', | ||
| 'HAIL_QUERY_STORAGE_URI': 'gs://test-bucket', | ||
| 'HAIL_QUERY_ACCEPTABLE_JAR_SUBFOLDER': '/jars', | ||
| 'HAIL_QUERY_SPARK_ARCHIVE_SUBFOLDER': '/spark-archives', | ||
| }.items(): | ||
| os.environ.setdefault(_name, _value) | ||
|
|
||
| from batch.driver.instance_collection import pool as pool_module # noqa: E402 | ||
| from batch.driver.instance_collection.pool import PoolScheduler # noqa: E402 | ||
| from batch.utils import ExceededSharesCounter # noqa: E402 | ||
|
|
||
| REGION = 'us-central1' | ||
| INSTANCE_CORES_MCPU = 16_000 | ||
|
|
||
|
|
||
| class FakeInstance: | ||
| region = REGION | ||
| state = 'active' | ||
|
|
||
| def adjust_free_cores_in_memory(self, delta_mcpu): | ||
| pass | ||
|
|
||
|
|
||
| class FakePool: | ||
| name = 'standard' | ||
|
|
||
| def __init__(self): | ||
| self.all_supported_regions = [REGION] | ||
| self.inst_coll_manager = SimpleNamespace(regions=[REGION]) | ||
|
|
||
| def get_instance(self, cores_mcpu, _regions): | ||
| return FakeInstance() if cores_mcpu <= INSTANCE_CORES_MCPU else None | ||
|
|
||
|
|
||
| class InlineWorkerPool: | ||
| async def call(self, f, *args, **kwargs): | ||
| await f(*args, **kwargs) | ||
|
|
||
|
|
||
| def make_scheduler(job_cores_mcpu_by_user: Dict[str, int], n_jobs_per_user: int): | ||
| """Returns the scheduler and a per-user count of jobs it has read from the queue.""" | ||
| n_read = {user: 0 for user in job_cores_mcpu_by_user} | ||
|
|
||
| async def compute_fair_share(): | ||
| return {user: {'allocated_cores_mcpu': 1_000_000} for user in job_cores_mcpu_by_user} | ||
|
|
||
| async def user_runnable_jobs(user): | ||
| for job_id in range(1, n_jobs_per_user + 1): | ||
| n_read[user] += 1 | ||
| yield { | ||
| 'batch_id': 1, | ||
| 'job_group_id': 0, | ||
| 'job_id': job_id, | ||
| 'user': user, | ||
| 'cores_mcpu': job_cores_mcpu_by_user[user], | ||
| 'regions_bits_rep': None, | ||
| 'n_prior_attempts': 0, | ||
| 'n_max_attempts': 5, | ||
| } | ||
|
|
||
| scheduler: Any = PoolScheduler.__new__(PoolScheduler) | ||
| scheduler.app = {'frozen': False} | ||
| scheduler.pool = FakePool() | ||
| scheduler.async_worker_pool = InlineWorkerPool() | ||
| scheduler.exceeded_shares_counter = ExceededSharesCounter() | ||
| scheduler.compute_fair_share = compute_fair_share | ||
| scheduler._user_runnable_jobs = user_runnable_jobs | ||
| return scheduler, n_read | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def scheduled_users(monkeypatch): | ||
| users: List[str] = [] | ||
|
|
||
| async def schedule_job(_app, record, _instance): | ||
| users.append(record['user']) | ||
|
|
||
| monkeypatch.setattr(pool_module, 'schedule_job', schedule_job) | ||
| return users | ||
|
|
||
|
|
||
| async def test_each_user_gets_their_share_in_one_pass(scheduled_users): | ||
| # Equal allocations give each user a share of 150 jobs per pass. | ||
| scheduler, _ = make_scheduler({'alice': 1000, 'bob': 1000}, n_jobs_per_user=200) | ||
|
|
||
| should_wait = await scheduler.schedule_loop_body() | ||
|
|
||
| assert scheduled_users.count('alice') == 150 | ||
| assert scheduled_users.count('bob') == 150 | ||
| assert should_wait is False | ||
|
|
||
|
|
||
| async def test_unplaceable_jobs_are_bounded_by_share(scheduled_users): | ||
| # alice's jobs don't fit on any instance. | ||
| scheduler, n_read = make_scheduler({'alice': 2 * INSTANCE_CORES_MCPU, 'bob': 1000}, n_jobs_per_user=200) | ||
|
|
||
| await scheduler.schedule_loop_body() | ||
|
|
||
| assert n_read['alice'] == 150 | ||
| assert scheduled_users.count('bob') == 150 | ||
|
|
||
|
|
||
| async def test_waits_when_nothing_could_be_placed(scheduled_users): | ||
| # A lone user's share is 300, so alice reaches it without placing anything. | ||
| scheduler, _ = make_scheduler({'alice': 2 * INSTANCE_CORES_MCPU}, n_jobs_per_user=400) | ||
|
|
||
| should_wait = await scheduler.schedule_loop_body() | ||
|
|
||
| assert scheduled_users == [] | ||
| assert should_wait is True |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.